Dynamo references in C#

Good morning.
Happy New Year.

I was wondering if anyone has been able to use Dynamo references as .dll files in C#. I’d like to know and get your recommendations.
The references are from Dynamo for Revit.
In the image, you can see that I’ve added the Dynamo references to my C# solution, and I have no problems calling and using Dynamo’s methods. Compiling doesn’t give me any errors or warnings either… everything seems fine. However, at runtime, when I execute the external command, I get a window saying that memory has failed - “External Command Failed
Revit was unable to complete the external command. Please contact your vendor for assistance. Information provided to Revit regarding your identity: AM3D
Revit encountered: Object reference not set to an instance of an object.“.
Could someone help me understand and solve this problem?

Sounds like the object you are using is expecting type X but is getting type Y. Perhaps expecting a Dynamo wrapped object instead of the native Revit API one?

Debugging your solution so you can step though the code and read the object states prior to the error will usually help resolve this.

That said, I don’t recommend using Dynamo for Revit methods in an add-in for several reasons. Every D4R node you call is doable via the Revit API already so there isn’t a need for complicating things by utilizing a dependency. Also doing the wrapping/unwrapping is going to slow things down to the point of ‘why not use C# to write a zero touch node in a Dynamo package and just use Dynamo player’ situation from a speed perspective. You will also have to expand your testing framework as there is no way to ensure thing will load correctly in the future. Finally you’ve gone and made distribution difficult as you have the Dynamo licensing concerns now. All in I would go about this differently.

I understand. However, I need a similar method from Dynamo called “ThinShell” that behaves and performs the same process, as well as many other methods that Dynamo has and that I would like to have, but the Revit API doesn’t seem to expose. I’m very interested in working with solids, geometries, surfaces, etc. Is there any other solution or library that can help me freely manipulate Revit API solids, or is it not possible?

Those APIs don’t exist directly, but you can manipulate the content via the tools in Revit. Thin shell is a tough one so there is somewhat of a case here.

My recommendation would be to utilize Dynamo directly instead of trying to build an add-in and have your add-in launch a Dynamo CLI instance and run the DYN file.

I think this may fall into the you are trying to run Dynamo API when you do not have access to these commands or not allowed to access them because you are only allowed to via dynamo.

I would suggest you look into running a dynamo script via a revit button, if you must go with the using dynamo geometry. You could look into Relay addin on how it works to run a dynamo script via a button(though do read the license!). GitHub - johnpierson/Relay: Relay allows for you to add Dynamo graphs to your Revit ribbon.

1 Like