Skip to content

Commit

Permalink
Arch: Allow for several IFC properties with same name (in different p…
Browse files Browse the repository at this point in the history
…sets)
  • Loading branch information
yorikvanhavre committed Apr 11, 2019
1 parent 86c11cd commit d02378a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Mod/Arch/importIFC.py
Expand Up @@ -905,6 +905,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
# handle properties

if pid in properties:

if IMPORT_PROPERTIES and hasattr(obj,"IfcProperties"):

# treat as spreadsheet (pref option)
Expand Down Expand Up @@ -957,6 +958,7 @@ def insert(filename,docname,skip=[],only=[],root=None):

d = obj.IfcProperties
for pset in properties[pid].keys():
#print("adding pset",pset,"to object",obj.Label)
psetname = ifcfile[pset].Name
if six.PY2:
psetname = psetname.encode("utf8")
Expand All @@ -976,7 +978,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
if hasattr(e.NominalValue,'Unit'):
if e.NominalValue.Unit:
pvalue += e.NominalValue.Unit
d[pname] = psetname+";;"+ptype+";;"+pvalue
d[pname+";;"+psetname] = ptype+";;"+pvalue
#print("adding property: ",pname,ptype,pvalue," pset ",psetname)
obj.IfcProperties = d

Expand Down Expand Up @@ -1821,22 +1823,29 @@ def export(exportList,filename):
psets = {}
for key,value in obj.IfcProperties.items():

# properties in IfcProperties dict are stored as "key":"pset;;type;;value" or "key":"type;;value"
# in 0.18, properties in IfcProperties dict are stored as "key":"pset;;type;;value" or "key":"type;;value"
# in 0.19, key = name;;pset, value = ptype;;value (because there can be several props with same name)

pset = None
pname = key
if ";;" in pname:
pname = key.split(";;")[0]
pset = key.split(";;")[-1]
value = value.split(";;")
if len(value) == 3:
pset = value[0]
ptype = value[1]
pvalue = value[2]
elif len(value) == 2:
pset = "Default property set"
if not pset:
pset = "Default property set"
ptype = value[0]
pvalue = value[1]
else:
if DEBUG:print(" unable to export property:",key,value)
if DEBUG:print(" unable to export property:",pname,value)
continue

#if DEBUG: print(" property ",key," : ",pvalue.encode("utf8"), " (", str(ptype), ") in ",pset)
#if DEBUG: print(" property ",pname," : ",pvalue.encode("utf8"), " (", str(ptype), ") in ",pset)
if ptype in ["IfcLabel","IfcText","IfcIdentifier",'IfcDescriptiveMeasure']:
if six.PY2:
pvalue = pvalue.encode("utf8")
Expand All @@ -1861,8 +1870,8 @@ def export(exportList,filename):
except:
if six.PY2:
pvalue = pvalue.encode("utf8")
if DEBUG:print(" warning: unable to export property as numeric value:",key,pvalue)
p = ifcbin.createIfcPropertySingleValue(str(key),str(ptype),pvalue)
if DEBUG:print(" warning: unable to export property as numeric value:",pname,pvalue)
p = ifcbin.createIfcPropertySingleValue(str(pname),str(ptype),pvalue)
psets.setdefault(pset,[]).append(p)
for pname,props in psets.items():
pset = ifcfile.createIfcPropertySet(ifcopenshell.guid.compress(uuid.uuid1().hex),history,pname,None,props)
Expand Down

0 comments on commit d02378a

Please sign in to comment.