Issue
In Inventor 2013 the SaveAs method of the PartDocument by default creates binary format STL. Can I control output file format – binary or ASCII?
Solution
SaveAs method to translate files is very easy to use and supports a wide variety of formats but has limited flexibility with respect to controlling the various options when doing the translation.
Another approach takes advantage of the fact that translators in Inventor are implemented as a special type of Add-In. All translator Add-Ins are required to support a common set of methods and properties which allows you to write a program that drives the translator. The best resource for this information is the programming help.
Related link: Good overview on Inventor translators.
You may download here very useful utility developed by Brian Ekins. This utility writes a report that contains information about all of the loaded translators, their Add-In ID, and the options supported by each Add-In.
Here are Save Copy As options for export to STL:
Name Value Map:
ExportUnits = 4
Resolution = 1
AllowMoveMeshNode = False
SurfaceDeviation = 60
NormalDeviation = 14
MaxEdgeLength = 100
AspectRatio = 40
ExportFileStructure = 0
OutputFileType = 0
ExportColor = True
Option OutputFileType controls file format:
0 – binary, 1 – ASCII.
VBA example:
Public Sub ExportToSTL()
‘ Get the STL translator Add-In.
Dim oSTLTranslator As TranslatorAddIn
Set oSTLTranslator = ThisApplication.ApplicationAddIns _
.ItemById("{533E9A98-FC3B-11D4-8E7E-0010B541CD80}")
If oSTLTranslator Is Nothing Then
MsgBox "Could not access STL translator."
Exit Sub
End If
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
‘ Save Copy As Options:
‘ Name Value Map:
‘ ExportUnits = 4
‘ Resolution = 1
‘ AllowMoveMeshNode = False
‘ SurfaceDeviation = 60
‘ NormalDeviation = 14
‘ MaxEdgeLength = 100
‘
AspectRatio = 40
‘ ExportFileStructure = 0
‘ OutputFileType = 0
‘ ExportColor = True
If oSTLTranslator.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
‘ Set accuracy.
‘ 2 = High, 1 = Medium, 0 = Low
oOptions.value("Resolution") = 1
‘ Set output file type:
‘ 0 – binary, 1 – ASCII
oOptions.value("OutputFileType") = 1
oContext.Type = kFileBrowseIOMechanism
Dim oData As DataMedium
Set oData = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = "C:\temp\Plate.stl"
Call oSTLTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)
End If
Beep
MsgBox "Completed"
End Sub
<
p style=”line-height: normal;margin: 0cm 0cm 0pt” class=”MsoNormal”>

Leave a Reply