assembly: fix adding constraint in sub-assembly
This commit is contained in:
parent
3427dc0461
commit
735d6ac260
61
assembly.py
61
assembly.py
|
@ -1042,6 +1042,9 @@ class AsmConstraint(AsmGroup):
|
||||||
elementInfo = []
|
elementInfo = []
|
||||||
assembly = None
|
assembly = None
|
||||||
selSubname = None
|
selSubname = None
|
||||||
|
infos = []
|
||||||
|
# first pass, collect hierarchy information, and find active assemble to
|
||||||
|
# use, i.e. which assembly to constraint
|
||||||
for sub in subs:
|
for sub in subs:
|
||||||
sobj = sel.Object.getSubObject(sub,1)
|
sobj = sel.Object.getSubObject(sub,1)
|
||||||
if not sobj:
|
if not sobj:
|
||||||
|
@ -1053,35 +1056,40 @@ class AsmConstraint(AsmGroup):
|
||||||
raise RuntimeError('Selection {}.{} is not from an '
|
raise RuntimeError('Selection {}.{} is not from an '
|
||||||
'assembly'.format(sel.Object.Name,sub))
|
'assembly'.format(sel.Object.Name,sub))
|
||||||
|
|
||||||
if not assembly:
|
infos.append((sub,sobj,ret))
|
||||||
assembly = ret[0].Assembly
|
|
||||||
selSubname = sub[:-len(ret[0].Subname)]
|
|
||||||
found = ret[0]
|
|
||||||
else:
|
|
||||||
found = None
|
|
||||||
for r in ret:
|
|
||||||
if r.Assembly == assembly:
|
|
||||||
found = r
|
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
raise RuntimeError('Selection {}.{} is not from the target '
|
|
||||||
'assembly {}'.format(
|
|
||||||
sel.Object.Name,sub,objName(assembly)))
|
|
||||||
|
|
||||||
if isTypeOf(sobj,Assembly,True):
|
if isTypeOf(sobj,Assembly,True):
|
||||||
continue
|
assembly = ret[-1].Assembly
|
||||||
|
if sub:
|
||||||
|
selSubname = sub
|
||||||
|
elif isTypeOf(sobj,(AsmConstraintGroup,AsmConstraint)):
|
||||||
|
assembly = ret[-1].Assembly
|
||||||
|
selSubname = sub[:-len(ret[-1].Subname)]
|
||||||
|
elif not assembly:
|
||||||
|
assembly = ret[0].Assembly
|
||||||
|
selSubname = sub[:-len(ret[0].Subname)]
|
||||||
|
|
||||||
|
# second pass, collect element information
|
||||||
|
for sub,sobj,ret in infos:
|
||||||
|
found = None
|
||||||
|
for r in ret:
|
||||||
|
if r.Assembly == assembly:
|
||||||
|
found = r
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
raise RuntimeError('Selection {}.{} is not from the target '
|
||||||
|
'assembly {}'.format(
|
||||||
|
sel.Object.Name,sub,objName(assembly)))
|
||||||
|
|
||||||
# check if the selection is a constraint group or a constraint
|
|
||||||
if isTypeOf(sobj,Assembly,True) or \
|
if isTypeOf(sobj,Assembly,True) or \
|
||||||
isTypeOf(sobj,(AsmConstraintGroup,AsmConstraint)):
|
isTypeOf(sobj,AsmConstraintGroup):
|
||||||
if isTypeOf(sobj,AsmConstraint):
|
|
||||||
if cstr:
|
|
||||||
raise RuntimeError('more than one constraint selected')
|
|
||||||
assembly = ret[-1].Assembly
|
|
||||||
selSubname = sub[:-len(ret[-1].Subname)]
|
|
||||||
cstr = sobj
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if isTypeOf(sobj,AsmConstraint):
|
||||||
|
if cstr:
|
||||||
|
raise RuntimeError('more than one constraint selected')
|
||||||
|
cstr = sobj
|
||||||
|
continue
|
||||||
|
|
||||||
# because we call Assembly.find() above with relativeToChild=False,
|
# because we call Assembly.find() above with relativeToChild=False,
|
||||||
# we shall adjust the element subname by popping the first '.'
|
# we shall adjust the element subname by popping the first '.'
|
||||||
|
@ -1148,9 +1156,10 @@ class AsmConstraint(AsmGroup):
|
||||||
|
|
||||||
if sel.SelObject:
|
if sel.SelObject:
|
||||||
FreeCADGui.Selection.clearSelection()
|
FreeCADGui.Selection.clearSelection()
|
||||||
subname = sel.SelSubname
|
if sel.SelSubname:
|
||||||
if subname:
|
subname = sel.SelSubname
|
||||||
subname += '.'
|
else:
|
||||||
|
subname = ''
|
||||||
subname += sel.Assembly.Proxy.getConstraintGroup().Name + \
|
subname += sel.Assembly.Proxy.getConstraintGroup().Name + \
|
||||||
'.' + cstr.Name + '.'
|
'.' + cstr.Name + '.'
|
||||||
FreeCADGui.Selection.addSelection(sel.SelObject,subname)
|
FreeCADGui.Selection.addSelection(sel.SelObject,subname)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user