Updating python node in multiple scripts

Is it possible to update text in a script to update a python node and save again? I could find and replace with this but then not sure how to write and save again. Is it risky?


Best options are:

  1. Use a custom package with Python in the nodes
  2. Use custom libraries (py files) and call on these to make code more reusable
1 Like

Dont understand any of that. Lets go risky. This thing seemed to do it… all corrupted :rofl: Maybe not possible?

append corrupts it too
updating the path manually does too

1 Like

Yep I’m not going to even pretend I understand how to modify Dynamo in a text editor. Hopefully someone else has some ideas…

You can probably look into python json module to read and write dyn files. There are some good tutorials on YouTube.


yeah theres lots of stuff on the web. But I wouldnt know how to figure it out. Can turn the data into JSON after adjusting the text but not sure how I’d write that back to the file as theres no nodes for it

import json

aList = [{"a":54, "b":87}, {"c":81, "d":63}, {"e":17, "f":39}]
jsonString = json.dumps(aList)
jsonFile = open("data.json", "w")
1 Like

I dont know, cant find a writing dynamo node I can open as an example

import sys, clr, json, os
aList = IN[0]
jsonFile = IN[1]
jsonString = json.dumps(aList)
OUT = jsonString

Apparently, there is a JsonData Package as well that lets you parse and write to json format.
I’d start with a small dyn file of one or two nodes and work up with more complex graphs.

1 Like

Can you upload a sample of the Python you want to bulk change? Judging by the scope I can see using a package containing the Python is likely the best way to go, or better still writing the path as an input value instead of hard coding it.

As a part of the class I helped present with @dana.defilippi at BiLT America this year I produced some Python code to bulk edit Dynamo graphs, including:

  • Adding a ‘tracker’ node or standard documentation
  • Upgrading the Python engine to CPython3
  • Swapping the old if node for the new one and maintaining lacing
  • Removing the bindings
  • Reordering inputs by alphabetical name
  • and a few more (if I recall there were like 9 in total but I can’t boot up that laptop at the moment)

While dyn and dyf files are text documents, you need to have them serialized correctly to have the application interpret them properly, which can be problematic for the packages I could find. The out of the box Python JSON tools worked well enough for me, but I recommend starting by editing in notepad++ so you can get the hang of it (change the language to json).


Thanks Jacob and others. Looking forwards to trying when I’m at work. Jacob where is your profile pic? :blush:

Hmmm I’m not sure if I can upload an example of the Python, its a tracking thing someone gave me :thinking:

any kind of string replace is no good messing with jsons. I put the updated python node in another file and thought maybe I could replace it in the other files but its just to tricky. 1s the python node alone in a file. 2 is the other files to update. But I must be messing up serializeing?

It was a syntax thing or serialized. Looked at that string of JSON with the fixed path I wanted and then used that. Seems to add extra \ all over the place and it worked :slight_smile:

1 Like

Hi Jacob, do you have a link to your BiLT America class with documentation by any chance? To avoid this situation in future I need to make my own package. However I will need to replace those python tracker nodes in the script maintaining the wire as a next goal

Try making it a standalone .py file in a commonly accessible location, then append to system path and use the syntax; from ‘filename’ import *

This is how I log my pyrevit tool use with a single function stored in a .py file where I control the function on one place.

That’s the ‘work’ account which exists solely because it has to, and since I had info I thought might keep you hopeful I wanted to share it out before you got discouraged.

First some background.

Managing Dynamo repositories is hard, as each release can require modifying your code base, similar to what developers of add-ins go through. However we (development, seasoned users, community leaders) haven’t done a good job showing how this is best accomplished. My small section of this class aimed to start showing users hope to do this while prepping graphs for the new player.

The attached file should be renamed to a .zip and extracted. It contains 9.1 Dynamo graphs:

  1. Graph Resizer: Manipulates the location of nodes to adjust the scale so the 2.13 UI changes don’t cause a million train wrecks to your layouts.
  2. Binding Remover: removes any bindings, a best practice before putting them into a library.
  3. Add Properties - BULK and Add Properties - Individual: Add a bunch of properties to a bunch of graphs or to an individual graph. Great for putting the Author info and such into all the graphs in your library.
  4. If Replacer: Swap out all the old If nodes with the new improved one.
  5. Python Engine Changer: Change the Python engine from IronPython 2 to CPython 3.
  6. Input Renamer: Renames inputs to the order in which they were created, so they sort in the same order when you get to the new Dynamo player (where alphabetical sort is the default).
  7. Add Tracker: Adds a tracker graph to your graph, placing it in the upper left hand corner of the graph.
  8. Build Testing Journals: builds a series of journals to test your graphs with - drag and drop the journal onto the Revit build you want to test in. Each journal will open the associated Revit file, launch Dynamo, and run the graph. User can then verify if they worked. If so the graph can be saved to to the new library, or if they fail the user can make the necessary changes or move to a new folder to edit later.
  9. Tracker: A sample graph containing one node representing what could be a tracker (or something else). Populating it with your actual desired tracker node is required before running the ‘add tracker’ graph.

The zip also contains the source journal used for playback, in case you want (or need) to edit that further so you can update the larger set of content.

All of these nodes (and a few more) will eventually make it up to package manager, but I need some beta testers first - feedback welcome.

Bulk Graph Edits.zip.txt (275.6 KB)

While none of these directly show you how to bulk modify your python, you can likely use them to append your tracker (if that is what you’re after) quite readily, or use them as a template to do the bulk editing of the python.


I have an error in Python engine changer like this:

Please try running with the IronPython 2.7 engine, and if the issue still persists post a .zip file renamed to .txt containing a sample of graphs to update.

by this way warning message has changed.Do i need to post sample of graph or is it possible to solve it by changing pyhthon code?

Interesting… try removing the , exist_ok=True from that line and see if it runs.

now warning has changed.