Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FreeCAD_Yaml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robotic Assembly
FreeCAD_Yaml
Commits
4e666870
Commit
4e666870
authored
May 15, 2024
by
Wanqi Zhao
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
dbfe9984
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
exportAsYaml.py
+49
-0
49 additions, 0 deletions
exportAsYaml.py
with
49 additions
and
0 deletions
exportAsYaml.py
0 → 100644
+
49
−
0
View file @
4e666870
# Import the necessary modules
import
FreeCAD
import
Part
import
yaml
# Get the active document
doc
=
FreeCAD
.
open
(
"
C:/Users/qiqi_/OneDrive/
\u6587\u6863
/Code/Test-FreeCAD/bridge.fcstd
"
)
# Get all the objects in the document
objects
=
doc
.
Objects
# Create empty lists to store parts
parts
=
[]
# Loop through all the objects in the document
for
obj
in
objects
:
# Check if the object is a part
if
isinstance
(
obj
,
Part
.
Feature
):
# Check if the label contains "Cube"
if
"
Cube
"
in
obj
.
Label
:
# Add the object to the parts list
parts
.
append
(
obj
)
# Create an empty dictionary to store the parts' information
parts_info
=
[]
# Loop through all the parts in the parts list
for
part
in
parts
:
# Get the part's label, size, and position
label
=
part
.
Label
length
,
width
,
height
=
part
.
Shape
.
BoundBox
.
XLength
,
part
.
Shape
.
BoundBox
.
YLength
,
part
.
Shape
.
BoundBox
.
ZLength
x
,
y
,
z
=
part
.
Placement
.
Base
.
x
,
part
.
Placement
.
Base
.
y
,
part
.
Placement
.
Base
.
z
size
=
{
"
length
"
:
part
.
Shape
.
BoundBox
.
XLength
,
"
width
"
:
part
.
Shape
.
BoundBox
.
YLength
,
"
height
"
:
part
.
Shape
.
BoundBox
.
ZLength
}
position
=
{
"
x
"
:
part
.
Placement
.
Base
.
x
,
"
y
"
:
part
.
Placement
.
Base
.
y
,
"
z
"
:
part
.
Placement
.
Base
.
z
}
# Add the part's information to the list
parts_info
.
append
({
"
name
"
:
label
,
"
size
"
:
size
,
"
position
"
:
position
})
print
(
parts_info
)
# Write the parts' information to a Yaml file
with
open
(
"
C:/Users/qiqi_/OneDrive/
\u6587\u6863
/Code/Test-FreeCAD/parts_info.yaml
"
,
"
w
"
)
as
file
:
yaml
.
dump
(
parts_info
,
file
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment