Python Forum
IFC entities extracted twice
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IFC entities extracted twice
#14
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:
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;
stage3
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)
        
        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,$);
Reply


Messages In This Thread
RE: Help with Python and ifcopenshell - by Larz60+ - Mar-17-2019, 07:17 AM
IFC entities extracted twice - by gurbhej_singh - Apr-11-2019, 09:25 AM
RE: IFC entities extracted twice - by Larz60+ - Apr-12-2019, 12:38 AM
RE: Help with Python and ifcopenshell - by Larz60+ - Apr-11-2019, 09:42 AM
RE: Help with Python and ifcopenshell - by Larz60+ - Apr-11-2019, 02:36 PM
RE: Help with Python and ifcopenshell - by Larz60+ - Apr-11-2019, 10:08 PM
RE: Help with Python and ifcopenshell - by Larz60+ - Apr-11-2019, 11:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  naming entities(city abbreviations) tirumalaramakrishna 1 1,274 May-06-2022, 11:22 AM
Last Post: jefsummers
  How to couunt extracted values ? Eidrizi 0 1,512 Sep-10-2020, 06:05 AM
Last Post: Eidrizi
  instaloaders problem: search certain hashtag - posts without hashtag extracted ledgreve 0 2,180 Nov-18-2019, 01:22 PM
Last Post: ledgreve
  Seperate entities in text file bigdazza 1 2,859 Jun-02-2018, 03:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020