But so far in all attempts I am unable to preserve structure. The test structure I am dealing with looks like If I use the GDML workbench i.e. with Gui it works. In this case the ImportGui.export function is used but this is only available when the
Gui is active so cannot be used. The exported Step file looks like This thread https://forum.freecadweb.org/viewtopic.php?t=32710 Has some examples of exporting STEP without the Gui,
But using this approach I am unclear how to retain structure. The post says there are three ways of doing this
Code: Select all
Part.export([testbox],"C:/Users/vad/Desktop/testbox/box.step")
testbox.Shape.exportStep("C:/Users/vad/Desktop/testbox/box.step")
import Import
Import.export([testbox],"C:/Users/vad/Desktop/testbox/box.step")
If I code as follows the structure does not get preserved.
Code: Select all
def stackShapes(objList) :
# Stack shapes to global shapesList
for x in objList :
if x.TypeId == 'App::Part' :
print("Part : "+x.Name)
shapesList.append(x)
if hasattr(x,'Shape') :
print('keep')
print(x.TypeId)
print(x.Name)
shapesList.append(x)
if len(x.OutList) > 0 :
stackShapes(x.OutList)
# iterate through all objects
for o in App.ActiveDocument.Objects:
# find root object and export the shape
#print(o.Name)
if o.Name == 'Volumes' :
global shapesList
shapesList = []
print(o.TypeId)
if len(o.OutList) > 0 :
stackShapes(o.OutList)
if len(shapesList) > 0 :
Part.export(shapesList,"/tmp/test4.step")