Grasshopper

algorithmic modeling for Rhino

Hello World - I'd like to be able to access the Grasshopper Panel (sliders) and the 'bake' function via vbscript. It would be cool if there were some methods that could be written, or at least the provision for access to these options through Rhino's command line. Any thoughts?

Views: 3448

Replies to This Discussion

rhinoscript.org check the object_curve_animate vb tool


leave comments and pictures if you use it


:) good luck
Thanks Adam >> I have Rhino 4 SR5, so I won't be able to read your GH file. So sad! I got all excited at first...
Hi David, hi Matt,

did you guys had any luck with this? I'm trying to program (in VS2008 C#) a component that will set the upper and lower limits of a slider. The input of the component should be the name or Guid and the numerical values you denoted as well (lower limit, upper limit and value).
However, I'm having problems with getting the name or Guid of a slider component. Do you have any thoughts on how to do this in C#?

Thanks,

Roel.
Hi Roel,

Here's some code that will find the first slider in the current document that adheres to a specific name. Please don't store references to these object as they may be deleted. So you really should find it over and over again whenever you try to access it.

I didn't actually test this code (ahem), but it should at least get you started. GH_NumberSlider is defined in the namespace Grasshopper.Kernel.Special, so be sure to import that one.

This code block uses the OnPingDocument() method which is only available inside a class which implements IGH_DocumentObject (all components and parameters do this though).

public GH_NumberSlider FindSlider(string name)
{
   //Get the document that owns this object.
   GH_Document doc = OnPingDocument();
   //Abort if no such document can be found.
   if (doc == null) { return null; }

   //Iterate over all objects inside the document.
   for (int i = 0; i < doc.ObjectCount; i++)
   {
     IGH_DocumentObject obj = doc.Objects[i];
     //First test the NickName of the object against the search name.
     if (obj.NickName.Equals(name, StringComparison.Ordinal))
     {
     //Then try to cast the object to a GH_NumberSlider.
     GH_NumberSlider sld_obj = obj as GH_NumberSlider;
     if (sld_obj != null) { return sld_obj; }
     }
   }
   return null;
}


--
David Rutten
david@mcneel.com
Poprad, Slovakia
Here's code to set the slider domain and value:

public bool SetSlider(GH_NumberSlider sld, double min, double max, double val)
{
   sld.set_MinValue(false, min);
   sld.set_MaxValue(false, max);
   sld.SliderValue = val;
   sld.ExpireSolution(true);
}


But note that you're not supposed to update sliders while you're inside a solution. So if you're doing this from within GH_Component.SolveInstance, there's really no way this is valid, as you're expiring a slider while a solution is being computed.

I'm not entirely sure how you are planning to use this.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks David, I will come back to you after 'testing' the code. I'm curious too, to see whether this will work.

David,

This is a very useful bit of code to see. To limit the updates an event trigger would seem appropriate.  I have a couple of questions.

1. Is it possible to track events for when an input is touched?

For example if a slider were attached to the second input of a custom component can is there a way to track the relevant event?

2. Is there any sample code for this that is available?

this is a old post but i had to use

owner.OnPingDocument();

instead of 

OnPingDocument();

To make it work...

Thanks Again David...

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