def openFile(self):
     self.form.labelStatus.setText("")
     if (self.form.listRevisions.currentRow() >= 0) and (len(self.Revisions) > self.form.listRevisions.currentRow()):
         rev = self.Revisions[self.form.listRevisions.currentRow()]
         import requests, json
         url,token = self.getPrefs()
         if url and token:
             FreeCAD.Console.PrintMessage(translate("Arch","Downloading file from Bimserver...\n"))
             self.form.labelStatus.setText(translate("Arch","Checking available serializers..."))
             url += "/json"
             serializer = None
             for s in ["Ifc2x3tc1"]: # Ifc4 seems unreliable ATM, let's stick with good old Ifc2x3...
                 data = { "token": token, "request": { "interface": "ServiceInterface", "method": "getSerializerByName", "parameters": { "serializerName": s } } }
                 resp = requests.post(url,data = json.dumps(data))
                 if resp.ok:
                     try:
                         srl = resp.json()["response"]["result"]
                     except:
                         pass # unable to get this serializer
                     else:
                         serializer = srl
                         break
             if not serializer:
                 FreeCAD.Console.PrintError(translate("Arch","Unable to get a valid serializer from the BimServer\n"))
                 return
             tf = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(), "Save the downloaded IFC file?", None, "IFC files (*.ifc)")
             if tf:
                 tf = tf[0]
             self.form.labelStatus.setText(translate("Arch","Downloading file..."))
             data = { "token": token, "request": { "interface": "ServiceInterface", "method": "downloadRevisions", "parameters": { "roids": [rev["oid"]], "serializerOid": serializer["oid"], "sync": "false" } } }
             resp = requests.post(url,data = json.dumps(data))
             if resp.ok:
                 try:
                     downloadid = resp.json()["response"]["result"]
                 except:
                     FreeCAD.Console.PrintError(translate("Arch","Unable to obtain a valid download for this revision from the BimServer\n"))
                     return
             data = { "token": token, "request": { "interface": "ServiceInterface", "method": "getDownloadData", "parameters": { "topicId": downloadid } } }
             resp = requests.post(url,data = json.dumps(data))
             if resp.ok:
                 try:
                     downloaddata = resp.json()["response"]["result"]["file"]
                 except:
                     FreeCAD.Console.PrintError(translate("Arch","Unable to download the data for this revision.\n"))
                     return
                 else:
                     FreeCAD.Console.PrintMessage(translate("Arch","Opening file...\n"))
                     self.form.labelStatus.setText(translate("Arch","Opening file..."))
                     if not tf:
                         th,tf = tempfile.mkstemp(suffix=".ifc")
                     f = open(tf,"wb")
                     f.write(base64.b64decode(downloaddata))
                     f.close()
                     os.close(th)
                     import importIFC
                     importIFC.open(tf)
                     os.remove(tf)
     self.form.labelStatus.setText("")
Exemplo n.º 2
0
 def openFile(self):
     self.form.labelStatus.setText("")
     if (self.form.listRevisions.currentRow() >= 0) and (len(self.Revisions) > self.form.listRevisions.currentRow()):
         rev = self.Revisions[self.form.listRevisions.currentRow()]
         import requests, json
         url,token = self.getPrefs()
         if url and token:
             FreeCAD.Console.PrintMessage(translate("WebTools","Downloading file from Bimserver...\n"))
             self.form.labelStatus.setText(translate("WebTools","Checking available serializers..."))
             url += "/json"
             serializer = None
             for s in ["Ifc2x3tc1"]: # Ifc4 seems unreliable ATM, let's stick with good old Ifc2x3...
                 data = { "token": token, "request": { "interface": "ServiceInterface", "method": "getSerializerByName", "parameters": { "serializerName": s } } }
                 resp = requests.post(url,data = json.dumps(data))
                 if resp.ok:
                     try:
                         srl = resp.json()["response"]["result"]
                     except:
                         pass # unable to get this serializer
                     else:
                         serializer = srl
                         break
             if not serializer:
                 FreeCAD.Console.PrintError(translate("WebTools","Unable to get a valid serializer from the BimServer\n"))
                 return
             tf = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(), "Save the downloaded IFC file?", None, "IFC files (*.ifc)")
             if tf:
                 tf = tf[0]
             self.form.labelStatus.setText(translate("WebTools","Downloading file..."))
             data = { "token": token, "request": { "interface": "ServiceInterface", "method": "downloadRevisions", "parameters": { "roids": [rev["oid"]], "serializerOid": serializer["oid"], "sync": "false" } } }
             resp = requests.post(url,data = json.dumps(data))
             if resp.ok:
                 try:
                     downloadid = resp.json()["response"]["result"]
                 except:
                     FreeCAD.Console.PrintError(translate("WebTools","Unable to obtain a valid download for this revision from the BimServer\n"))
                     return
             data = { "token": token, "request": { "interface": "ServiceInterface", "method": "getDownloadData", "parameters": { "topicId": downloadid } } }
             resp = requests.post(url,data = json.dumps(data))
             if resp.ok:
                 try:
                     downloaddata = resp.json()["response"]["result"]["file"]
                 except:
                     FreeCAD.Console.PrintError(translate("WebTools","Unable to download the data for this revision.\n"))
                     return
                 else:
                     FreeCAD.Console.PrintMessage(translate("WebTools","Opening file...\n"))
                     self.form.labelStatus.setText(translate("WebTools","Opening file..."))
                     if not tf:
                         th,tf = tempfile.mkstemp(suffix=".ifc")
                     f = open(tf,"wb")
                     f.write(base64.b64decode(downloaddata))
                     f.close()
                     os.close(th)
                     import importIFC
                     importIFC.open(tf)
                     os.remove(tf)
     self.form.labelStatus.setText("")
def openIfcFile(path: str):
    """ Opens an IfcFile behind path. IfcOpenShell is required! """

    logger.info("Opening IFC file {} in FreeCAD".format(path))
    if not os.path.exists(path):
        logger.error("File {} could not be found. Please supply a path that"\
                "exists")
        return OperationResults.FAILURE

    if not FREECAD:
        logger.error("I am not running inside FreeCAD. {} can only be opened"\
                "inside FreeCAD")
        return OperationResults.FAILURE

    import importIFC as ifc
    ifc.open(path.encode("utf-8"))
    docName = join(os.path.basename(path).split('.')[:-1], '')
    App.setActiveDocument(docName)
    App.ActiveDocument = App.getDocument(docName)
    Gui.ActiveDocument = Gui.getDocument(docName)
    Gui.sendMsgToActiveView("ViewFit")

    return OperationResults.SUCCESS
# ************************************************************************************************
# ifc import *************************************************************************************
# ************************************************************************************************

# ************************************************************************************************
# bernd min geometry importer, geometry only as solids
import importIFCmin, os, archadd
path_to_importIFCrebar = archadd.__file__.rstrip(
    os.path.basename(archadd.__file__))
importIFCmin.open(path_to_importIFCrebar + "example_01_two_stirrups.ifc")

# ************************************************************************************************
# FreeCAD ifc importer
import importIFC, os, archadd
importIFC.open(path_to_importIFCrebar + "example_01_two_stirrups.ifc")

# ************************************************************************************************
# rebar importer which uses rebar2
import os, importIFCrebar
path_to_importIFCrebar = importIFCrebar.__file__.rstrip(
    os.path.basename(importIFCrebar.__file__))
importIFCrebar.open(path_to_importIFCrebar + "example_01_two_stirrups.ifc")
# importIFCrebar.open(path_to_importIFCrebar + "example_02_channel_foundation.ifc")  # takes looong
importIFCrebar.open(path_to_importIFCrebar + "example_03_crane_foundation.ifc")
importIFCrebar.open(path_to_importIFCrebar + "example_04_vat.ifc")
FreeCAD.ActiveDocument.recompute()

# for debugging with reload of importer
import importIFCrebar
import importlib
Exemplo n.º 5
0
# ifc import *************************************************************************************
# ************************************************************************************************

# ************************************************************************************************
# bernd min geometry importer, geometry only as solids
import importIFCmin, os, ArchBaseRebar

path_to_ArchBaseRebar = ArchBaseRebar.__file__.rstrip(
    os.path.basename(ArchBaseRebar.__file__))
importIFCmin.open(path_to_ArchBaseRebar + "example_01_two_stirrups.ifc")

# ************************************************************************************************
# FreeCAD ifc importer
import importIFC, os, ArchBaseRebar

importIFC.open(path_to_ArchBaseRebar + "example_01_two_stirrups.ifc")

# ************************************************************************************************
# rebar importer which usees ArchBaseRebar and ArchReinforcement
import os, ArchBaseRebar, importIFCrebar

path_to_ArchBaseRebar = ArchBaseRebar.__file__.rstrip(
    os.path.basename(ArchBaseRebar.__file__))
importIFCrebar.open(path_to_ArchBaseRebar + "example_01_two_stirrups.ifc")
# importIFCrebar.open(path_to_ArchBaseRebar + "example_02_channel_foundation.ifc")  # takes looong
importIFCrebar.open(path_to_ArchBaseRebar + "example_03_crane_foundation.ifc")
importIFCrebar.open(path_to_ArchBaseRebar + "example_04_vat.ifc")
FreeCAD.ActiveDocument.recompute()

# for debuging with reload of importer
import importIFCrebar