Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fixing "high" resolution export option for .obj in VB script

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
1261 Views, 5 Replies

Fixing "high" resolution export option for .obj in VB script

Hi Team,

 

I am using autodesk inventor version 2018.

I have VB script which opens and exports a list of CAD files to .obj format.

I need to lock the resolution of export as "High", when i manually do 1 export in "high" resolution and run the VB script, it reverts back to "BREP" resolution.

Can someone please help me with the syntax i have to include in my VB script to fix the resolution at "high".

 

Thanks in advance

5 REPLIES 5
Message 2 of 6
WCrihfield
in reply to: Anonymous

I'm using Inventor 2021.2.2, so I'm not 100% sure all of this will work for you, but here is what I've got for you.  This was written in iLogic, but iLogic uses VB.NET as its basis, so it should still be compatible with your vb project with minimal tweaks.  It shows you how to work with Inventor's translator add-in (in case your not currently), and which options are available for you to set the way you want them by code.  I don't currently know of any official documentation that specified what all the possible values to these options stand for, but with a little trial & error testing, you could likely figure it out on your own.  I don't use this specific translator myself, so I don't have any personal experience based options values meanings for you, other than having just seen the default values in the dialog just before capturing the current options and their values to see what they were, before producing this code solution for you.

Here is the iLogic code for exporting Part or Assembly to OBJ file:

Sub Main 'Sub ExportToOBJ(oDoc As Inventor.Document)
	Dim oApp As Inventor.Application = ThisApplication
	Dim oDoc As Document = oApp.ActiveDocument
	Dim oOBJ As TranslatorAddIn
	For Each oAppAddin As ApplicationAddIn In oApp.ApplicationAddIns
		If oAppAddin.DisplayName = "Translator: OBJ Export" Then
			oOBJ = oAppAddin
		End If
	Next

	'The following lines create the needed input variables
	Dim oTO As TransientObjects = oApp.TransientObjects
	Dim oContext As TranslationContext = oTO.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kUnspecifiedIOMechanism
	Dim oOptions As NameValueMap = oTO.CreateNameValueMap
	Dim oDataMedium As DataMedium = oTO.CreateDataMedium

	'set these options the way you want them here
	oOptions.Value("ExportUnits") = 0 '(I assume 0 is 'Source Units' in the dialog)
	oOptions.Value("Resolution") = 1 '(I believe 1 = High, and 4 = Brep in the dialog)
	oOptions.Value("SurfaceDeviation") = 16 '(I assume 16 is default in dialog)
	oOptions.Value("NormalDeviation") = 1500 '(I assume 1500 is default in dialog)
	oOptions.Value("MaxEdgeLength") = 100000 '(I assume 100000 is default in dialog)
	oOptions.Value("AspectRatio") = 2150 '(represents 21.5 in the dialog - default setting)
	oOptions.Value("ExportFileStructure") = 0 '(I assume 0 is 'One File' in the dialog)

	'set output file's path and file name here
	'the way it is set-up right now, it will save to the same location,
	'and same file name as original document, 'but with the .obj file extension
	oDataMedium.FileName = System.IO.Path.ChangeExtension(oDoc.FullFileName, ".obj")

	If oOBJ.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
		oOBJ.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
	End If
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6
w.poortinga
in reply to: WCrihfield

I'm using the code above in my .iam but getting the following error on the last line:

 

wpoortinga_0-1649325865152.png

 

When removing the last line:

oOBJ.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)

The file obviously doesn't get saved but I'm not receiving an error either. 


Is there anything I can do to fix this?

 

My goal is to save multiple instances (in .obj format) of my file with parameter changes inbetween.

Message 4 of 6

I found the problem;

 

The context.Type should be kFileBrowseIOMechanism instead of kUnspecifiedIOMechanism

 

	Dim oContext As TranslationContext = oTO.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

 

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


Message 5 of 6

That's great, you're a hero 🙂

I got it to work now. Thanks again.

Message 6 of 6
atsushi_kuno
in reply to: Anonymous

Let me add this link as a reference in case of losing what parameters should be set in future.

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

Post to forums  

Autodesk Design & Make Report