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: 

place a list of components with iMates into an assembly using ilogic/VBA

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
waynehelley
2861 Views, 8 Replies

place a list of components with iMates into an assembly using ilogic/VBA

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,

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
8 REPLIES 8
Message 2 of 9
Robert..F
in reply to: waynehelley

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. 

Message 3 of 9
waynehelley
in reply to: Robert..F

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,

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 4 of 9
Robert..F
in reply to: waynehelley

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
Message 5 of 9
Carthik_Babu
in reply to: Robert..F

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
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 6 of 9
waynehelley
in reply to: Carthik_Babu

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.

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 7 of 9
Carthik_Babu
in reply to: waynehelley

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

 

Insert-Error.png

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 8 of 9
Carthik_Babu
in reply to: Carthik_Babu

sorry...i missed to include the path of my part file in the xl sheet. That is the bug.....Thanks for the input......
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 9 of 9
cencinaNB2ET
in reply to: Carthik_Babu

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)


 

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

Post to forums  

Autodesk Design & Make Report