Python node live updating


#1

Is there a way to have the results of a python script node live update when inputs change?


#2

hmmm…Almost.

So, I still get a syntax error with the persistent library on your original suggestion "crv=doc.FamilyCreate.NewCurveByPoints(refptarr) persistent.Add(crv.Id)"

Which I can fix by pushinng persistent to a separate line.



However, it still doesn’t erase the previous items.



https://www.dropbox.com/sh/qkae0xsetkry5mc/TERRub2flt


#3

Hey Alex,



__persistent__ is just a python dictionary that should persist between script executions. Think about it as a record of past script calls. You can store elements in it that you want to access in a future invocation, and in that way it can be used to clean up old elements.



In the mobius example, we use it to store the old results of a loft, which we then clean up as shown in the example code shown above:



loft = doc.FamilyCreate.NewLoftForm(True, refarar) __persistent__.Add(loft.Id)



~Peter


#4

Sorry for the delay...


I'm still having a few issues with the code.


I tried using DynStoredElements as outlined in the sample, but I'm getting an 'undefined' error. Maybe I don't have the right libraries?


Also, I am having a few issues with the __persistent__ libraries and its somewhat odd syntax.



I just need to work at it some more.


#5

Hey Alex,



I'm guessing no news is good news. Did that work out? We definitely need to do some work to improve this workflow. If you have any ideas, please let us know on our Github issues page. We look at it everyday. :)



https://github.com/ikeough/Dynamo/issues?state=open



~Peter


#6

Hi Alex,



Sorry, I missed that because I had so many problems opening your solution. Again, our fault. :/



Check out the DynamicMobius example. You'll need to look at the .py file that comes with it (under Samples/09 Dynamic Python Editing/01-RPS-Mobius.py). You'll see the following code:



# The __persistent__ dictionary gives you a persistent
# dictionary between runs. Here we use it to store elements
# we wish to clean up later.


# Initialize if it's not already created.
if 'oldElements' not in __persistent__:
__persistent__ = []


#delete old elements
if __persistent__.Count > 0:
count = 0
for eID in __persistent__:
doc.Delete( __persistent__[count] )



This allows you to clean up your old geometry. This is actually a provisional solution we hope to improve on, but it should get you started.



Let me know if you need anything else.


#7

Thank you for your help. (and I am glad to be of help myself when I can)


So, you meant you got the sightlines to update dynamically?


I still can't get it to do that.


Even if I choose to "run automatically" I get duplicate solutions when I update the location of my original nodes.



https://www.dropbox.com/sh/qkae0xsetkry5mc/TERRub2flt


#8

Here's a link to a version of your dyn where I pulled out the output node:



https://dl.dropboxusercontent.com/u/1017585/sightline_003%20fixed.dyn



Thanks so much for your work and communication. The bugs you found were great. Consider contributing in the future to our github issues page - it's easiest for us to respond there:



https://github.com/ikeough/Dynamo/issues?state=open



Thanks,


Peter


#9

Hey Alex,



I'm a developer on Dynamo and I took a look at your dyn file. :)



You found a bunch of important bugs!



1) There was an Output node in your definition. These are only allowed in Custom Node workspaces. I updated Search in the dev directory so you shouldn't be able to place them in the home workspace anymore. This isn't your fault, but ours entirely.


2) For now, you'll need to place your dyf files in the definitions folder in your dynamo install directory. Again, this is our fault. I'll update it in the future to search in other places for your dyf files, like the directory where your dyn is. BTW, dyf files are the save format for Custom Nodes.


3) It seems like not all of your connectors were in place for your list node. This is when I looked at it without the dyf present. By default, this causes dynamo to return a Function on the list node, rather than the results of your node. This isn't always obvious to the user (indeed it's an advanced concept in functional programming!), so we're working on making this behavior more clear.



In short, your dyn file opens smoothly and runs without crashing on my machine with the newest build of Dynamo.



#10

Hmmm... I can get it to work on the sample file. But not on mine. (test for stadium sightline tool)



Rather than redraw the content it just creates a new set of sightlines.


Is the problem in the python syntax? or is it somewhere else?


files here: https://www.dropbox.com/sh/qkae0xsetkry5mc/TERRub2flt


#11

Yes. Take a look at the file in Help>Samples>Python Node. The "Connect 2 Point Arrays" sample has an adjustable list of reference points fed into the Python Node input, and the script recalculates based on these changing values.