Hello guys,
I'm currently playing with branch jriegel/dev-assembly (build 3416), which compiles without any problems, and I'm facing a weird behavior when I try to export assemblies. I know it's in alpha state & all, but maybe it's just me doing it wrong or perhaps I've got my hand on an point that you'll be interested in... Anyway I've read somewhere that feedback is always good
When I...
- open the assembly workbench and it creates a new assembly for me
- "Import an existing component" and select a step file, and do it for, say 2 or 3 step files,
- add some constraints and manage to get some changes synced with the Gui
- hit CTRL+A in the objets tree
- and hit CTRL-E to export this assembly in STEP
... then all I get is a resulting STEP with the very components I've added before, but those components haven't moved, like if I've done no assembling work at all.
Some exporting formats _does work_, like "export to PDF" for example.
After some investigation :
- import from Part workbench with "ImportGui.Insert" and export from Assembly with ImportGui.export _works_, which means I get all my changes inside the exported STEP file. The thing is, components being not properly imported inside Assembly objects, I cannot use the constraints,
- Import and Export from Assembly workbench with AssemblyLib.ImportAssembly and ImportGui.export _don't work_: I can add constraints but can't get my changes exported inside a step file.
Looks like the mechanism behind AssemblyLib.ImportAssembly (which is Part.read and not Part.insert) is maybe not suited for a proper export in STEP?
Could be great to have some insight from some veterans here, and maybe I can help getting around this?
Thanks, cheers
Exporting assembly to STEP format
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Exporting assembly to STEP format
STEP export does not care about assembly structures. Thats not implemented yet....
Stop whining - start coding!
Re: Exporting assembly to STEP format
That's what I thought, thanks for your reply.
Do you think it's something I could help you with somehow?
What would be roughly the way you would implement it?
Do you think it's something I could help you with somehow?
What would be roughly the way you would implement it?
Re: Exporting assembly to STEP format
Since for Assembly STEP is a vital part, I already started a new Import/export line of code in the Import module. There are basically two possible approaches to that problem.
1st approach is to use the OCAF (OCC document model) translator and generate Assembly objects instead of Part objects. Unfortunately do OCC only transfer STEP objects/concepts it has objects for in its library. Mostly geometric stuff. Also no support for more specialized STEP stuff like STEP-NC or IFC....
There for I will go for the 2nd approach. I use the STEP-Code project python binding to load all high level objects from a STEP file, like Produkts, Persons and all kind of meta data. Interpret it with a python script, which makes it very flexible and easy to extend. After heaving the high level information I use the low level OCC translater to just get the (Part 42) shapes.
For Approach 1 you get faster results, but got most likely stuck very soon. Approach 2 I already started but got not much time for it lately.
1st approach is to use the OCAF (OCC document model) translator and generate Assembly objects instead of Part objects. Unfortunately do OCC only transfer STEP objects/concepts it has objects for in its library. Mostly geometric stuff. Also no support for more specialized STEP stuff like STEP-NC or IFC....
There for I will go for the 2nd approach. I use the STEP-Code project python binding to load all high level objects from a STEP file, like Produkts, Persons and all kind of meta data. Interpret it with a python script, which makes it very flexible and easy to extend. After heaving the high level information I use the low level OCC translater to just get the (Part 42) shapes.
For Approach 1 you get faster results, but got most likely stuck very soon. Approach 2 I already started but got not much time for it lately.
Stop whining - start coding!
Re: Exporting assembly to STEP format
Thanks for your insight! Your high-level-pythonic approach is indeed the best between the two.
I may try to implement the direct translator way, but just as a personal exercise
I may try to implement the direct translator way, but just as a personal exercise
Re: Exporting assembly to STEP format
Why not, as more choices as better!
Stop whining - start coding!
-
- Posts: 436
- Joined: Wed Sep 15, 2010 9:38 am
Re: Exporting assembly to STEP format
I also neede this and wrote a small macro that takes all shapes of an assembly and copy them into a new document.
Hope this helps,
Gaël
Code: Select all
import FreeCAD as App
import FreeCADGui as Gui
doc = App.activeDocument()
# Get the list of features and their placement
feature_list = []
placement_list = []
label_list = []
for o in doc.Objects:
if o.TypeId == 'PartDesign::Solid':
feature_list.append(o)
body = o.InList[0]
part = body.InList[0]
placement = part.Placement
placement_list.append(placement)
label_list.append(o.Label)
# Copy the features and place them
new_doc = App.newDocument()
fpl_list = zip(feature_list, placement_list, label_list)
for feature, placement, label in fpl_list:
o = new_doc.addObject('Part::Feature', label)
o.Shape = feature.Shape
o.Placement = placement
Gui.SendMsgToActiveView("ViewFit")
Gaël
Re: Exporting assembly to STEP format
Hi,
I use FreeCAD 0.15 and the above code did not work for me.
so I tried to debug and get this:
... extract any
in a subDirectory
"myExport"
in the Directory where your base FreeCAD File is stored
cheers Manfred
I use FreeCAD 0.15 and the above code did not work for me.
so I tried to debug and get this:
... extract any
- Part::Feature
Part::FeaturePython
- FreeCAD and
STEP-File
in a subDirectory
"myExport"
in the Directory where your base FreeCAD File is stored
Code: Select all
# import FreeCAD as App
import os
import shutil
import FreeCAD
# import FreeCAD as App
# import FreeCADGui as Gui
print "Start"
doc = App.activeDocument()
# print doc.PropertiesList
print "document: " + doc.getPropertyByName('Label')
activeFileName = doc.getPropertyByName('FileName')
print "document: " + activeFileName
exportDir = os.path.dirname(activeFileName) + "/myExport"
print "exportDir: " + exportDir
#
if not os.path.exists(exportDir):
os.makedirs(exportDir)
#
for filename in os.listdir(exportDir):
filepath = os.path.join(exportDir, filename)
try:
shutil.rmtree(filepath)
except OSError:
os.remove(filepath)
#
# Get the list of features and their placement
feature_list = []
placement_list = []
label_list = []
#
print "\n\n -- STEP export ---\n\n"
for o in doc.Objects:
# print " o: " + o.TypeId + " / " + o.Label
if o.TypeId == 'Part::Feature' or o.TypeId == 'Part::FeaturePython':
print " o: " + o.TypeId + " / " + o.Label
feature_list.append(o)
exportFileName = exportDir + "/" + o.Label + ".stp"
print " export: " + exportFileName
#
o.Shape.exportStep(exportFileName)
#
#print o.PropertiesList
# body = o.getInList[0]
# part = body.getInList[0]
# placement = part.Placement
# placement_list.append(placement)
label_list.append(o.Label)
else:
print " o: " + o.TypeId + " ... exception"
#
#exit
#
#
#
print "\n\n -- FreeCAD export ---\n\n"
#
#
#
# new_doc = App.newDocument()
# fpl_list = zip(feature_list, placement_list, label_list)
# exportFileName = exportDir + "/" + label + ".stp"
# exportFileName = exportDir + "/complete.stp"
#
#for feature, placement, label in fpl_list:
fpl_list = zip(feature_list, label_list)
#
for feature, label in fpl_list:
print " export: " + label
freeCADFileName = exportDir + "/" + label + ".FCStd"
stepFileName = exportDir + "/" + label + "_b.stp"
print " export: " + freeCADFileName
print " export: " + stepFileName
#
newDoc = App.newDocument(label)
o = newDoc.addObject('Part::Feature', label)
o.Shape = feature.Shape
App.getDocument(label).saveAs(freeCADFileName)
#
# o.Placement = placement
Gui.SendMsgToActiveView("ViewFit")
newDoc.recompute()
#
#o.Shape.exportStep(stepFileName)
#
App.closeDocument(label)
Gui.SendMsgToActiveView("ViewFit")
#
#
#
print "\n\n -- Done ! ---\n\n"
#
#
#
exit