Grasshopper

algorithmic modeling for Rhino

hi! :-)

Is it possible to find a sliders GUID only using the python component? (not C#)

Is it possible to change a slider from inside the python component (e.g. from 0<0.1<1 to 0<0.1<5) ?

How can i convert a GUID for a point, plane, brep, srf ect. back to the original GH geometry (also inside the python component) ?

I would also like to hear for what purpose and context GUIDs in generally is used?

I'm a python/rs/rc/ect. newbie but i'm only getting better by exploring the possibilities :-)

Views: 5048

Replies to This Discussion

Hi Thomas. The attached definition should get you going with regards to getting/setting slider properties using GHPython.

In general I would recommend not to operate on GUIDs when scripting within the Grasshopper document. You can read more about GUIDs both on this forum and on the McNeel wiki. But in general they are more appropriate when you are targeting the Rhino document directly. That said, to get the RhinoCommon object "behind" a GUID you can use the rs.coerce methods in the RhinoScriptSyntax module.

Hope that helps (a bit)..

Attachments:

Thanks! This is awesome! But I'm not fond of the constant pinging.. Is it possible to get the guid from the sliders connected to a python component without pinging?

Try this.

Attachments:

Thanks again! It works perfectly :-) 

Hi Thomas,

In addition to Anders great answer:

Once an object (geometry, grasshopper component...) has been added to the Rhino/Grasshopper document, the way to identify it, is by checking it's guid (globally unique identifier).

Here is how to change the range and value of a slider:

gh = Rhino.RhinoApp.GetPlugInObject("Grasshopper")

gh.SetSliderRangeAndValue("slider_guid", 0.1, 0.0, 5.0)

But this does not change slider's rounding (meaning if before this you had an integer rounding, you can not convert it to float.

About your last question: You have referenced some geometry from Rhino to grasshopper? Can you attach your .gh and .3dm file?

actually I'm already using the gh.SetSliderRangeAndValue function to change the slider value, but I hadn't realised it was possible to change the range too. :-D thank you very much! 

rs.cource seems to do the trick mentioned in the 'last' question. 

Generally about GUID http://en.wikipedia.org/wiki/Globally_unique_identifier#Common_uses

In Rhino we use GUIDs mostly to identify objects (This is the most common usage from the 3rd party developer point of view). When you create an object with code (like circle), the function returns it's new GUID, therefor you can use it later on to modify this object.

In Grasshopper (again form the 3rd party POV) the most significant place where we use GUIDs is when we create a new component. Each class(component) has it's own component GUID, which is used by Grasshopper to identify component type properly. Ideally, when a developer updates his/her plugin, and some component changes it's behavior slightly, we mark it as obscure and create a new component with a new GUID. 

That way developer can decide what happens on the end user side once he/she updates the plugin. 

Let's say you have some definition which uses component named "Black hole" (yes, it creates a randomly placed black hole in our universe, achieved with division by 0).

We have at least 2 situations after the update:

1. "Black hole" changed just a bit (some bugs causing creation of antimatter black holes). Developer doesn't change the componentGuid, end user can open his/her file which will utilize the updated "Black hole". The difference is that it now works more robust - it'll cause less crashes, especially when antimatter reacts with matter.

2. "Black hole" changed a lot (developer decided to add new parameter - now the user can specify the radius of event horizon). Developer creates a new component with a new componentGuid, which is named the same, and occupies the place left after the old one. Developer also sets the old component to be obsolete.

When end user opens the file with the old "Black hole" component, he/she can see the "Old" label drawn on it... but the old "Black hole" component isn't visible in a component panel anymore. End user can decide if he/she want's to use the new "Black hole" or stay with the old one (who needs the radius of event horizon ?). 

There is also another GUID which is created each time you place a component on a canvas (InstanceGuid). It can be used to find a particular instance of component on particular canvas. You can create somehow a new component on a canvas (it's actually quite cumbersome), and then find it again with the same script.

Maybe a bit better example is my own - Anemone. If you're familiar with this plugin, you know that it relies on 2 components linked together. They have to be connected with each other, also they cannot connect with more than one instances (no 2 starts can connect with one end and vice versa). Once they connect with each other, they exchange information about their InstanceGuids. That way End can quicky look for Start when it want's to copy it's data back (there is a function in GH SDK to search for particular component on a canvas). The InstanceGuid is the most robust method to find a particular component. You can search for components with a particular name, but name and nickname can be changed by end user.

This also applies to Parameters (inputs and outputs).

Thank you for this very fine and detailed description!

Mateusz rocks the house. Thank you from my part too.

Great breakdown. I should add that my original post was primarily focused on operating on geometry GUIDs. If one is scripting Grasshopper itself, indeed canvas object GUIDs are super useful (necessary even). Apologies for any caused confusion :)

Is it possible to find a sliders current value, range and number of decimals if I only have the guid? What function would it be? I can't find it myself.. does it exist? :-) 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service