Grasshopper

algorithmic modeling for Rhino

Hi All,

I am trying out to get the data from a parameter by invoking the "VolatileData" of the Battery but I am losing the tree structure. Not sure why this thing happens...I had it working in other occasions...Also if you try and print the result you will get a weird : structure {0;1;2;3;4;5;6;7;8;9}

am I doing something wrong?

Cheers

Views: 1140

Attachments:

Replies to This Discussion

Hi

you should not need to use VolatileData in general in GhPython.

What are you trying to do?

Thanks

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Hi Giulio,

I am loading the data from one GH script and I want to pass them to a parameter located on another script. Basically you can avoid having one huge script, or bake and re-reference elements to pass them from one script to another. 

This is what I am basically doing

import clr
clr.AddReferenceByName("Grasshopper")

import rhinoscriptsyntax as rs
import System
import Rhino
import Grasshopper
from Rhino import RhinoApp, RhinoDoc
from Rhino.Geometry import *

gh = RhinoApp.GetPlugInObject("Grasshopper")

def FindBatteryByNickname(docObjects, name):
if docObjects is None: return None

for obj in docObjects:
attr = obj.Attributes
if attr.PathName == name:
return obj
raise Exception(name + " was not found in document")

def FindGrasshopperFile(name):

for x in range(Grasshopper.GH_InstanceServer.DocumentServer.DocumentCount):
myDoc = Grasshopper.GH_InstanceServer.DocumentServer.DocumentNames[x]
if (name == myDoc or name + "*" == myDoc):
return Grasshopper.GH_InstanceServer.DocumentServer[x]
raise Exception(name + " is not one of the Open Documents")

doc = FindGrasshopperFile(GHname)
myp = FindBatteryByNickname(doc.Objects, DataName)
D = myp.VolatileData

An easy method for passing data between definitions, components, the grasshopper document and the Rhino document is to use the sticky dictionary which can be accessed from all RhinoPython interfaces (GHPython and the EditPythonScript editor). Just import sticky and add your key/values to it..

Hi Anders,

Thanks for your reply. If there is an established way to store values that is great.

I tried:

import sticky

but there is no auto complete! Is this what you mean? Can you give me a simple example of how it is used?

Cheers,

Stam 

The sticky dictionary is within the scriptcontext module.

import scriptcontext as sc
sc.sticky

This is a fairly relevant discussion. It'll help explain how sticky is used between components, at least. I suggest reading Giulio's "Word to the Wise" comment.

/SPM

In addition to Stephen's notes/link: It is literally a Python dictionary (i.e. a hash table or associative array). You can read more about it in the official Python docs: https://docs.python.org/2/tutorial/datastructures.html#dictionaries

Thanks Stephes, Anders,

I guess it is a solution to use sticky but this means you would need to have two components, one that saves and one that loads sticky and you would need to be carefull not to give them the same name. I can work with that in GH, but I think my problem still remains in "editPythonScript"

Basicly I am having an automation script that looks into certain parameters using the function FindBatteryByNickname() that Guilio wrote in another post. Then I want to update the data using data from another parameter. What I am using so far is param.setPersistentData(anotherParam.VolatileData) In this case where I have one script I don't know how the sticky can come into play. I am getting the object from the FindBatteryByNickname() and I have to use Volatile to take the data, it is not the same as using the inputs in a python cluster where you could say cs.sticky['x'] = x , this "x" is your actual data with its structure and everything. In the end of the day the Volatile data thing should work and it has worked for me in half of the script...I transfered the problem in this small cluster to be more specific but the actual script is like so:

load "GH file 1"

Compute

Load "GH file 2"

assign parameters from "GH file 1"

Compute

Get Result

Any Other ideas?

I think you might be overcomplicating your pipeline. Is there any reason why you can't just have the whole process in one GH definition with two overall sub-processes? It is pretty straightforward to only send data downstream once/if some condition has been met (data dam, filter, scripts etc, see attached).

Attachments:

Well I don't think so :D

Each of those scripts takes around 15mins plus they might need to be combined in differend ways...

I am not trying to create a data gate, or something like that.

My problem is how to simply assign values of GH Data Types within a Python script while at the same retaining the structure of those variables. I was using .volatileData to access their data but that seems to be unreliable.

I must admit that I'm not really sure what it is you're trying to do. If you need to pass around data in memory in the same Rhino/GH session, use the sticky dictionay. If you need to pass around data on disk between different Rhino/GH sessions you can try pickling the data using Python or just use Dave Stasiuk's TreeSloth which has Pack/Unpack data. All these options should allow you to maintain the data structure. You could of course also just internalize the data in a GH definition ;)

Hey Anders,

Yes Packing and Unpacking would be one solution to circumvent the problem! I am using my own version right now, because at the time I created the GH scripts those were not out. Of course you need to save it externally which is not ideal! 

To answer your question my goal is to transfer data between GH scripts (not between Python scripts). I am doing exactly what you suggested with "picking the data using Python" but it does not work! I think that would be ideal for me, right now, of course there are many way to skin a cat but I was hoping to automate certain aspects of the script and require no special extra components (like Packing/Unpacking/Saving externally) and being able to automatically set inputs and outputs to different components is important for me. Hope that clears it out a bit.

Thank you for your effort so far, sorry if I was not so clear from the beginning.

I took lots of ideas from here (one of your replies :) ):

http://www.grasshopper3d.com/forum/topics/use-pythoneditor-to-run?i...

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service