1

I must extract data in an IFC file but when i read the file seems I make some mistake I don't undestand: First: I've a key; Second: I read a file; Third: I create a string and I put it in a csv like file. Fourth: the visual components are in Pyside2.

the code:

orderNr = self.getIFC_ProjectDetail(readFile, self.orderNrLineEdit.text())
custNr = self.getIFC_ProjectDetail(readFile, self.custNoLineEdit.text())
if len(custNr) == 0:
    custNr = "9999"
projManager = self.getIFC_ProjectDetail(readFile, self.projManagerLineEdit.text())
    drawer = self.getIFC_ProjectDetail(readFile, self.drawerLineEdit.text())

ifcFile = open(readFile, 'r')
csvFile = open(csvFileName, 'w')
lineTokens = []
csvFile.write("GUID;Type;UserText1;UserText2;UserText3;UserText4;UserText5;UserText6;UserText7;\n")
 for mainLine in ifcFile:
    if ("IFCSLAB" in line or "IFCWALLSTANDARDCASE" in line):
                if len(uID) > 0:
                    if uID == oldID:
                        uID = "ciao"
                    csvFile.write("{0};{1};{2};{3};{4};{5};{6};{7};{8};\n".format(uID, matType, orderNr, custNr, assPos, partPos, fab, projManager, drawer))
                    oldID = uID
                    uID = ""
                    matType = ""
                    assPos = ""
                    partPos = ""
                    fab = ""
                lineTokens = line.split(",")
                headerLine = line[0:line.find("'")]
                line = line[line.find("(") +1:len(line)]
                lineTokens = line.split(",")
                uID = lineTokens[0]
                uID = uID[1:len(uID)-1]
                matType = lineTokens[2]
                matType = matType[1:len(matType)-1] 
                floorName = lineTokens[4]
                floorName = floorName[1:len(matType)-1]
            if self.assPosLineEdit.text() in line:
                assPos = self.getIFC_EntityProperty(line, self.assPosLineEdit.text())
            if self.partPosLineEdit.text() in line:
                partPos = self.getIFC_EntityProperty(line, self.partPosLineEdit.text())
            if self.fabricatorLineEdit.text() in line:
                fab = self.getIFC_EntityProperty(line, self.fabricatorLineEdit.text())
        if i == progDlg.maximum():
            csvFile.write("{0};{1};{2};{3};{4};{5};{6};{7};{8};\n".format(uID, matType, orderNr, custNr, assPos, partPos, fab, projManager, drawer))
 ifcFile.close()
 csvFile.close()

def getIFC_EntityProperty(self, row, ifcKey):
    s = ""
    lineTokens = []
    if ifcKey in row:
        lineTokens = row.split(",")
        ifcTag = lineTokens[2]
        ifcTag = ifcTag[0:ifcTag.find("(")]
        #print(ifcTag)
        if len(ifcTag) > 1:
            s = row[row.find(ifcTag)+len(ifcTag)+2:row.rfind(',')-2]
    return s

  def getIFC_ProjectDetail(self, fileName, ifcKey):
    s = ""
    content = open(fileName, 'r')
    lineTokens = []
    for line in content:
        if ifcKey in line:
            lineTokens = line.split(",")
            ifcTag = lineTokens[2]
            ifcTag = ifcTag[0:ifcTag.find("(")]
            if len(ifcTag) > 1:
                s = line[line.find(ifcTag)+len(ifcTag)+2:line.rfind(',')-2]
                break
    content.close()
    return s

The problem is it jumps a value, it shifts a row and post the data in the line below in the csv like file, creating however the line with the right uID but leaveng the fields of the line blanks. can Anyone help me?

Silenzio76
  • 53
  • 7

0 Answers0