Grasshopper

algorithmic modeling for Rhino

Hello everybody,

Despite a huge effort reading the forum and the documentation I can't write the function to access to the layer name of an object or other attributes.

Extract of my code :

Private Sub RunScript(ByVal mesh As Mesh, ByRef A As Object)
   
    A = mesh.??? > which property to get layer name that contains the mesh

or

    A = Rhino.ObjectLayer(strObjectID) but how to access to strObjectID ?

  End Sub

Thanks for your help.

Michel

Views: 18448

Replies to This Discussion

Things like layers, names, colours, linetypes etc are stored on the attributes of Rhino objects. A Rhino object (like a mesh) contains geometry (the actual mesh shape) and attributes. If you only have the geometry then it's too late to get layer data. 

Where does the mesh come from?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

The mesh comes from Grasshopper in fact, baked in Rhino in a particular layer. Then I read it back in Grasshopper by 'select mesh'. So the mesh is in Rhino stored in a layer. (I must make some manual modification to the mesh so I cannot always stay in Grasshopper).

If the mesh data in Grasshopper is still referenced (tooltip of the data should tell you), then you can convert the mesh to a GUID and import the GUID into the script. It's a bit awkward, but there's no other way to do it using the script components. If you were writing a GHA library then you could choose to get access to the GH_Mesh instance, which has both the mesh geometry and the Rhino object ID.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

I'm often casting the IGH_ActiveObject owner... to type GH_Component, so i have access to all inputs and outputs (linked Components). But isn't there a way to get to the IGH_DataAcess object of that component. If so, it would be easy to get the GH_ geometric type of the object.

Cheers FF

Thank you David. After studying your message and others I think I can go on. What I try to do : from multiple meshes I would like to have a unique list of points and different groups of meshes, with vertices related to this list of points. The groups of meshes would be distinguishable by an Id like the layer if they come from Rhino or by an string Id it they come from GH.

Michel

Hi Michel,

This is a script, that gets the layer from a referenced geometry (of every kind) in gh:

if(obj == null) 
  return;

 

int lIndex = doc.Objects.Find(obj).Attributes.LayerIndex;
Print(doc.Layers[lIndex].Name);

For bake with attributes in Grasshopper check out FabTools

Cheers

FF

Attachments:

Hi Florian,

Do you also know how is it possible to script finding the ID of a referenced object?

Thanks,

-Mostapha

Hi Mostapha,

this is an interesting topic. In script components it seems, that you can't cast objects to their GH_ geometric container, so there is no reference id.

In a custom GH_Component it's fairly easy though:

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddMeshParameter("Mesh", "M", "", GH_ParamAccess.item);
//Optional Input
//pManager[0].Optional = true;
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.Register_GenericParam("info", "", "Information");
}
protected override void SolveInstance(IGH_DataAccess DA)
{
GH_Mesh data = default(GH_Mesh);
DA.GetData(0, ref data);
DA.SetData(0, data.ReferenceID);
}

 

Cheers

FF

I hope this is what you were asking.

Hi Florian,

Thank you for the reply. To find the ID of the objects in script component is what I was looking for. At least now, that you say that there is no way to do that in script components, I don't feel bad that I couldn't figure it out! :)

Thanks again,

Mostapha

It's actually really easy, just set the type hint of a scripting component input as GUID and connect the parameter with referenced geometry to it.

If you want to find out the layer name where the object is located (the x input having the type hint as guid):

 

   Dim obj As New docobjects.ObjRef(x)
    a = doc.Layers(obj.Object.attributes.LayerIndex).name

hmm... someone answered almost the same thing above. Not sure what is the problem then.

Thanks Vicente. I assume this trick works only for C# and VB components but there is no GUID option for GHPython. I assume this is because GHPython is set up to work by GUID as default, however when I use the GHPython GUID to find the layer it fails. I'll provide an example when I go back to my desk. -Mostapha

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service