Grasshopper

algorithmic modeling for Rhino

Hello! I'm catching up with C#. Earlier,I had acheived this using GHpython. How can it be acheived using c#?? Please help

#input x : boolean toggle 

import Grasshopper.Kernel as gh
import System.Drawing as sd

gh_doc = ghenv.Component.OnPingDocument()
a = []
b = []


for i in gh_doc.Objects:
    if type(i) is gh.Special.GH_NumberSlider:
       a.append( i.NickName)
       k = gh_doc.RelevantObjectAtPoint(i.Attributes.Pivot)
       b.append( k)


if x:
  for i in b:
     gh_doc.Select(i,True,False)

Views: 762

Replies to This Discussion

k = gh_doc.RelevantObjectAtPoint(i.Attributes.Pivot)

This is not a good way. It's the loooong way around and it will fail if there's another object on top of the one you're working with.

I'd go for something along the lines of:

foreach (IGH_DocumentObject obj in GrasshopperDocument.Objects)
{
  var slider = obj as Grasshopper.Kernel.Special.GH_NumberSlider;
  if (slider == null) continue;
  slider.Attributes.Selected = true;
}

wow! thank you Tom and David! :D

David's code is much nicer and more readable but if you end up doing a lot of GH document manipulation you can be quite efficient with Linq:

GrasshopperDocument.Objects.OfType<Grasshopper.Kernel.Special.GH_NumberSlider>().ToList().ForEach(s => s.Attributes.Selected = true);

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