Add Revit Component as an input in C# script

Hello!

I am trying to use a Revit component in a C# script, so that I can retrieve its data through the API directly.

I am not sure how to set this kind of element as an input type:

based on my knowledge of Dynamo, this input type should be Revit.Element.Element, but GS wouldn’t let me edit it from the code directly:

Hi, in general, if your object type is not listed in that menu, you need to retrieve the object as a System.Object type object. Afterward, you can do a “cast” and put it into another variable with the object’s actual type.

The code will be something like
Revit.Element.Element elem= (Revit.Element.Element) revitElement;
or
Revit.Element.Element elem= revitElement as Revit.Element.Element;

Good luck!

2 Likes

thx! I will now give it a try

I’m not sure I can make it work. It seems like I should get those elements directly as API elements, which means Autodesk.Revit.DB.Element (as Revit.Element.Element is usually the Dynamo cast):

but it doesn’t work:

I have the API added as an assembly:

You will need to cast the elements inside the list as shown below

2 Likes

Thx! that works :slight_smile:

1 Like

got a bit carried away and tried to transfer geometry from Revit Family Instances entirely with C# :smiley:

seems like a lot of fun. It’s really cool there’s a C# scripting component