

This script will create a sphere based on the Radius input value: import clr clr. To show how a geometry that is created in Grasshopper, previews in both Rhino and Revit dynamically we will use the script below. Once this foundation is ready, then we can continue to create the script. This is a really good practice and it makes the definition a lot more clear to a new user. It will pass that sphere onto other Grasshopper components through the output and it will create the sphere in Revit and bake into Rhino if the button connected to the input is pressed.Īs you see in the image above, we have renamed the input components and also the input and output parameters on the python components. This example component will create a sphere of an adjustable radius in Revit and Rhino.

Place under Grasshopper User Objects folder.
REVIT API DOWNLOAD
You can download the User Object for this template from this button:

Error, msg ) def show_remark ( msg ): ghenv. Warning, msg ) def show_error ( msg ): ghenv. ActiveDBDocument # a few utility methodsĭef show_warning ( msg ): ghenv. VersionNumber # access the active document objectĭoc = Revit. Geometry ) from Autodesk.Revit import DB # access to Revit as host AddReference ( 'RevitAPIUI' ) from System import Enum, Action import rhinoscriptsyntax as rs import Rhino import RhinoInside import Grasshopper from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML from RhinoInside.Revit import Revit, Convert # add extensions methods as wellĬlr. AddReference ( 'RhinoInside.Revit' ) clr. Here is a template script that covers most of the use cases: import clr clr.

You can setup a template python component with a default script importing all the most frequently used APIs and save that as a User Component in Grasshopper:Īfter the user object has been created, you can easily create a new python component from the user object and it will have the template python script with all your default imports: Since the imports mentioned above need to be done for every single python component, the process can get tedious. Geometry ) # Revit APIįrom Autodesk.Revit import DB from Autodesk.Revit import UI Custom User Component ToXXX() convertor methods on Revit objectsĬlr. Import RhinoInside from RhinoInside.Revit import Revit, Convert # add extensions methods as well Now we can import the namespaces into the script scope: # from System.Core DLLįrom System import Enum, Action # API AddReference ( 'RhinoInside.Revit' ) # add reference to Revit API (two DLLs)Ĭlr. AddReference ( 'System.Core' ) # add reference to API provided by Ĭlr. Import clr # add reference to base system types e.g. To access Revit and we need to first import the CLR (Common-Language-Runtime) module in python and use that to add the necessary library references: # Common-Language-Runtime module provided by IronPython In order to access the various APIs we need to import them into the script scope first. When adding a new python component into the Grasshopper definition, you will get the default imports: """Provides a scripting component.Ī: The a output variable""" _author_ = "" _version_ = "" import rhinoscriptsyntax as rs In this article we will discuss using the python component to create custom components for Revit. Since project brings Rhino and Grasshopper into the Autodesk Revit® environment, the scripted components also get access to the Revit API runtime. The component, therefore, can accept a configurable number of input and output connection points. These scripted components allows a user to create custom logic for a Grasshopper component. One for python (IronPython to be specific) programming language and another two for VB.NET and C#. Grasshopper has three scripted components.
