Circumvent Revit Object "replacement"

I have a user in my firm who is interested in creating sets of floor plans in revit. His desired use case is to re-run the graph several times, with different view names / templates specified. The problem is that the node creating the views deletes the views he created last time - when he just wants to add a new set of views. I recognize this is the expected behavior of all nodes interacting with revit - when you make a “change” all the old revit geometry gets replaced - but sometimes a “change” is not really a change, it’s a new “run” - and dynamo doesn’t seem to offer any way to enable that kind of use. Am I missing anything obvious? Do I have to script a whole replacement for the floor plan create node in python just to avoid this behavior?

Ideally the native Revit nodes should have a switch that allows both behaviours.

5 Likes

I’ll toss my support in here as well. I’d like to see some way to run and create, change parameters, run and create something else without having to bail out of the script. As Luke suggests, a Boolean input added to all revit nodes that can toggle between “create and remember” and “create new always” seems like the easiest way.

The only way I’ve successfully worked around this was to do a SaveAs with a new script name after each run - which was just ridiculous in my opinion.

2 Likes

2 questions / suggestions :

  • does this happen if you run the node with Dynamo Player ? (I assume each run is encapsulated in its own session)
  • if you add a manual Transaction.Commit at the end of the graph, do the views still get deleted at next run ?

Don’t have access to Dynamo right now otherwise I’d test.

if the graph uses Dynamo nodes, the elements are bound and the data is serialized into the dyn - so even if the runs were separate the element binding should be reloaded on restart of Dynamo. (element binding is the connection between a node being called and some element created in Revit)

If you use nodes that have been written in python or c# and are not from the Dynamo Team it is likely they don’t use element binding and you’ll get the behavior you are after.

Thanks for the explanation Michael. Before we all start writing our own python nodes with Boolean toggles for Element Binding (I assume this isn’t that difficult if you know how to do basic things with the API), is there any chance that this might be coming in the near future from standard Revit Nodes?

@Michael_Kirschner Does the .ToDSType(bool) method have anything to do with element binding?

Wrapping

In order to interoperate with our Revit nodes, any raw Autodesk.Revit.DB.Element being returned from a Python script must be wrapped in a Revit.Elements.Element. This can be done by using the ToDSType(bool) extension method. The bool argument determines whether or not the Element is “Revit-owned.” This distinction is important: Revit-owned Elements are not controlled by Dynamo, non-Revit-owned Elements are. Basically, if you are creating a new Element in your Python script, then you should not mark the wrapped Element as Revit-owned. If you are selecting an Element from the Document, then you should mark the wrapped Element as Revit-owned.

yes, well kinda…

DynamoRevit wraps the raw Revit.Db.Elements with wrappers. These wrappers when constructed via constructor nodes, document queries, or selection nodes, return wrapped elements. The wrappers implement element binding by linking the element ID - > a callsite -> a node in the graph.

I think if an element is RevitOwned it usually came from a selection - or you called the method with true - and these elements will not be deleted by Dynamo.

So Guys no solution for this using the dynamo nodes or any custom node until now right?

@ali.safiaddine,

I think it can be done with custom nodes only.

Have a look at this post…

Create New Sheet Each Run

It is as @Einar_Raknes mentioned earlier with the .ToDSType(bool) method and changing the bool from false to true.

Cheers,
Dan

Thank you @Daniel_Woodcock1,
But it seams that it is a solution for a specific problem, am not familiar with coding that’s why I can not get the logic.

The general solution would be as follows:

  • Find a custom node for your task
  • Open the python script and look for the line(s) that contains “ToDSType(False)” and change it “ToDSType(True)”
1 Like

@Einar_Raknes Thank you