Grasshopper

algorithmic modeling for Rhino

I have a very simple python script that is supposed to get an object from a layer but I keep on getting an error saying that this function is not callable from inside Grasshopper. Can someone please explain this to me.

Thanks.

Jon

Views: 814

Attachments:

Replies to This Discussion

Hi Jon

are you sure that a class is the correct data structure to represent the block placement behavior?

In any case, the Layer calls do not work in the Grasshopper document context, because they refer to layers (while Grasshopper has no knowledge of layers). So, you can use layers if you switch the target document for RhinoScript to Rhino.RhinoDoc.ActiveDoc, like this:

import scriptcontext
import Rhino
scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc

After this, all RhinoScript methods will be targeting the Rhino document, not the Grasshopper definition (you will see side effects in the document).

I attach the script with the change. I hope this helps,

- Giulio
________________
giulio@mcneel.com

PS: Please try the new version of GhPython.

Attachments:

Giulio, In response to your first quesstion - no I am not sure a class data structure is the correct structure. the idea was to read in some blocks and place them based on how far they are from a set of points. I thought I could encapsulate all of this functionality into a class. If you think there is a better way please let me know as I am definitely not an OOP expert.

Thanks for the help. I think I sometimes get confused as to what grasshopper has knowledge of. I have added some other files where I start to insert the blocks. This part fails. I assume it is because the rhinoscript methods are now targeting the document. Can you please take a look when you get a chance and if this is the case tell me how to revert back to targeting grasshopper.

As always thanks for your help and insights.

jon

Attachments:

hi giulio

i'm running into the same problem. tried to go around it using your suggestion but couldn't make it work. i get this error:

Runtime error (ValueErrorException): 4d859156-5a82-4e50-b88f-5eff9f286ee7 does not exist in ObjectTable

i'm using latest gh and ghython versions.

thanks

diego

Hi Diego,

maybe next time can I ask you to create a new discussion, and add the file you are working on (and a concise explanation)?

If you are just trying to collect all objects on a layer, in order to use them later in Grasshopper, calling the command is the wrong way around (it's more complicated than necessary).

The attached script shows how to address what you are trying to do (if I guessed it right).

I hope this helps,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Attachments:

Hi Giulio,

I have just taken a look at rs.coercegeometry()'s RhinoCommon code, and I am not sure I understand it.
Is this some universal replacement function for rs.coercebrep (in this case) but also rs.coercesurface, rs.coerce3dpoint ...
?

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