Hi! I’m wondering if there is a workflow to send geometry info from Viktor app to Revit AND automatically create geometry in Revit. All suggestions will be appreciated. Thanks!
More specifically, the use case:
Background:
I have a Viktor app for generative design. Users can import an .ifc file containing site info, set their preferences, and then the app generates and shows many possible building massing options, each one with a few simple blocks as building masses. It works well till this point.
After the generation of options, it is expected that users can choose one of the generated option which is interesting to them, send it to Revit, and work further from there (adding more details, adjusting the size or location of masses, etc.).
So, what I need is a good workflow to send/create geometry to Revit.
What’s expected in Revit:
- It would be the best if 2D polygons or maybe 3D building elements representing building masses can be created in Revit x-y plane, so that the users see intuitively what the design is like, plus they have the freedom to model and adjust their buildings on top of that;
- At the very least, the dimensions of the blocks and their relative locations (doesn’t need to be RD coordinates) show be sent to Revit;
- Preferably the users don’t need to do a lot of work, e.g. the whole exporting-to-revit process is completed conveniently with only one or two clicks of button.
Other relevant info:
- The building options as output of the Viktor app are essentially a collection of polygons (or, lists of coordinates of their vertices) and heights.
Hi amy.jxz
First of all, this sounds like an awesome engineering project. We recently build something that might actually suit your use-case quite well.
We have created a Revit Plugin that can exchange information with the VIKTOR platform. It has been open-sourced and the repo can be found here: github/viktor-platform/pyrevit-plugin.
Note that for most cases, the user-action starts in Revit instead of VIKTOR, but other than that it should enable you to do the following for the flows you mention:
-
I have a Viktor app for generative design. Users can import an .ifc file containing site info, …
The plugin supports a “Push” data button that allows you to push an .ifc file from Revit directly to a particular entity (where it will now be available to be selected in a FileField)
-
… set their preferences, and then the app generates and shows many possible building massing options, each one with a few simple blocks as building masses.
This just happens in the VIKTOR app as normal. Ensure that the User saves their work!
-
After the generation of options, it is expected that users can choose one of the generated option which is interesting to them, send it to Revit, and work further from there
The plugin can be updated to also include a “Pull” data button that retrieves data from the VIKTOR platform (i.e. retrieve the chosen option).
Note that the “Pull” data button does not exist in the base plugin, but there has been a Hackathon team recently (they are referenced in the repo) that has implemented an example of this that does roughly the following:
- Pull the params from VIKTOR
- Post-process these params to convert them into Revit-native objects/geometries.
I hope this helps to get on your way to build an awesome User-friendly workflow.
1 Like
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