Apr-11-2019, 11:56 PM
Ok, I have managed to isolate where the duplicates are coming from.
To show this, I restructured your code a bit, to my style, so I could move around quicker,
code now looks like:
main module:
stage 1:
This file format is totally new to me, but on looking in the model file, i see:
I wonder, does (#1, #2, $) mean include #1: (#1=IFCPERSON($,$,'',$,$,$,$,$);) and
include #2: #2=IFCORGANIZATION($,'',$,$,$); and
include $ (self?): #5=IFCPERSONANDORGANIZATION(#3,#4,$);
To show this, I restructured your code a bit, to my style, so I could move around quicker,
code now looks like:
main module:
import IFCpaths import ifcopenshell import sys class ifc: def __init__(self): self.ipath = IFCpaths.IFCpaths() self.f = ifcopenshell.open(self.ipath.ModelFull) self.f2 = ifcopenshell.file() self.process() def process(self): persons = self.f.by_type("IFCPERSON") for person in persons: self.f2.add(person) organizations = self.f.by_type("IFCORGANIZATION") for organization in organizations: self.f2.add(organization) personorganizations = self.f.by_type("IFCPERSONANDORGANIZATION") for personorganization in personorganizations: self.f2.add(personorganization) self.f2.write("test222.ifc") if __name__ == '__main__': ifc()IFCpaths.py
import os from pathlib import Path class IFCpaths: def __init__(self): os.chdir(os.path.abspath(os.path.dirname(__file__))) self.homepath = Path('.') self.rootpath = self.homepath / '..' self.datapath = self.rootpath / 'data' self.datapath.mkdir(exist_ok=True) self.beam_material = self.datapath / 'Beam_Material.ifc' self.ModelFull = self.datapath / 'ModelFull.ifc' self.testfile = self.datapath / 'test222.ifc'Now to isolate the duplication, i wrote the output bit by bit
stage 1:
import IFCpaths import ifcopenshell import sys class ifc: def __init__(self): self.ipath = IFCpaths.IFCpaths() self.f = ifcopenshell.open(self.ipath.ModelFull) self.f2 = ifcopenshell.file() self.process() def process(self): persons = self.f.by_type("IFCPERSON") for person in persons: print(f'person: {person}') self.f2.add(person) self.f2.write("test222.ifc") sys.exit(0) organizations = self.f.by_type("IFCORGANIZATION") for organization in organizations: print(f'organization: {organization}') self.f2.add(organization) personorganizations = self.f.by_type("IFCPERSONANDORGANIZATION") for personorganization in personorganizations: print(f'personorganization: {personorganization}') self.f2.add(personorganization) self.f2.write("test222.ifc") if __name__ == '__main__': ifc()output (all ok):
Output:ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1');
FILE_NAME('','2019-04-11T19:46:26',(),(),'IfcOpenShell 0.5.0-dev','IfcOpenShell 0.5.0-dev','');
FILE_SCHEMA(('IFC2X3'));
ENDSEC;
DATA;
#1=IFCPERSON($,$,'',$,$,$,$,$);
ENDSEC;
END-ISO-10303-21;
stage 2:import IFCpaths import ifcopenshell import sys class ifc: def __init__(self): self.ipath = IFCpaths.IFCpaths() self.f = ifcopenshell.open(self.ipath.ModelFull) self.f2 = ifcopenshell.file() self.process() def process(self): persons = self.f.by_type("IFCPERSON") for person in persons: print(f'person: {person}') self.f2.add(person) organizations = self.f.by_type("IFCORGANIZATION") for organization in organizations: print(f'organization: {organization}') self.f2.add(organization) self.f2.write("test222.ifc") sys.exit(0) personorganizations = self.f.by_type("IFCPERSONANDORGANIZATION") for personorganization in personorganizations: print(f'personorganization: {personorganization}') self.f2.add(personorganization) self.f2.write("test222.ifc") if __name__ == '__main__': ifc()output (all still ok):
Output:ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1');
FILE_NAME('','2019-04-11T19:48:24',(),(),'IfcOpenShell 0.5.0-dev','IfcOpenShell 0.5.0-dev','');
FILE_SCHEMA(('IFC2X3'));
ENDSEC;
DATA;
#1=IFCPERSON($,$,'',$,$,$,$,$);
#2=IFCORGANIZATION($,'',$,$,$);
ENDSEC;
END-ISO-10303-21;
stage3import IFCpaths import ifcopenshell import sys class ifc: def __init__(self): self.ipath = IFCpaths.IFCpaths() self.f = ifcopenshell.open(self.ipath.ModelFull) self.f2 = ifcopenshell.file() self.process() def process(self): persons = self.f.by_type("IFCPERSON") for person in persons: print(f'person: {person}') self.f2.add(person) organizations = self.f.by_type("IFCORGANIZATION") for organization in organizations: print(f'organization: {organization}') self.f2.add(organization) personorganizations = self.f.by_type("IFCPERSONANDORGANIZATION") for personorganization in personorganizations: print(f'personorganization: {personorganization}') self.f2.add(personorganization) self.f2.write("test222.ifc") sys.exit(0) self.f2.write("test222.ifc") if __name__ == '__main__': ifc()output (not ok)
Output:ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1');
FILE_NAME('','2019-04-11T19:49:57',(),(),'IfcOpenShell 0.5.0-dev','IfcOpenShell 0.5.0-dev','');
FILE_SCHEMA(('IFC2X3'));
ENDSEC;
DATA;
#1=IFCPERSON($,$,'',$,$,$,$,$);
#2=IFCORGANIZATION($,'',$,$,$);
#3=IFCPERSON($,$,'',$,$,$,$,$);
#4=IFCORGANIZATION($,'',$,$,$);
#5=IFCPERSONANDORGANIZATION(#3,#4,$);
ENDSEC;
END-ISO-10303-21;
So why? ...This file format is totally new to me, but on looking in the model file, i see:
Output:#3=IFCPERSONANDORGANIZATION(#1,#2,$);
So, and this is a wild guess being totally uneducated on model file structurs, but having experience with other CAD layouts,I wonder, does (#1, #2, $) mean include #1: (#1=IFCPERSON($,$,'',$,$,$,$,$);) and
include #2: #2=IFCORGANIZATION($,'',$,$,$); and
include $ (self?): #5=IFCPERSONANDORGANIZATION(#3,#4,$);