|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Copyright 2022 Doug Blanding (dblanding@gmail.com) |
| 4 | +# |
| 5 | +# This file contains the PythonOCC equivalent code for the C++ code |
| 6 | +# presented in the Open CASCADE Technology OCAF Documentation at: |
| 7 | +# https://dev.opencascade.org/doc/overview/html/occt_user_guides__ocaf.html |
| 8 | +# |
| 9 | + |
| 10 | +from OCC.Core.TCollection import (TCollection_AsciiString, |
| 11 | + TCollection_ExtendedString) |
| 12 | +from OCC.Core.TDocStd import TDocStd_Application, TDocStd_Document |
| 13 | +from OCC.Core.XCAFApp import XCAFApp_Application_GetApplication |
| 14 | +from OCC.Extend.DataExchange import read_step_file_with_names_colors |
| 15 | +from OCC.Core.STEPCAFControl import STEPCAFControl_Reader |
| 16 | +from OCC.Core.IFSelect import IFSelect_RetDone |
| 17 | + |
| 18 | +# The Application |
| 19 | + |
| 20 | +# There are several different "flavors" of applications & documents |
| 21 | +# Here, XDE (Extended Data Exchange) has been chosen, enabling STEP |
| 22 | +title = "Main document" |
| 23 | +doc = TDocStd_Document(TCollection_ExtendedString(title)) |
| 24 | +""" |
| 25 | +app = XCAFApp_Application_GetApplication() |
| 26 | +app.NewDocument(TCollection_ExtendedString("MDTV-XCAF"), doc) |
| 27 | +""" |
| 28 | +filename = "/home/doug/step-files/as1-oc-214.stp" |
| 29 | +step_reader = STEPCAFControl_Reader() |
| 30 | +step_reader.SetColorMode(True) |
| 31 | +step_reader.SetLayerMode(True) |
| 32 | +step_reader.SetNameMode(True) |
| 33 | +step_reader.SetMatMode(True) |
| 34 | +step_reader.SetGDTMode(True) |
| 35 | + |
| 36 | +status = step_reader.ReadFile(filename) |
| 37 | +if status == IFSelect_RetDone: |
| 38 | + step_reader.Transfer(doc) |
| 39 | + |
| 40 | +# see if I can retrieve the app from doc |
| 41 | +# app = doc.Application() # gives runtime error: document has not yet been opened by any application |
0 commit comments