assembly: fix support of link to a link array

This commit is contained in:
Zheng, Lei 2018-07-16 13:04:12 +08:00
parent 871b945cf6
commit 4eb9910b02

View File

@ -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,51 +751,51 @@ 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:
# b) The elements are collapsed. Then the moveable Placement plaList = getLinkProperty(part[0],'PlacementList',None,True)
# is stored inside link object's PlacementList property. So, if plaList:
# the shape obtained below is already before 'Placement', # b) The elements are collapsed. Then the moveable Placement
# i.e. no need to set 'transform' to False. # is stored inside link object's PlacementList property. So,
if not shape: # the shape obtained below is already before 'Placement',
shape=part[1].getSubObject(sub) # i.e. no need to set 'transform' to False.
obj = part[1] if not shape:
try: shape=part[1].getSubObject(subname)
idx = int(names[1].split('_i')[-1]) obj = part[1]
# we store the array index instead, in order to modified try:
# Placement later when the solver is done. Also because idx = int(names[1].split('_i')[-1])
# that when the elements are collapsed, there is really # we store the array index instead, in order to modified
# no element object here. # Placement later when the solver is done. Also because
part = (part[0],idx,part[1],True) # that when the elements are collapsed, there is really
pla = part[0].PlacementList[idx] # no element object here.
except ValueError: part = (part[0],idx,part[1],True)
raise RuntimeError('invalid array subname of element {}: ' pla = plaList[idx]
'{}'.format(objName(parent),subnameRef)) except ValueError:
raise RuntimeError('invalid array subname of element '
'{}: {}'.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
@ -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