iLogic - automatically generate iMates on place

iLogic - automatically generate iMates on place

Anonymous
Not applicable
407 Views
1 Reply
Message 1 of 2

iLogic - automatically generate iMates on place

Anonymous
Not applicable

I'd like the following bit of code to place the component using iMates. 

 

SyntaxEditor Code Snippet

'file path to use
oPath = ThisDoc.Path & "\Phantom\"
'file to use
oFile = "Q02120-2.iam"
MessageBox.Show("This example is looking for this file: " & vbLf & oPath & oFile, "iLogic")

' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
    
' Create a matrix.  
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence

'place an instance of the component 
oOccurrence = oAsmCompDef.Occurrences.Add(oPath & oFile,oMatrix)  

 

I came across this post which might have something in it, but I've been unable to extract what I need from it.

 

http://forums.autodesk.com/t5/inventor-customization/design-view-representation-add-using-imates/td-...

 

Any help would be much appreciated!

0 Likes
408 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
I found something else that does the job.
The sequence of placement depends on an parameter selection.
Any ideas how I could get the model to regenerate and place the parts in the correct sequence when the parameter is changed?

Public Sub Main()
' Get the component definition of the currently open assembly.
' This will fail if an assembly document is not open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Create a new matrix object. It will be initialized to an identity matrix.
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(0,0,0))
' Place the first occurrence.
'Dim oOcc1 As ComponentOccurrence
'oOcc1 = oAsmCompDef.Occurrences.Add("C:\Part1.ipt"?, oMatrix)
' Place the second occurrence, but use iMates for its placement. This is
' equivalent to "Use iMate" check box on the "Place Component" dialog.
Dim oOccEnumerator As ComponentOccurrencesEnumerator
oOccEnumerator = oAsmCompDef.Occurrences.AddUsingiMates("C:\_Vault-WIP\Work Files\Case Masters\Inca X\Phantom\Q02120-2.iam", False)
' Since the 'PlaceAllMatching' flag was specified as False, we can be
' sure that just one ComponentOccurrence was returned in the enumerator.
'oOcc1 = oOccEnumerator.Item(1)
Dim oOccEnumerator2 As ComponentOccurrencesEnumerator oOccEnumerator2 = oAsmCompDef.Occurrences.AddUsingiMates("C:\_Vault-WIP\Work Files\Case Masters\Inca X\Phantom\Q02120-4.iam", False) Dim oOccEnumerator3 As ComponentOccurrencesEnumerator oOccEnumerator3 = oAsmCompDef.Occurrences.AddUsingiMates("C:\_Vault-WIP\Work Files\Case Masters\Inca X\Phantom\Q02120-3.iam", False) End Sub


  

 

0 Likes