Create/send geometry from Viktor to Revit

Hi Kevin,
Thanks for your elaborated answer!
Just a follow-up: for now we decided to not use a Viktor-to-Revit connection, but .ifc export from Viktor and then import to Revit. Viktor-to-Revit connection may be a nice addition for future.

For those who are interested, this is a snapshot of the code to write an .ifc file, store in Viktor Storage, and download:

Write an .ifc file:

 # Create a new IFC file
        ifc = ifcopenshell.file(schema='IFC2X3')
        # Create an IfcOwnerHistory
        person = ifc.createIfcPerson(GivenName='John', FamilyName='Doe')
        organization = ifc.createIfcOrganization(Name='Example Organization')
        person_and_org = ifc.createIfcPersonAndOrganization(ThePerson=person, TheOrganization=organization)
        # ... 
        # other ifc writing thing ...
        # ... 

Use a temporary file for ifc.write() and store the file in Storage:

        # Use a temporary file for ifc.write()
        # ifc.write() to local directory produces an error after publishing
        with tempfile.NamedTemporaryFile(suffix='.ifc', delete=False) as tmp_file:
            temp_file_path = tmp_file.name  # Get the temporary file path

        ifc.write(temp_file_path)

        ifc_file = File.from_path(temp_file_path)
        Storage().set("ifc_as_str_" + building.name + ".ifc", data=ifc_file, scope='entity')

        # Delete the temporary file
        os.remove(temp_file_path)
file_obj = Storage().get("ifc_as_str_" + building.name + ".ifc", scope='entity')
        print("file_obj.source test in def write_ifc_file_into_storage for ", building.name, ": ", file_obj.source)  

And then use the code in this post for .ifc download:
Storage from_path storing and downloading a file

1 Like