I’m writing a Revit Dynamo Python script that needs elements from two documents (I want to copy some stuff between the documents).
I have two selection nodes, and everything works as long as I select in the same document.
However, when I switch to another document to do selection, Dynamo won’t let me and shows “Dynamo is not pointing at the current document” error at the bottom (see the image).
Could you please help?
That’s going to be more complex if you are going from A → B and B → A at the same time.
It will be a lot simpler if you first do A → B as one script/step. And the B → A as a second script/step. Most likely the same script(?)
To do it all at once, you’ll need to first get both documents. Then get the elements from each of the documents. This can be more difficult as the Select Model Elements is limited to one document.
You could highlight the elements in Doc A and then in Doc B. And then you would have to use dynamo or python to get the selection from each of the documents. And of course, you’ll need to keep the elements and documents straight as you move them about.
From the little we can see, I’m guessing you are taking elements from one document and then moving or copying them to a second document’s room(?) If that is the case, the best approach would be to just select the room not with the UI, but by number/name.
We need more information. What exactly are you trying to do? There are plenty of ways to interact with multiple documents but it all depends on what you need and what you want to modify.
Thank you Aaron for your reply.
> you are taking elements from one document and then moving or copying them to a second document’s room
Yes, that’s correct.
I only want to copy from one document to the other.
> you’ll need to first get both documents
I hoped to get the documents from the elements.
select the room not with the UI, but by number/name
That wouldn’t be user-friendly I’m afraid.
What do you mean by the two scripts/steps?
You’re bumping into the limits of the Dynamo UI.
You probably need to use a temp file or some intermediate storage method to do what you want.
- Select Objects to be copied.
- Start script.
- Copy the info of the elements to a non-modal dialog.
- Move to second document.
- Select room.
- Hit Ok on the non-modal dialog to run the second part of the script.
Not the simplest thing to do - but it can be done. I wouldn’t use dynamo for this application.
I see.
The intent was to eventually use generative design to arrange the copied elements in the destination room. I thought Dynamo was needed for this.
Thank you for clarifications @aaron_rumple.
Do you mean that the 2nd part would be in another .dyn file?
A second dyn would certainly do the trick. Selecting across documents via the UI is not easily doable, and in some cases not doable at all.
What sort of content are you trying to gather? It might be easier to grab things programmatically, or as others have suggested, use a ‘pre-run’ graph in the source file which extracts the data into either a Remember node or an external file such as a json.
What type of stuff are you planning on having users select and how are they being arranged?
Hi Jacob,
The 1st file has a “library” – a number of rooms with different furniture and equipment. I thought box selecting everything would be a quick way to get what I want, but it appears not the case. I can instead get everything visible in the view programmatically. I just need to figure out how to get to the other document :).
Thanks for the help!
On e selected are you going to be pulling geometry and information into Dynamo?
If so there is a much faster way to do this, as you don’t want the full 3D geometry but simplified shapes.
-
In a separate graph for ‘generative prep work’, perform for each family users were going to select, build a dictionary with the a key for family type, a key for the simplified geometry (i.e. a desk is a rectangle patched to a surface if you’re doing the exercise in plan, a cuboid if in 3D), and a key for it’s location coordinate system. Then build a dictionary of all those dictionaries using the name of the of the furniture. Hint: keep all geometry at the origin or relative to a shape in the room - that will allow Geometry.Transform to quickly place and orient them. I’ve used keys like ‘color’ (for display purposes via GeometryColor.ByGeometryColor), plan shape / 3D shape, cost, rotation limits, placement methods (to control stuff which sits ‘in the middle’ vs stuff which needs to be on a wall), clearances, and more.
-
Serialize that dictionary into a JSON file and deploy that with your graph. This can be done with a ‘Stringify JSON’ node, which also needs file path. You can read more about that in this blog post: Lost in Translation? Unmasking Data.StringifyJSON and Data.Remember Nodes in Dynamo - Dynamo BIM . The result should be a string showing a dictionary with a key for each object type, and under each another dictionary with keys for the geometry, family name, and anything else you have included.
-
Now we move to the file users are going to use - most never need to see your previous graph. If the intent is for people to ‘select a standard furnishing list’, build a second dictionary with room names as keys and a list of furniture/equipment strings as the values. Populate a ‘Custom Selection’ node with the names (use the name as both the key and the output). Users will pick from that dropdown. If the intent is to have users select individuals pieces, populate a ‘Custom Selection’ node with all the names of the furniture. Mark that as an input and copy it for each selection you might want, giving each a unique name. The advantage with full rooms is you can also ‘pre-train’ the starting locations if you have room types to simplify the initial placement. You can read about the custom selection node in this blog post: Dynamo Core 2.16 Release - Dynamo BIM
-
You also need to bring your JSON back into the Dynamo environment. This requires reading the text from the document and using a Parse JSON node. The result of the dropdown can now be used to pull the required info for each piece of furniture allowing you to build out all of the rest of your graph.
Jacob, thank you so much for the detailed answer!