Community
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)
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
Can't find what you're looking for? Ask the community or share your knowledge.