41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
import os
|
|
from OCC.Core.STEPControl import STEPControl_Reader, STEPControl_Writer, STEPControl_AsIs
|
|
from OCC.Core.STEPCAFControl import STEPCAFControl_Writer
|
|
|
|
from OCC.Core.Interface import Interface_Static_SetCVal
|
|
from OCC.Core.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
|
|
from OCC.Core.TDocStd import TDocStd_Document
|
|
from OCC.Core.TCollection import TCollection_ExtendedString
|
|
|
|
try:
|
|
import svgwrite
|
|
HAVE_SVGWRITE = True
|
|
except ImportError:
|
|
HAVE_SVGWRITE = False
|
|
|
|
def write_step_file(a_shape, filename, application_protocol="AP242DIS"):
|
|
""" exports a shape to a STEP file
|
|
a_shape: the topods_shape to export (a compound, a solid etc.)
|
|
filename: the filename
|
|
application protocol: "AP203" or "AP214IS" or "AP242DIS"
|
|
"""
|
|
# a few checks
|
|
#if a_shape.IsNull():
|
|
# raise AssertionError("Shape %s is null." % a_shape)
|
|
if application_protocol not in ["AP203", "AP214IS", "AP242DIS"]:
|
|
raise AssertionError("application_protocol must be either AP203 or AP214IS. You passed %s." % application_protocol)
|
|
if os.path.isfile(filename):
|
|
print("Warning: %s file already exists and will be replaced" % filename)
|
|
# creates and initialise the step exporter
|
|
step_writer = STEPCAFControl_Writer()
|
|
Interface_Static_SetCVal("write.step.schema", application_protocol)
|
|
|
|
# transfer shapes and write file
|
|
step_writer.Transfer(a_shape, STEPControl_AsIs)
|
|
status = step_writer.Write(filename)
|
|
|
|
if not status == IFSelect_RetDone:
|
|
raise IOError("Error while writing shape to STEP file.")
|
|
if not os.path.isfile(filename):
|
|
raise IOError("File %s was not saved to filesystem." % filename)
|