assembly: fix support of link to a link array
This commit is contained in:
parent
871b945cf6
commit
4eb9910b02
39
assembly.py
39
assembly.py
|
@ -25,13 +25,22 @@ def getProxy(obj,tp):
|
||||||
checkType(obj,tp)
|
checkType(obj,tp)
|
||||||
return obj.Proxy
|
return obj.Proxy
|
||||||
|
|
||||||
def getLinkProperty(obj,name,default):
|
def getLinkProperty(obj,name,default=None,writable=False):
|
||||||
try:
|
try:
|
||||||
getter = getattr(obj.getLinkedObject(True),'getLinkExtProperty',None)
|
obj = obj.getLinkedObject(True)
|
||||||
return getter(name)
|
if not writable:
|
||||||
|
return obj.getLinkExtProperty(name)
|
||||||
|
name = obj.getLinkExtPropertyName(name)
|
||||||
|
if 'Immutable' in obj.getPropertyStatus(name):
|
||||||
|
return default
|
||||||
|
return getattr(obj,name)
|
||||||
except Exception:
|
except Exception:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
def setLinkProperty(obj,name,val):
|
||||||
|
obj = obj.getLinkedObject(True)
|
||||||
|
setattr(obj,obj.getLinkExtPropertyName(name),val)
|
||||||
|
|
||||||
def resolveAssembly(obj):
|
def resolveAssembly(obj):
|
||||||
'''Try various ways to obtain an assembly from the input object
|
'''Try various ways to obtain an assembly from the input object
|
||||||
|
|
||||||
|
@ -742,35 +751,37 @@ def getElementInfo(parent,subname,checkPlacement=False,shape=None):
|
||||||
|
|
||||||
# special treatment of link array (i.e. when ElementCount!=0), we
|
# special treatment of link array (i.e. when ElementCount!=0), we
|
||||||
# allow the array element to be moveable by the solver
|
# allow the array element to be moveable by the solver
|
||||||
if getLinkProperty(part,'ElementCount',0):
|
if getLinkProperty(part,'ElementCount'):
|
||||||
|
|
||||||
# store both the part (i.e. the link array), and the array
|
# store both the part (i.e. the link array), and the array
|
||||||
# element object
|
# element object
|
||||||
part = (part,part.getSubObject(names[1]+'.',1))
|
part = (part,part.getSubObject(names[1]+'.',1))
|
||||||
|
|
||||||
# trim the subname to be after the array element
|
# trim the subname to be after the array element
|
||||||
sub = '.'.join(names[2:])
|
subname = '.'.join(names[2:])
|
||||||
|
|
||||||
# There are two states of an link array.
|
# There are two states of an link array.
|
||||||
if getLinkProperty(part[0],'ElementList',None):
|
if getLinkProperty(part[0],'ElementList'):
|
||||||
# a) The elements are expanded as individual objects, i.e
|
# a) The elements are expanded as individual objects, i.e
|
||||||
# when ElementList has members, then the moveable Placement
|
# when ElementList has members, then the moveable Placement
|
||||||
# is a property of the array element. So we obtain the shape
|
# is a property of the array element. So we obtain the shape
|
||||||
# before 'Placement' by setting 'transform' set to False.
|
# before 'Placement' by setting 'transform' set to False.
|
||||||
if not shape:
|
if not shape:
|
||||||
shape=part[1].getSubObject(sub,transform=False)
|
shape=part[1].getSubObject(subname,transform=False)
|
||||||
pla = part[1].Placement
|
pla = part[1].Placement
|
||||||
obj = part[0].getLinkedObject(False)
|
obj = part[0].getLinkedObject(False)
|
||||||
partName = part[1].Name
|
partName = part[1].Name
|
||||||
idx = int(partName.split('_i')[-1])
|
idx = int(partName.split('_i')[-1])
|
||||||
part = (part[0],idx,part[1],False)
|
part = (part[0],idx,part[1],False)
|
||||||
else:
|
else:
|
||||||
|
plaList = getLinkProperty(part[0],'PlacementList',None,True)
|
||||||
|
if plaList:
|
||||||
# b) The elements are collapsed. Then the moveable Placement
|
# b) The elements are collapsed. Then the moveable Placement
|
||||||
# is stored inside link object's PlacementList property. So,
|
# is stored inside link object's PlacementList property. So,
|
||||||
# the shape obtained below is already before 'Placement',
|
# the shape obtained below is already before 'Placement',
|
||||||
# i.e. no need to set 'transform' to False.
|
# i.e. no need to set 'transform' to False.
|
||||||
if not shape:
|
if not shape:
|
||||||
shape=part[1].getSubObject(sub)
|
shape=part[1].getSubObject(subname)
|
||||||
obj = part[1]
|
obj = part[1]
|
||||||
try:
|
try:
|
||||||
idx = int(names[1].split('_i')[-1])
|
idx = int(names[1].split('_i')[-1])
|
||||||
|
@ -779,15 +790,13 @@ def getElementInfo(parent,subname,checkPlacement=False,shape=None):
|
||||||
# that when the elements are collapsed, there is really
|
# that when the elements are collapsed, there is really
|
||||||
# no element object here.
|
# no element object here.
|
||||||
part = (part[0],idx,part[1],True)
|
part = (part[0],idx,part[1],True)
|
||||||
pla = part[0].PlacementList[idx]
|
pla = plaList[idx]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise RuntimeError('invalid array subname of element {}: '
|
raise RuntimeError('invalid array subname of element '
|
||||||
'{}'.format(objName(parent),subnameRef))
|
'{}: {}'.format(objName(parent),subnameRef))
|
||||||
|
|
||||||
partName = '{}.{}.'.format(part[0].Name,idx)
|
partName = '{}.{}.'.format(part[0].Name,idx)
|
||||||
|
|
||||||
subname = sub
|
|
||||||
|
|
||||||
if not obj:
|
if not obj:
|
||||||
# Here means, either the 'part' is an assembly or it is a non array
|
# Here means, either the 'part' is an assembly or it is a non array
|
||||||
# object. We trim the subname reference to be relative to the part
|
# object. We trim the subname reference to be relative to the part
|
||||||
|
@ -956,9 +965,9 @@ class AsmElementLink(AsmBase):
|
||||||
'''
|
'''
|
||||||
if isinstance(part,tuple):
|
if isinstance(part,tuple):
|
||||||
if part[3]:
|
if part[3]:
|
||||||
part[0].PlacementList = {part[1]:pla}
|
setLinkProperty(part[0],'PlacementList',{part[1]:pla})
|
||||||
else:
|
else:
|
||||||
part[1].Placement = pla
|
part[2].Placement = pla
|
||||||
else:
|
else:
|
||||||
part.Placement = pla
|
part.Placement = pla
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user