iLogic - Creating STL with options

This widget could not be displayed.

iLogic - Creating STL with options

Anonymous
Not applicable

I created a iLogic routine to generate a STL file if the iProperty "Printed Part" is set to YES.  

I am getting an error when Ln33 oTranslator.SaveCopyAs(oDocument, oContext, oOptions, oData) is executed.

Any help would be appriciated

 

If iProperties.Value("Custom", "Printed Part") = False Then 'False = "NO"
	Return
Else
	MsgBox ("Selected to output STL for printing" & vbCrLf & "Disable by setting the custom iProperty:Printed Part to NO")
End If

'Create _OUTPUTS directory
oPath = ThisDoc.Path
oFolder = oPath & "\" & iProperties.Value("Custom", "Output Directory")
'Check for the custom iProperty directory and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

' Get the STL translator Add-In.
Dim oTranslator As TranslatorAddIn
oTranslator = ThisApplication.ApplicationAddIns.ItemById ("{533E9A98-FC3B-11D4-8E7E-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
'Configure options and write out
If oTranslator.HasSaveCopyAsOptions (ThisApplication.ActiveDocument, oContext, oOptions) Then
	oOptions.Value("ExportUnits") = 1	'Inch	'Based off of index in combo box in STL Export Dialog
	oOptions.Value("Resolution") = 1	'High	'Based off of index of radio buttons in STL Export Dialog
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    Dim oData As DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
    Dim oFileName As String
	oFileName = ThisDoc.PathAndFileName(False) 
	oData.FileName =  oFolder & "\" & oFileName & " Rev " & oRevNum  & ".stl" '  
	'Write out file
	oTranslator.SaveCopyAs(oDocument, oContext, oOptions, oData)
Else
	MsgBox("!!!ERROR: STL File was not created!!!")
End If

 

0 Likes
Reply
Accepted solutions (1)
2,395 Views
7 Replies
Replies (7)

Anonymous
Not applicable

I did find one code error, but did not fix my issue

Ln30 should be: 

oFileName = ThisDoc.FileName(False) 
0 Likes

mrattray
Advisor
Advisor

You'll likely get a better response to programming questions on the Inventor Customization forum. This is where all of the developer types hang around.

Mike (not Matt) Rattray

Anonymous
Not applicable

Old post, but did you found out waht your error was+

im interested to use this code also.

 

Best regards

Lennart

0 Likes

t_hascj
Autodesk
Autodesk

Hi Lennart,

oDocument is uninitialized.

Thanks,
Jaroslav

0 Likes

Anonymous
Not applicable

Sorry, but i dont understand? 

Is there a code that works.

 

Thanks

Lennart

0 Likes

t_hascj
Autodesk
Autodesk
Accepted solution

You ask about solution for code in the first post. You need to initialized the oDocument.

oDocument = ThisApplication.ActiveDocument ' add this code
oTranslator.SaveCopyAs(oDocument, oContext, oOptions, oData)

Here is another code https://forums.autodesk.com/t5/inventor-forum/ilogic-save-as-stl-in-mm-with-high-quality/m-p/7287161...

Thanks.

0 Likes

Anonymous
Not applicable

Aha ok i got it.

Thanks man.

 

0 Likes