Export Multi Body Part As Separate STL

Export Multi Body Part As Separate STL

ilyas_adnm
Advocate Advocate
557 Views
2 Replies
Message 1 of 3

Export Multi Body Part As Separate STL

ilyas_adnm
Advocate
Advocate

Hi Everyone,

 

I have multi-body part files and I'd like to export each solid body into separate STL files via the API.

 

The workflow I have currently is to make components and create individual IPTs for each body, followed by running the following script to export them to STL.

 

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument

For Each oOccurrence As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences
	Dim oCompDoc As PartDocument = oOccurrence.Definition.Document
	
	Dim stlName As String= System.IO.Path.GetFileNameWithoutExtension(oCompDoc.FullFileName)+".stl"
	Dim savePath As String = System.IO.Path.GetDirectoryName(oCompDoc.FullFileName)
	Logger.Trace(savePath & "\" & stlName)	
	oCompDoc.SaveAs(savePath & "\" & stlName,True)	
Next

MessageBox.Show("Done","ExportAllPartsAsSTL")

 

I'm wondering if there is a way to export the solid bodies directly via the API without having to go through the Make Component step?

 

Or if there is a way to access the 3D Print Environment via the API? Because in this environment, user can suppress individual bodies and export the remaining bodies as STL.

 

Regards

Ilyas

0 Likes
Accepted solutions (2)
558 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

Hi @ilyas_adnm 

You can derive the solids to a part which is the same function as make components tool. See post here.

Found by searching ilogic make components.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

ilyas_adnm
Advocate
Advocate
Accepted solution

Hi @A.Acheson,

 

Thanks for the hint.

 

'ThisApplication.ScreenUpdating = False

Dim oActiveDoc As PartDocument = ThisApplication.ActiveDocument

For Each oSurfaceBody As SurfaceBody In oActiveDoc.ComponentDefinition.SurfaceBodies
	Dim oPartDoc As PartDocument = ThisApplication.Documents.Add(kPartDocumentObject)    
	Dim oDerivedPartComponents As DerivedPartComponents = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents	
	Dim oDerivedPartDef As DerivedPartUniformScaleDef = oDerivedPartComponents.CreateUniformScaleDef(oActiveDoc.FullDocumentName)
	For Each oDerivedPartEntity As DerivedPartEntity In oDerivedPartDef.Solids
      If Not oDerivedPartEntity.ReferencedEntity Is oSurfaceBody Then
        oDerivedPartEntity.IncludeEntity = False
      End If
    Next
	oDerivedPartComponents.Add(oDerivedPartDef)	
	
	Dim iptName As String = System.IO.Path.GetFileNameWithoutExtension(oSurfaceBody.Name) + ".ipt"
	Dim stlName As String = System.IO.Path.GetFileNameWithoutExtension(oSurfaceBody.Name) + ".stl"
	Dim savePath As String = System.IO.Path.GetDirectoryName(oActiveDoc.FullFileName)
	Logger.Trace(savePath & "\" & stlName)	
	oPartDoc.SaveAs(savePath & "\" & iptName, True) 'need to save ipt first before it will be able to save stl
	oPartDoc.SaveAs(savePath & "\" & stlName, True)
	oPartDoc.Close(True)
	System.IO.File.Delete(savePath & "\" & iptName)
Next

MessageBox.Show("Done", "ExportBodiesAsSTL")
'ThisApplication.ScreenUpdating = True

 

Regards
Ilyas

0 Likes