Hi there,
I was just wondering how to place a component into an assembly using ilogic? If this is possible, is there also an option to choose if iMates will be generated?
I would ideally like to place a list of components into an assembly, the list with probably exist in excel, then have iMates set to 'Automatically generate iMates on place' so that my assembly assembles automatically.
thanks,
Solved! Go to Solution.
Solved by Robert..F. Go to Solution.
The following is a sample in vba directly from the api help:
Public Sub iMateDuringOccurrencePlacementSample() ' Get the component definition of the currently open assembly. ' This will fail if an assembly document is not open. Dim oAsmCompDef As AssemblyComponentDefinition Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Create a new matrix object. It will be initialized to an identity matrix. Dim oMatrix As Matrix Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix ' Place the first occurrence. Dim oOcc1 As ComponentOccurrence Set oOcc1 = oAsmCompDef.Occurrences.Add("C:\TempiMatePart.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 Set oOccEnumerator = oAsmCompDef.Occurrences.AddUsingiMates("C:\TempiMatePart.ipt", False) ' Since the 'PlaceAllMatching' flag was specified as False, we can be ' sure that just one ComponentOccurrence was returned in the enumerator. Dim oOcc1 As ComponentOccurrence Set oOcc1 = oOccEnumerator.Item(1) End Sub
I'm not very familiar with iLogic but I am sure it is possible in much the same way.
Thanks Robert.
When I move the code over to ilogic, it can't seem to carry out the command to place the components.
' oOcc1 = oAsmCompDef.Occurrences.Add("C:\ARTICULATE\09\090\09090GT0000008\09090P00103695.iam", oMatrix)'
Does anybody now how to make this line of code work in ilogic?
Thanks,
I've confirmed that this code is working in iLogic:
Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 7937 StartFragment: 314 EndFragment: 7905 StartSelection: 314 EndSelection: 314
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:\Part2.ipt", 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) End Sub
Dear Sir,
I am using Inventor 2011. I tried to use your code and found "'Let' and 'Set' assignment statements are no longer supported.". So i removed the code, now its asking for "Expression expected." Can you please solve the bug in the code below. Thanks in Advance - Carthik
Public Sub Main()
ins_comp("PinLink ANSI 50.ipt","RollerLink ANSI 50.ipt")
End Sub
Function ins_comp(p1 as String, p2 as String)
' 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))
'file path to use
oPath = ThisDoc.Path & "\"
'file to use
oFile = ins_comp_name
' Place the first occurrence.
Dim oOcc1 As ComponentOccurrence
MessageBox.Show("Message"&p1, "Title")
oOcc1 = oAsmCompDef.Occurrences.Add(& vbLf & oPath & p1, 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(& vbLf & oPath & p2, 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)
End Function
Hi there,
The code attached will place a list of components from a spreadsheet into an assembly.
You will have to include the file paths within the spreadsheet. You will have to adjust the file path of the spreadsheet within the code.
Dear Sir,
Thank you very much for the reply.
I tried your code and found some error. I have attached the file for your reference.
Request you to kindly open and find the bug( Note: I am using Autodesk Inventor 2011)
Thanks in advance- Carthik
Hi,
What if Im placing all?
iMate Creation During Occurrence Placement
How would I reference those particular Component Occurrences Enumerators as A component Occurrence?
AddUsingiMates(" Part/Assembly...", true)