Grasshopper

algorithmic modeling for Rhino

How can i get the object name(s) of an object grouped togheter with a c# script/component?

Views: 1460

Replies to This Discussion

Like this?

 

In Main:

List<Grasshopper.Kernel.Parameters.Param_GenericObject> objects
      = FindObjectsInCurrentGroup<Grasshopper.Kernel.Parameters.Param_GenericObject>();

Function:

private List<T> FindObjectsInCurrentGroup<T>() where T : Grasshopper.Kernel.IGH_DocumentObject
  {    
    List<Grasshopper.Kernel.Special.GH_Group> groups = GrasshopperDocument
      .Objects
      .OfType<Grasshopper.Kernel.Special.GH_Group>()
      .Where(gr => gr.ObjectIDs.Contains(Component.InstanceGuid))
      .ToList<Grasshopper.Kernel.Special.GH_Group>();

    Print("{0}", groups.Count);
    List<T> output = groups.Aggregate(new List<T>(), (list, item) =>
      {
      list.AddRange(
        GrasshopperDocument.Objects.OfType<T>()
        .Where(obj => item.ObjectIDs.Contains(obj.InstanceGuid))
        );
      return list;
      }).Distinct().ToList();

    return output;
  }

Why Grasshopper.Kernel.Parameters.Param_GenericObject ? That will not find the Panel as Panel doesn't derive from Param_GenericObject. 

Oops my bad. Accept my apologies.

Until a proper demo is ready get this.

Attachments:

Here we are (again: accept my apologies).

Moral of all these: Buy a proper Ducati, what else? (see def)

Attachments:

And the trad update

Attachments:

Errata : objects4 instead of objects2

Hi guys!

Sorry for late reply, my dsl at home is offline this week.

Thanks a lot peter! uber stuff as always...

I'll take my time to metabolize it and then i'll post here what i'm working on.

Thanks again.

Hmm ... I suspect that you want to find all groups in the document otherwise it doesn't make much sense ... or maybe it does who knows? he he.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service