Export STEP file without Gui and preserve structure.

Need help, or want to share a macro? Post here!
keithsloan52
Posts: 1163
Joined: Mon Feb 27, 2012 5:31 pm

Export STEP file without Gui and preserve structure.

Postby keithsloan52 » Mon Mar 23, 2020 7:32 am

i am trying to develop a standalone utility to convert a GDML file to Step,

But so far in all attempts I am unable to preserve structure. The test structure I am dealing with looks like
Volumes.png
Volumes.png (31.69 KiB) Viewed 128 times
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
FCexport.step
(36.34 KiB) Downloaded 2 times
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")
But what should the list look like if structure is to be preserved?

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")
Out of interest where would I find the source to ImportGui.export?
keithsloan52
Posts: 1163
Joined: Mon Feb 27, 2012 5:31 pm

Re: Export STEP file without Gui and preserve structure.

Postby keithsloan52 » Mon Mar 23, 2020 8:09 am

@easyw-fc With your experience of exporting STEP for KiCAD are you able to advise?
keithsloan52
Posts: 1163
Joined: Mon Feb 27, 2012 5:31 pm

Re: Export STEP file without Gui and preserve structure.

Postby keithsloan52 » Thu Mar 26, 2020 11:35 am

Closed where as Part.export will only deal with flat structure Import.export will.