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

Hi Mostapha,

Ok i didn't know that you're searching for python. I thought you had some other situation, where you couldn't get the GUID from a geometry.

Well in this case you can just use this:

 

import System.Guid as Guid

import Rhino

doc = Rhino.RhinoDoc.ActiveDoc

gid = Guid.Parse(x)

obj = doc.Objects.Find(gid)

a = doc.Layers[obj.Attributes.LayerIndex].Name

 

Hi Florian, Thanks again. This is what happens when I try it. I tired couple of different ways to pass x to Parse but it never worked.

Hi Florian,

Thank you for your help. I didn't known the ID component before your post ! So I looked for a lot to find how to retrieve the objects Id.

Regards,

Michel

Genius, Alter, genuis! in nem 3-Zeier ich geh kaputt. Danke dir.

Hi Mostapha,

You cast the Mesh on the input to a string type...this will cause the value "Rhino.Geometry.Mesh" and not the desired guid. put the ID (which you show on the panel) to the string input of the python script ;-)

Thanks Florian! For some reason I totally forgot about this discussion! Thank you Michel to make it live again. So apparently I couldn't clearly explain my problem.

What I'm looking for is not to use the ID component and find the layer of the objects using GHPython. In C# component GUID type Hint just gave the same ID as ID component so one can find the object attributes as you did, however GHPython Component gives a different GUID for the same object, and the GUID changes each time that I ran the script.

Since this GUID is not the right ID/GUID of the object so I cannot use it to find the object attributes (When I try to find the object it returns no object which totally makes sense because it is not the right ID).

in the image below, you can see how the IDs from the Python component for the same objects are different from the C# and ID component:

Thanks,

Mostapha

Hi Mostapha,

glad you came back ;-) As i said, you have to connect an ID containter to whatever geometry first, and then connect it to the python component as String.

Python works a little different than the native .net languages. The guid might come from GH rather than from Rhino, i don't know. It's definitely not the one from the Rhino Reference. You have to ask Steve if you want to know why.

But this works:

import System.Guid as Guid

gid = Guid.Parse(yourStringInput)

//Guid cast only with grasshoppers "ID" component that's safe ;-)

Best,

FF

Hi Florian, thank you for the quick reply. :)
I agree that Steve can help.
I think I'll also take a look to GHPython source code when I get a chance.
I'll post it here if I find the solution.
Best,
Mostapha

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service