How to insert a part file to assembly file using ilogic (at given X,Y, Z)

How to insert a part file to assembly file using ilogic (at given X,Y, Z)

Anonymous
Not applicable
1,518 Views
2 Replies
Message 1 of 3

How to insert a part file to assembly file using ilogic (at given X,Y, Z)

Anonymous
Not applicable

Hi, I have part files saved in a folder (For ex:- C:\temp\Partfiles).... The part files names & XYZ coordinates are mentioned in the excel file in the same folder location (File name:- Parts_Coords.xlsx)...... I want to create a ilogic (For assembly file) which will open the given excel file, loop through the all rows- copy the part file name (one by one) - search in the part files folder - & once found then insert that part file in the assembly file at the coordinates given in the excel.

 Below is excel file structure:-

 

Part name                     X             Y             Z

Fan.ipt                         100         100         100

Table.ipt                      500         500         500

 

Any help will be much appreciated, thanks in advance.

 

Regards,

 

Vinay

0 Likes
Accepted solutions (1)
1,519 Views
2 Replies
Replies (2)
Message 2 of 3

Yijiang.Cai
Autodesk
Autodesk
Accepted solution

I suppose you could get the file name of component plus its coordinate, and you just need to pass the file name and coordinate using the function below. The part will be inserted into the target assembly.

Public Sub AddOccurrence()
    ' Set a reference to the assembly component definintion.
    ' This assumes an assembly document is open.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Set a reference to the transient geometry object.
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    ' Create a matrix.  A new matrix is initialized with an identity matrix.
    Dim oMatrix As Matrix
    Set oMatrix = oTG.CreateMatrix

    ' Set the rotation of the matrix for a 45 degree rotation about the Z axis.
    Call oMatrix.SetToRotation(3.14159265358979 / 4, _
                            oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))

    ' Set the translation portion of the matrix so the part will be positioned
    ' at (3,2,1).
    Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))

    ' Add the occurrence.
    Dim oOcc As ComponentOccurrence
    Set oOcc = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)
End Sub
Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 3 of 3

Anonymous
Not applicable

Hi Cai,

 

Thank you very much for your help... It worked perfectly 🙂

 

Regards,

 

Vinay

0 Likes