Grasshopper

algorithmic modeling for Rhino

Hi all, so I'm working on a large project that needs to take advantage of cluster organization, and to manipulate slider values from within the Python component.

So far I've been using the excellent bit of code from this discussion with no problems.

http://www.grasshopper3d.com/forum/topics/change-number-slider-para...

However since clustering, my Python script (within the cluster) and sliders (on the main canvas) no longer interact.  Is there a line or two of code that can reconnect the two?

I've attached a simple example to illustrate the problem.

Views: 1543

Attachments:

Replies to This Discussion

You can access objects inside a cluster using .Objects. Here is an example:

if type(obj) == gh.Special.GH_Cluster:
       

       clusterDoc = obj.Document("")
       

       for clusterObj in clusterDoc.Objects:
           #try to find sliders and so on

Hi Mostapha,

It seems like you misunderstood my question.  What you've provided would be a solution if I needed to manipulate a slider that was inside a cluster (with the python component on the main canvas).

However my problem is the opposite.  I need to access a slider that is on the main canvas (from inside the cluster).

If you download the example file I provided that should clarify the problem.

To access the "parent document" from inside a cluster, get the current GH Document's "Owner" property and cast it to GH_Document. Probably a good idea to test for null - if it's the topmost document it won't have a valid owner. Once you've got that though you can replace any references to the current GH document in your script with the owner and everything should behave as expected.

Thanks for the response Andrew.  This seems like the right direction but I don't know how to access the "Owner" property.  All I get when I print Grasshopper.Kernel.GH_Document.Owner is this:  <property# Owner on GH_Document>

Maybe you could tell me how to access it or give an example?

I have a feeling you'll want to use Grasshopper.Kernel.IGH_OwnerDocument, but I'm not near a computer so I can't verify. Try pinging the parent document and, like Andrew said, replace OnPingDocument().Objects with the owner objects.

Not sure if it's because this strategy doesn't work or because I'm so new to ghpython, but I still haven't solved this.

Try this line inside the GHPython component in the cluster. docObjects is the list of objects in owner document:

docObjects = ghenv.Component.OnPingDocument().Owner.OwnerDocument().Objects

Nice one, that did it.  Thanks!

Looks like I'm a day and a buck short; Mostapha beat me to it! Was just about to post the same solution after (finally) getting to look at it in GH. Glad it's working for you.

/SPM

How would you test to see if the component is in a cluster, as Andrew commented on above, as it works nicely in a clustered code but not outside a cluster. 

Also any idea how i could translate this code to maybe C# solve this issue here.

http://www.grasshopper3d.com/forum/topics/trampoline-script-counter...

Thanks

Matt

Hi all,

I am kind of a beginner in scripting...

I am trying to update my slider in the canevas with a C# component inside a cluster.

I manage to do it with python following your instructions, however i didn't manage to get it work with the following lines in C# from Guilio's Trampoline component...

GH_Document RecurseUpTillHighestParentIsFound(GH_Document ghDoc)
{
if(ghDoc.Owner != null && ghDoc.Owner.OwnerDocument() != null)
{
return RecurseUpTillHighestParentIsFound(ghDoc.Owner.OwnerDocument());
}
else return ghDoc;
}

I would really appreciate some help :)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service