STL file export

maurizio_mottarellaP385U
Contributor

STL file export

maurizio_mottarellaP385U
Contributor
Contributor
Hello Fusion 360,

I have a problem with exporting to STL format.
With API I generate an extruded profile, starting from a DXF file. 
After extruding it, I rotate the piece along the X axis using the transform2 property of the Occurrence
object, performing a rototranslation. By doing this my application continues to work fine, also taking advantage
of the inverse matrix. However, I need to export the rotated piece in STL format.
The problem is that what I see is that it is the original file to be exported, therefore without the rototranslation.
I attach the code that do the job (very simple, perhaps too much .. :))
Where am I wrong ?
Thank you for your help ...

 

0 Likes
Reply
Accepted solutions (1)
475 Views
3 Replies
Replies (3)

BrianEkins
Mentor
Mentor
Accepted solution

That's Fusion's behavior when writing out an occurrence. If you create a box as a new component, this creates a new occurrence, which is what you see in the browser. Run the "Move" command, making sure you choose "Components" as the type of object you want to move. Now, select the occurrence in the browser and arbitrarily move and rotate it. Next, export the occurrence as STL and then import it to see the result. You'll see that the imported STL is back at the original position before you moved the occurrence. This is because the STL export doesn't take into account the occurrence transform but is writing out the referenced component.

 

However, here's a workaround that creates a body with the desired transform and exports it.

# Get the body from an occurrence.
body: adsk.fusion.BRepBody = design.rootComponent.occurrences[0].bRepBodies[0]

# Create a temporary B-Rep copy of the body. This bakes the occurrence transform
# into the body.
tempBRep = adsk.fusion.TemporaryBRepManager.get()
tempBody = tempBRep.copy(body)

# Create a new document and make sure it isn't parametric.
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType, True)
des: adsk.fusion.Design = doc.products.itemByProductType('DesignProductType')
des.designType = adsk.fusion.DesignTypes.DirectDesignType

# Create a real body using the temporary body.
root = des.rootComponent
newBody = root.bRepBodies.add(tempBody)

# Export the body as STL.
filename = 'C:/Temp/TransBodyTest.stl'
stlOptions = exportMgr.createSTLExportOptions(newBody, filename)
rslt = exportMgr.execute(stlOptions)

# Close the document without saving.
doc.close(False)

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

maurizio_mottarellaP385U
Contributor
Contributor
Hi Brian, thank you very much, it works fine ..
0 Likes

Hi Brian,

 

I have another problem with STL export. I have this problem when I import with API an IGES file. After having imported it, I rototranslate to move the origin and orientation of the axis. However, when I generate the STL, it is generated with the original origin and axis orientation. The problem is that importing procedure of the IGES file does not generate a BRepBody and therefore I cannot apply the procedure that you sent me. Is there another way to generate a correct STL ? I attach both original IGES file and fusion file after the import. Thank you !

(the attached stp file is actually a iges file ...)

0 Likes