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: 

CreateAssemblyJointDefinition in Inventor API with python

1 REPLY 1
Reply
Message 1 of 2
22351396
63 Views, 1 Reply

CreateAssemblyJointDefinition in Inventor API with python

I try to create an assembly joint using inventor api with python. It connects the midpoints of the edges of two faces using a rotational joint. 

import win32com.client as wc

try:
  
    inv = wc.GetActiveObject('Inventor.Application')
 
    inv_assembly_document = inv.Documents.Add(12291, inv.FileManager.GetTemplateFile(12291, 8962))

    assembly_com_definition = inv_assembly_document.ComponentDefinition

    tg = inv.TransientGeometry
    trans = tg.CreateMatrix()
    part_path = r'C:\\Users\\MINHAZULISLAM\\Desktop\\API Join\\Part1.ipt'
    
    matrix1 = tg.CreateMatrix()
    translation_vector1 = tg.CreateVector(0, 0, 0)
    matrix1.SetTranslation(translation_vector1)
    occ1 = assembly_com_definition.Occurrences.Add(part_path, matrix1)
    part_path2 = r'C:\\Users\\MINHAZULISLAM\\Desktop\\API Join\\Part2.ipt'
    matrix2 = tg.CreateMatrix()

    translation_vector2 = tg.CreateVector(8, 6, 2)
    matrix2.SetTranslation(translation_vector2)
    occ2 = assembly_com_definition.Occurrences.Add(part_path2, matrix2)

    face1 = occ1.SurfaceBodies.Item(1).Faces.Item(1)
    face2 = occ2.SurfaceBodies.Item(1).Faces.Item(1)
    edge1 = occ1.SurfaceBodies.Item(1).Edges.Item(1)
    edge2 = occ2.SurfaceBodies.Item(1).Edges.Item(1)
    
    intent1edge1 = assembly_com_definition.CreateGeometryIntent(edge1, 57871)
    intent2edge1 = assembly_com_definition.CreateGeometryIntent(edge2, 57860)
    intent_point1 = assembly_com_definition.CreateGeometryIntent(face1,intent1edge1)  
    intent_point2 = assembly_com_definition.CreateGeometryIntent(face2,intent2edge1) 
    assembly_join=assembly_com_definition.Joints
    joint_def=assembly_join.CreateAssemblyJointDefinition(102401, intent_point1, intent_point2)

    
    
    joint = assembly_com_definition.Joints.Add(joint_def)
    print("Making joint visible...")
    joint.Visible = True
    assembly_path = r'C:\\Users\\MINHAZULISLAM\\Desktop\\API Join\\assembly1v1.iam'
    print(f"Saving assembly document to {assembly_path}...")
    inv_assembly_document.SaveAs(assembly_path, True)

    print("Script completed successfully.")

except Exception as e:
    print(f"An error occurred: {e}")


An error occurred: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147467259), None)

1 REPLY 1
Message 2 of 2
YuhanZhang
in reply to: 22351396

If you mean to contect the mid-point of two linear edges, you can update your code to below:

 

intent1edge1 = assembly_com_definition.CreateGeometryIntent(edge1, 57859)
intent2edge1 = assembly_com_definition.CreateGeometryIntent(edge2, 57859)

 

Hope above helps.

 

Thanks,

Rocky



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

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

Post to forums  

Autodesk Design & Make Report