Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F83558534
create_part_geometry.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Sep 17, 19:32
Size
1 KB
Mime Type
text/x-python
Expires
Thu, Sep 19, 19:32 (2 d)
Engine
blob
Format
Raw Data
Handle
20827041
Attached To
R11910 Additive Manufacturing Work
create_part_geometry.py
View Options
import
numpy
as
np
import
argparse
import
sys
import
os
from
read_data
import
*
def
parse_args
():
"""
Function to handle arguments
"""
parser
=
argparse
.
ArgumentParser
(
description
=
'Create Part Geometry and Save'
)
parser
.
add_argument
(
"freecad_dir"
,
type
=
str
,
help
=
'location of FreeCAD library directory'
)
parser
.
add_argument
(
"data_file"
,
type
=
str
,
help
=
'filename of the geometry data'
)
parser
.
add_argument
(
"extrude_width"
,
type
=
float
,
help
=
'part extrusion width'
)
parser
.
add_argument
(
"save_file"
,
type
=
str
,
help
=
'name of the step file to be saved'
)
args
=
parser
.
parse_args
()
return
args
def
main
():
#get the arguments
args
=
parse_args
()
#add FreeCAD directory to path nad import FreeCAD modules
sys
.
path
.
append
(
args
.
freecad_dir
)
import
FreeCAD
import
Part
from
FreeCAD
import
Base
#define points of the face to be extruded and empty array to store the edges
cantilever_face_points
=
read_data
(
args
.
data_file
)
cantilever_face_edges
=
[]
#create the edges using the points defined
for
i
in
range
(
len
(
cantilever_face_points
)):
try
:
cantilever_face_edges
.
append
(
Part
.
makeLine
(
cantilever_face_points
[
i
],
cantilever_face_points
[
i
+
1
]))
except
:
cantilever_face_edges
.
append
(
Part
.
makeLine
(
cantilever_face_points
[
i
],
cantilever_face_points
[
0
]))
#create the wire, face and extrude
cantilever_wire
=
Part
.
Wire
(
cantilever_face_edges
)
cantilever_face
=
Part
.
Face
(
cantilever_wire
)
cantilever
=
cantilever_face
.
extrude
(
Base
.
Vector
(
0
,
args
.
extrude_width
,
0
))
#create new directory with save_file name and save the geometry as .step file
try
:
os
.
mkdir
(
args
.
save_file
)
except
FileExistsError
:
pass
#export the cantilever geometry
cantilever
.
exportStep
(
'{}/{}'
.
format
(
args
.
save_file
,
args
.
save_file
))
if
__name__
==
'__main__'
:
main
()
Event Timeline
Log In to Comment