Can iLogic can export individual Positions?

Can iLogic can export individual Positions?

HaiderAlghifary
Contributor Contributor
512 Views
7 Replies
Message 1 of 8

Can iLogic can export individual Positions?

HaiderAlghifary
Contributor
Contributor

I would like to ask about the capabilities of iLogic.

 

Let's say we have a model with ten different Positions.

My requirement is to export an OBJ file, model unit in centimeters, for each Position in the model.

 

Is this achievable with iLogic?

 

HaiderAlghifary_0-1713530174432.png

 

0 Likes
Accepted solutions (1)
513 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

What do you mean by "Positions"?  Is this a transient 2D point object, a transient 3D Point object, a sketch point within a 2D sketch, a sketch point within a 3D sketch,...?  Please explain in more detail, and maybe using different terminology, so we can better understand what you want.  Also, are you able to do what you want manually (without using any code)?  If so, then maybe if you explained how you do it manually, in detailed steps, we can also create code to to that process.  If you can not do it manually, then we very likely can not do it by code either.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

HaiderAlghifary
Contributor
Contributor

Hi @WCrihfield 

Sorry for the confusion - I corrected the term to "Model States".

The manual process requires a manual click to activate and then export the model one by one.

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

OK, then yes, that does sound possible.  We can navigate to the ModelStates collection of a model document, then as it iterates through them it can activate each ModelState, then export the document to some other format, before then moving on to the next ModelState, all by code.

 

I do not use the OBJ file type though, so I would have to create a block of code for that export process.  What are your export options preferences for that process?  Below is a list of option names we have access to by code, when using the TranslatorAddIn route to export an Inventor file to OBJ file type.

ExportUnits
ExportFileStructure
Resolution
SurfaceDeviation
NormalDeviation
MaxEdgeLength
AspectRatio

You can see what the options for these are at the following online help page, down within the 'Export' area tables & their definitions.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-25D24E28-7517-4903-8AEE-123F8C71A89E&v=In... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8

Curtis_Waguespack
Consultant
Consultant

@WCrihfield wrote:

... I would have to create a block of code for that export process. 


Good news, you did this in the past! ( I just ran across this the other day, and pointed someone to your post) :

https://forums.autodesk.com/t5/inventor-programming-ilogic/fixing-quot-high-quot-resolution-export-o...

EESignature

Message 6 of 8

ryan.rittenhouse
Advocate
Advocate
Accepted solution

I'm not sure how to specify the units on an ilogic OBJ export, but this will iterate through all your position and export each one to an OBJ. You can tweak the file name pretty easily to fit your needs.

 

Dim fileName As String
Dim doc As Document = ThisDoc.Document

For Each position As PositionalRepresentation In doc.ComponentDefinition.RepresentationsManager.PositionalRepresentations
	position.Activate()
	fileName = ThisDoc.Path & "\" & position.Name & ".obj"
	doc.SaveAs(fileName, True)
Next position

 

Edited to fix the doc declaration in the code

If this solved your problem, or answered your question, please click Accept Solution.
Message 7 of 8

HaiderAlghifary
Contributor
Contributor

@WCrihfield - once again sorry

 

It was indeed "Positions". I am not an everyday Inventor-user, hence the confusion from my side as well.

I updated the original post again, and here is a screenshot again:

 

 

HaiderAlghifary_0-1713530249739.png

 

 

0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

Hi @HaiderAlghifary.  My guess is that the solution that @ryan.rittenhouse posted may work just fine for you, but I have not tried it myself, because I rarely use positional representations, and pretty much never use OBJ files.  However, below is another possible code for this task.  The Sub main area is laid out mostly the same, but this uses the TranslatorAddIn object specifically for exporting OBJ files, and gives you the opportunity to specify those 'Options' when exporting those files.  This is very similar to the old code I posted at the link above, but with the mistake fixed, and more documentation included for each of the individual options, to make it easier to specify what you want.  It also includes a small block of code that will check if that file (it is about to export to) already exists.  And if it does, it will let you know, and ask you if you want to overwrite it or not.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim oRepsMgr As RepresentationsManager = oADoc.ComponentDefinition.RepresentationsManager
	Dim oPosReps As PositionalRepresentations = oRepsMgr.PositionalRepresentations
	Dim oAPosRep As PositionalRepresentation = oRepsMgr.ActivePositionalRepresentation
	Dim sPathAndName As String = ThisDoc.PathAndFileName(False)
	For Each oPosRep As PositionalRepresentation In oPosReps
		oPosRep.Activate
		Dim sOBJ_File As String = sPathAndName & oPosRep.Name & ".obj"
		ExportToOBJ(oDoc, sOBJ_File)
	Next 'oPosRep
End Sub

Sub ExportToOBJ(oDoc As Inventor.Document, sNewFullFileName As String)
	Dim sOBJ_Exporter_TranslatorAddIn_ClientID As String = "{F539FB09-FC01-4260-A429-1818B14D6BAC}"
	Dim oOBJ As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById(sOBJ_Exporter_TranslatorAddIn_ClientID)
	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oContext As TranslationContext = oTO.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	Dim oOptions As NameValueMap = oTO.CreateNameValueMap
	Dim oDataMedium As DataMedium = oTO.CreateDataMedium
	'<<< check if that exported file already exists, if so, notify user & ask if it should be overwritten >>>
	If System.IO.File.Exists(sNewFullFileName) = True Then
		Dim oAns As MsgBoxResult = MsgBox("The following file already exists." & vbCrLf & _
		sNewFullFileName & vbCrLf & _
		"Do you want to overwrite it?", vbYesNo + vbQuestion + vbDefaultButton2, "File Already Exists")
		If oAns = MsgBoxResult.No Then Exit Sub
	End If
	'set output file's full path, file name, and file extension here
	oDataMedium.FileName = sNewFullFileName
	If oOBJ.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
		'Inch = 2 ; Foot = 3 ; Centimeter = 4 ; Millimeter = 5 ; Meter = 6 ; Micron = 7
		oOptions.Value("ExportUnits") = 0 '(I assume 0 = 'Source Units')
		'One File = 0 ; One File Per Part Instance = 1
		oOptions.Value("ExportFileStructure") = 0
		'High = 0 ; Medium = 1 ; Low = 2 ; Custom = 3 ; BREP = 4
		oOptions.Value("Resolution") = 0
		'<<< the following 4 options will be ignored if the 'Resolution' is NOT set to 3 (Custom) >>>
		'Range 0 to 100, with precision to 0.0001 (percentage)
		oOptions.Value("SurfaceDeviation") = 0
		'Range 0 to 41 (any value outside of this range will be forced to 14)
		oOptions.Value("NormalDeviation") = 0
		'Range 0 to 100 (percentage)
		oOptions.Value("MaxEdgeLength") = 0
		'Range 0 to 21.5
		oOptions.Value("AspectRatio") = 0
		Try
			oOBJ.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
			Logger.Error("Exported following document:" & vbCrLf & _
			oDoc.FullDocumentName & vbCrLf & _
			"to the following OBJ file:" & vbCrLf & _
			sNewFullFileName)
		Catch
			Logger.Error("Error exporting following document:" & vbCrLf & _
			oDoc.FullDocumentName & vbCrLf & _
			"to the following OBJ file:" & vbCrLf & _
			sNewFullFileName)
		End Try
	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) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)