Running Dynamo and keeping objects created

Hi,
I have a question about how Dynamo works:

I’ve a routine which places face based families over a select objects face – this works fine and places the families. But when I select another face and run the routine again it removed the previously created families from the model and places new ones on the new face.

I would like to keep all objects created.

Is there some sort of setting or node which will cause Dynamo to ‘release’ the objects it creates so that when the routine is run again on a different part of the model it simply creates more families.

Thanks.

2 Likes

This is intentional behavior. Imagine you modified the script cuz it didn’t make the elements at the right points, you would want the generated elements to disappear right? That’s why it works this way. To resolve this you have 3 options:

  1. Force the creation of new elements every time using Python.
  2. Close and reopen the script between runs.
  3. Run the script via Dynamo player.

I like option 3 best, but option 1 is also rather nice.

mmm - that’s a bit frustrating… I can see that there are good reasons for this behavior, but there are also some instances where the user would want to turn off the ability.

As for the solutions you suggest:

  1. I’m trying to avoid Python for the moment as the graph is almost there.

  2. I’ve tried closing and reopening the script between runs - this option doesn’t work.

  3. I don’t have Dynamo player as yet…

It seems strange that there is no option to turn this behaviors off?

@Kevin.Bell, there are actually two ways to workaround this behaviour:
a) Use python code to place family instances (like “family instance in transaction” node from the Bakery package);
b) Use groups: 1. Place your family instances with Dynamo; 2. Group these elements; 3. Run Dynamo graph again to place the next pack of elements (this is when Dynamo deletes all the previously placed instances); 4. Select your group and click “Restore All Excluded”.

Another workaround:

run your script, select all knots, open a new dynamo-file, insert the knots run the sript again,

If this is important to you feel free to voice that opinion on GtHub as well…

@Kevin.Bell, one additional remedy for this is essentially copying the elements and breaking their association. Dynamo package beaker has a node called “Bake elements” that does this. (its a hit or miss when used on automatic though)

4 Likes

That’s for all your responses guys, there’s lots of solutions there.

@Ben_Osbourne - I’ve left a comment on the GitHub, hopefully something might come of it!

Is the issue of Dynamo retaining links to objects the reason why the Dynamo files I save suddenly get very big?

I created a graph to place some family instances, when I first used it to create 400 the Dynamo files was 87kb, I then increased the instances to 40,000 and the Dynamo file was 16.2MB after saving…

No idea but worth looking into.

@Kevin.Bell

Yes, if you open the dyn file with an editor like notepad++ or jedit you will see the object information under the ‘SessionTraceData’ xml node

1 Like

I see.

I found that running the graph again on 400 instances reduced the file size back to 200kb…

I’d love to be able to turn this feature off…

This method worked for me!

I need to run my Dynamo script until I’m satisfied with the instances created -hosted to a topo. surface; so, I want to avoid copying and pasting with additional re-hosting steps. Next, I want to leave them as-is and create a new set.

Run script for final instances
Save the Dynamo file
Find file folder and rename the filename with a new extension for opening in Notepad, e.g. “filename.dyn” becomes "filename.dyn.txt"
Open it in Notepad
Scroll down to the bottom to find the section "SessionTraceData"
Highlight and delete all the block of characters including the header text “SessionTraceData” all the way down to “/SessionTraceData” including that text and the “<” “>”, characters, too
Leave no extra blank lines
Leave the text “/Workspace” at the end
Save the edited file
(un)Rename it by removing the .txt you added earlier -ignore any error message about files becoming unusable or associated with another program because you are deliberately altering the file
Re-open the script and run a new set of instances unlinked to the previous set

Looks like a lot of steps and a little scary tinkering with the file innards, but it’s easy and convenient for me.

Thanks to all sharing their knowledge and the programmers pioneering Dynamo scripting for Revit. You people are saving thousands of mouse clicks!

1 Like

@paulight

glad it worked to you- although probably falls into the category of a nasty hack rather than a sound method.
(incidentally, you could just drag the .dyn file into notepad, rather than renaming & unrenaming to .txt)

It would be good if there was the ability to bake objects in the same way as Grasshopper- including ‘BakeName’

Andrew

Thanks, I’ll do the drag-n-drop to skip a few steps.

I’m sure the bake/drop/save/freeze function will get done someday.

Might it be possible to edit the contents directly in Dynamo, in the same run but sequentially?

//Some file read work
StartIndex = String.IndexOf(DynFile, "<Session Trace");
EndIndex = String.IndexOf(DynFile, "Session Trace>");
CharCnt = EndIndex-StartIndex
String.Remove(DynFile,StartIndex,CharCnt)
//Some file write work

No idea of the file will allow write access in the same script as the one creating the geometry, as Dynamo will already have it open, but worth a shot right? Add it to the list of reasons we need to be able to access the path of the active dyn file inside of Dynamo if that does work.

1 Like

@JacobSmall
not a bad idea, but might be a case of:

1 Like

Oh I think we can cut faster than that…

takes out his chainsaw

1 Like

This seems old but it still behaves in that underwhelming way for most of the cases you want resolve in Dynamo 2.0.3.
The most incredible thing is I can close Dynamo and the Revit file, I reopen again everything and I run to set different elements and it still deletes my old objects. So for some reason the file keeps all the information. I grouped them and they still were deleted within the group. The unique solution seems copy them.

This is VERY old. See here for information on element binding.

Getting used to element binding is a must for being above an intermediate level Dynamo user. I am teaching a course (and a replay course) on this at AU Vegas this year (search the course catalog for Pandora’s Box if you’re curious), where I’ll show as much of the advanced stuff as possible in the 90 minutes I have to demo in.