Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic - Creating STL with options

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
nick.tinney
2003 Views, 7 Replies

iLogic - Creating STL with options

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

 

Tags (2)
7 REPLIES 7
Message 2 of 8
nick.tinney
in reply to: nick.tinney

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

Ln30 should be: 

oFileName = ThisDoc.FileName(False) 
Message 3 of 8
mrattray
in reply to: nick.tinney

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

Message 4 of 8
lennart.losjo
in reply to: nick.tinney

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

im interested to use this code also.

 

Best regards

Lennart

Message 5 of 8
t_hascj
in reply to: lennart.losjo

Hi Lennart,

oDocument is uninitialized.

Thanks,
Jaroslav

Message 6 of 8
lennart.losjo
in reply to: t_hascj

Sorry, but i dont understand? 

Is there a code that works.

 

Thanks

Lennart

Message 7 of 8
t_hascj
in reply to: lennart.losjo

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.

Message 8 of 8
lennart.losjo
in reply to: t_hascj

Aha ok i got it.

Thanks man.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report