albie0803
Alibre Super User
My script is giving an error
TypeError: expected IInstance, got Part
on line 36
The script is to place a bolt assembly into non patternable holes using the fastener constraint.
It will constrain the bolt assembly into the selected hole and constrain a copy of the assembly into all the holes on the face that are the same size.

TypeError: expected IInstance, got Part
on line 36
The script is to place a bolt assembly into non patternable holes using the fastener constraint.
It will constrain the bolt assembly into the selected hole and constrain a copy of the assembly into all the holes on the face that are the same size.

Python:
win = Windows()
ca = CurrentAssembly()
def NearZero(value):
if abs(value) < 0.00000001:
return 1
return 0
options = []
values = []
own_face = None
options.append(['Select bolt set edge' , WindowsInputTypes.Edge , None])
options.append(['Select a hole edge' , WindowsInputTypes.Edge , None])
values = win.OptionsDialog( 'Select Faces to Mate', options , 180 )
# get edges
blt_edge = values[0]
own_edge = values[1]
# get the sub assembly blt_edge is part of
blt_part = blt_edge.GetPart()
blt_ass = blt_part.GetAssembly() # <=== Problem starts here?
blt_Sub = ca.GetSubAssembly(blt_ass.Name + '<1>')
# determine the face and part that the hole is on
Sel_Edge = values[1].SelectableObject()
EdgeFaces = Sel_Edge.Faces
for x in range(EdgeFaces.Count):
edge_count = Face(EdgeFaces.Item(x)).GetEdges()
if len(edge_count) > 2:
own_face = Face(EdgeFaces.Item(x))
P1 = own_face.GetPart()
dia = own_edge.Diameter
# constrain original fastener
ca.AddFastenerConstraint(0,0,blt_Sub,blt_edge,P1, own_edge,False,'bolted')
if win.QuestionDialog('Does the Fastener Constraint need to Flipped?', 'Flip Constraint') == True:
flip = True
# get the other matching holes and put a bolt assembly in them
holelist = []
holelist = own_face.GetEdges()
for i in range(len(holelist)):
if NearZero(holelist[i].Diameter - dia):
if holelist[i].Name != own_edge.Name:
sub_assy1 = ca.DuplicateSubAssembly(blt_Sub,0,0,0)
ca.AddMateConstraint(0, sub_assy1, sub_assy1.YZPlane, P1, own_face)
ca.AddAlignConstraint(0, sub_assy1, sub_assy1.XAxis, P1, holelist[i])
if flip == True:
win.InfoDialog('Remember to flip the first constraint!','Attention')
sys.exit('Script Complete')
Attachments
Last edited: