1

我必须在 IFC 文件中提取数据,但是当我阅读该文件时,我似乎犯了一些错误,我不明白: 首先:我有一把钥匙;第二:我读了一个文件;第三:我创建了一个字符串,并将其放入类似 csv 的文件中。第四:可视化组件在 Pyside2 中。

编码:

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

问题是它会跳转一个值,它会移动一行并将数据发布到类似 csv 的文件中的下一行中,但是会创建具有正确 uID 的行,但会将行的字段留空。谁能帮我?

4

0 回答 0