Example #1
0
def export_STEPFile_single(shape, filename, tol=1.0E-6):
    """
    Exports a .stp file containing the input shapes

    Parameters
    ----------
    shape : TopoDS_Shape

    filename : string
        The output filename
    """

    step = STEPCAFControl_Writer()
    step.SetNameMode(True)
    step.SetPropsMode(True)
    h_doc = TDocStd_Document()
    x_app = XCAFApp_Application.GetApplication().GetObject()
    x_app.NewDocument(TCollection_ExtendedString("MDTV-CAF"), h_doc)
    doc = h_doc.GetObject()
    h_shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
    shape_tool = h_shape_tool.GetObject()
    Interface_Static_SetCVal("write.step.schema", "AP214")

    # transfer shapes
    print(filename)
    shape_tool.AddShape(shape)
    step.Transfer(h_doc, STEPControl_AsIs)
    status = step.Write(filename)
    assert(status == IFSelect_RetDone)
Example #2
0
class ExportCAFMethod (object):

    def __init__(self, name="name", tol=1.0E-10):
        self.name = name
        self.step = STEPCAFControl_Writer()
        self.step.SetNameMode(True)
        self.h_doc = TDocStd_Document()
        self.x_app = XCAFApp_Application.GetApplication().GetObject()
        self.x_app.NewDocument(
            TCollection_ExtendedString("MDTV-CAF"), self.h_doc)
        self.doc = self.h_doc.GetObject()
        self.h_shape_tool = XCAFDoc_DocumentTool_ShapeTool(self.doc.Main())
        self.shape_tool = self.h_shape_tool.GetObject()
        Interface_Static_SetCVal("write.step.schema", "AP214")

    def Add(self, shape, name="name"):
        """
        STEPControl_AsIs                   translates an Open CASCADE shape to its highest possible STEP representation.
        STEPControl_ManifoldSolidBrep      translates an Open CASCADE shape to a STEP manifold_solid_brep or brep_with_voids entity.
        STEPControl_FacetedBrep            translates an Open CASCADE shape into a STEP faceted_brep entity.
        STEPControl_ShellBasedSurfaceModel translates an Open CASCADE shape into a STEP shell_based_surface_model entity.
        STEPControl_GeometricCurveSet      translates an Open CASCADE shape into a STEP geometric_curve_set entity.
        """
        label = self.shape_tool.AddShape(shape)
        self.step.Transfer(self.h_doc, STEPControl_AsIs)

    def Write(self, filename=None):
        if not filename:
            filename = self.name
        path, ext = os.path.splitext(filename)
        if not ext:
            ext = ".stp"
        status = self.step.Write(path + ext)
        assert(status == IFSelect_RetDone)
Example #3
0
def read_step_file_shapes(filename):
    _shapes = []

    # create an handle to a document
    h_doc = TDocStd_Document()

    # Create the application
    app = XCAFApp_Application.GetApplication().GetObject()
    app.NewDocument(TCollection_ExtendedString("MDTV-CAF"), h_doc)

    # Get root assembly
    doc = h_doc.GetObject()
    h_shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())

    step_reader = STEPCAFControl_Reader()
    step_reader.SetNameMode(True)

    status = step_reader.ReadFile(filename)
    if status == IFSelect_RetDone:
        step_reader.Transfer(doc)

    labels = TDF_LabelSequence()
    shape_tool = h_shape_tool.GetObject()
    h_shape_tool.GetObject().GetFreeShapes(labels)

    print("Number of shapes at root :%i" % labels.Length())
    for i in range(labels.Length()):
        label = labels.Value(i + 1)
        a_shape = h_shape_tool.GetObject().GetShape(label)
        _shapes.append(a_shape)
    return _shapes
Example #4
0
from OCC.Core.Quantity import Quantity_Color
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform
from OCC.Display.SimpleGui import init_display

filename = './models/as1-oc-214.stp'

# create an handle to a document
h_doc = TDocStd_Document()

# Create the application
app = XCAFApp_Application.GetApplication().GetObject()
app.NewDocument(TCollection_ExtendedString("MDTV-CAF"), h_doc)

# Get root assembly
doc = h_doc.GetObject()
h_shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
h_color_tool = XCAFDoc_DocumentTool_ColorTool(doc.Main())
h_layer_tool = XCAFDoc_DocumentTool_LayerTool(doc.Main())
h_mat_tool = XCAFDoc_DocumentTool_MaterialTool(doc.Main())

step_reader = STEPCAFControl_Reader()
step_reader.SetColorMode(True)
step_reader.SetLayerMode(True)
step_reader.SetNameMode(True)
step_reader.SetMatMode(True)

status = step_reader.ReadFile(filename)
if status == IFSelect_RetDone:
    step_reader.Transfer(doc.GetHandle())