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
Solved! Go to Solution.
Solved by basautomationservices. Go to Solution.
Solved by WCrihfield. Go to Solution.
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
(Not an Autodesk Employee)
I'm using the code above in my .iam but getting the following error on the last line:
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.
I found the problem;
The context.Type should be kFileBrowseIOMechanism instead of kUnspecifiedIOMechanism
Dim oContext As TranslationContext = oTO.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Can't find what you're looking for? Ask the community or share your knowledge.