Dynamo API with C#

Hi,
I am trying to use Dynamo geometry library and I’m not sure how, I’m fairly new to Dynamo and have a background with the Revit API.

If possible I want to include it in my C# code without using Dynamo UI at all. If not, I guess writing some custom nodes can also work.

My end goal is to use nodes like Solid.ByUnion node or the Solid class of Dynamo, but I cant seem to find them inside any of the next dll’s which I got from ‘DynamoForRevit’ folder:
DynamoCore.dll
DynamoServices.dll
DynamoUtilities.dll
RevitNode.dll

Am I looking in the right place?
Do you have a suggestion for a good tutorial/example on how to use this API / write custom nodes?

an illustration of some of the stuff I want to do

If you aren’t using the Dynamo UI, you’re doing yourself a disservice by approaching things this way.

The everything up till the Solid.ByUnion has a direct method in the Revit API already, and the Revit API has solid union method that can be iterated over to get one solid (see here: ExecuteBooleanOperation Method), add in that there is a performance hit in converting to Dynamo geometry which you likely won’t be able to overcome… and this isn’t likely a good path forward.

If your use case is much more complex there might be more value, but I haven’t see such a use case yet in my travels, and Solid.ByUnion likely isn’t it.

1 Like

Thank you for your comment.
I am familiar with the Boolean Operation methods that Revit API exposes.
Unfortunately, they are far from perfect and do not work in some cases for arbitrary reasons.

After some research in the RevitAPI forum it is clear that the issue with these methods is not new and Autodesk developers are aware of it but with no solution in sight.

I know that converting elements/instance will result in a massive hit to performance, but I prefer some performance to no performance at all.

So please if you can point me in the right direction, even if it means writing custom nodes and splitting my script into two tools - Revit API and then a Dynamo script that will complete it.

Can you give me an example of such? I’m pretty well plugged in with those developers and if there is something we can shift to make a better product I will advocate internally for you. “Autodesk Developers” is a VERY large group and often those who know aren’t actually the ones who need to know in order to initiate change. Feel free to describe it here or link me to the API forum. If there are multiple which are holding you back a bulleted list is fine. Having a sample model to reproduce and a business case (i.e. how much not having these is impacting you and the industry at large, and a brief outline of the work-around and it’s cost if you have one) would help as well.

As far as how you can access the geometry library, you’ll have to pull in the ASM library and a few others to enable it first, which is a proprietary library and not directly exposed - I am not sure it can be accessed directly from a 3rd party component or if doing so would be a licensing violation (my gut says ‘yes’ which would make further exploration here a violation). You can also expect doing so to add up to a minute to every Revit start up (depending on how it’s configured).

1 Like

Its hard to give an example when Revit just throws a generic error each time.
However, you can see some examples in this Revit API Forum Post that dates back to 2017 till 2024…

When I try to preform union/difference/intersection operations I face the same exception mentioned in the post:
'Failed to perform the Boolean operation for the two solids. This may be due to geometric inaccuracies in the solids, such as slightly misaligned faces or edges. If so, eliminating the inaccuracies by making sure the solids...'

I appreciate you trying to help, thank you.
I found this Github example for creating custom nodes, and it has a
using Autodesk.DesignScript.Geometry; statement which gives me access to the Solid class, but now I need the Boolean operation methods…

This seems like it might be what I’m looking for but I’m not sure from where to browse the assembly that holds the Boolean operation methods…

You could bypass the solids causing the error. This is similar to how Clockwork is handling and I would expect that the OOTB Dynamo node is probably doing something similar.

# Try to union all solids
    result_solid = solids.pop(0)  # Start with the first solid
    
    for solid in solids:
        try:
            new_result = BooleanOperationsUtils.ExecuteBooleanOperation(result_solid, solid, BooleanOperationsType.Union)
            result_solid = new_result
        except:
            continue  # Skip the problematic solid
        
    return result_solid

@Amecam i don’t think this will work; both design script and protogeometry are proprietary if i remember correctly. at best, as described in that post, either to accept the possibility of some minor inaccuracies and apply a little transformation to the geometry, or to switch to a different kernel—opencascade is pretty robust. and they have c# bindings too if u prefer not using c++.

So looking those over, the issue isn’t with the API, and converting to Dynamo geometry to trudge forward is likely to only to cause further modeling issues (and even geometry errors which make things intolerable or corrupt at the sort of scales that add-ins need to be built to). To put it bluntly, I don’t recommend using this tool in a native Revit context as it can and will break things or lead to inaccurate results. Cleaning up the bad geometry which causes the issue should the the first and foremost goal if accuracy if of any concern (i.e. if you aren’t ok with buying extra concrete, or not buying enough concrete, don’t use this method for concrete calculations). This stems from the great many edge cases which the ToProtoType method suppresses, and round tripping those back into Revit just seems like it’s apt to cause inaccuracies and compound the problem.

That said, you could try adding the Dynamo nugets to your project and call the Dynamo methods that way. This is my preferred reference tutorial for doing so in the context you linked above, which is creating custom Dynamo nodes for execution in the context of Dynamo. I am not certain it will work though as you aren’t in a Dynamo context if you’re working only in the Revit API. The only foolproof method I know to access these libraries is to call up the context to execute a Dynamo graph - basically run a Dynamo CLI in the Revit context (which is what Dynamo player does) and thereby execute the code in a Dynamo context.

Thank you guys for trying to help.
As for you guys warning about inaccuracies and performance - I know this can happen but I still want to fully explore all options to try and get to the bottom of this.
Its imperative that I successfully run these These Boolean operations without skipping elements/solids.

After some more digging, I found almost all the classes and methods I need inside DynamoCore.dll and ProtoGeometry.dll .

Meanwhile except for the method that gets all the elements of a category inside Dynamo from revit which I havent found…

Either way, I tried running some of the Solid methods along side my RevitAPI C# code outside of Dynamo environment and surprise surprise - it did not work, I got this error

I then tried to open Dynamo in the background and then run my code, but I could not get Dynamo to open, my guess is that its because I’m already using the assemblies Dynamo is trying to use at same time…

So my options are as follows:

  1. Write Zero Touch Nodes - which I’m not excited about, because
    a- I prefer no to split my to tool into parts.
    b- I’m not proficient with Dynamo and also I cant seem to find some of the methods I need.

  2. Somehow set up a fake Dynamo environment so that I can use these classes and methods outside of Dynamo which will be ideal.

  3. Give it up completely and try a different approach like opencascade :slight_smile:

You could look at the following C# code that John Pierson has released that shows how to run a Dynamo script and have it as a button.

This may be a good starting point for you, if this is the direction you go to.

Relay/src at master · johnpierson/Relay

I still think you have a 4th option - identify the invalid geometries and have them cleaned up. 9/10 times they are related to warnings which are already negatively impacting performance, so this is not only a benefit to your tool but the project as well.

There is also a fifth option in leveraging the AutoCAD API which ships with Revit and should already be in memory (if memory serves acdbmgd.dll is the reference needed to leverage that library) and work with the geometry there. You’ll find that the solid operations there are very close (if not the same) as Dynamo’s because they both use the same geometry library under the hood.

The sixth option is to alter one of the solids slightly or changing the join order prior to executing the boolean opperations - strangely enough stuff like taking the difference before unioning can make all the difference in the world (and I have seen this work with other tools that utilize the same geometry engine as Dynamo/Autocad quite successfully).

To know what the overall ‘best’ method is would require more context into what you’re using the method for. The best practices for handling this for say 3D printing are different than for visualization which also differ from manufacturing which also differ from element tracking which… you get the idea. :slight_smile:

@Amecam i watched the clip introducing new features in revit 2026. starting from 2:55, they mentioned a minor shift is applied when dealing with toposolid bool ops. reading from the description, i suppose thats just what people have been doing so far (tiny little transformation), especially the guys from that post. my speculation is it might have been introduced to all bool ops not just the ones on toposolid. so i guess u have one more option worth trying, an upgrade to rvt 26.

What’s New in Revit 2026

edit: wait, i just saw the checkbox. if its an option that needs to be enabled manually. ah i hope they added a new bool argument in the api.