Grasshopper

algorithmic modeling for Rhino

I will likely switch to Python to grab layer objects since Pipeline seems broken to hidden objects inclusion, outputting nothing when the option to include hidden objects is used:

Views: 814

Replies to This Discussion

Indeed, Python to the rescue:

import rhinoscriptsyntax
import scriptcontext
import Rhino

OBJECTS_CONTAINER = []

scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc # Speak directly to Rhino

ALL_OBJECTS = rhinoscriptsyntax.ObjectsByLayer("Nik_Mesh_Cocoon_NURBS_Solids_Input") # Get GUIDs of each object.

for q in ALL_OBJECTS:
  EACH_OBJECT = rhinoscriptsyntax.coercebrep(q) # Grab actual objects from GUIDs "coerced" as breps.
  OBJECTS_CONTAINER.append(EACH_OBJECT)

ObjectsFromInputLayer = OBJECTS_CONTAINER

scriptcontext.doc = ghdoc # Return Python state of speaking to Grasshopper

Based on: http://www.grasshopper3d.com/forum/topics/use-objectsbylayer-in-pyt...

Now how do I leave out Hidden Objects at will? Delving into rhinocommon.chm....

Hi Nik,
rhinoscriptsyntax module itself has a IsObjectHidden function. You check if an object is hidden before adding it to your OBJECTS_CONTAINER list:

import rhinoscriptsyntax
import scriptcontext
import Rhino

OBJECTS_CONTAINER = []

scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc # Speak directly to Rhino

ALL_OBJECTS = rhinoscriptsyntax.ObjectsByLayer("Nik_Mesh_Cocoon_NURBS_Solids_Input") # Get GUIDs of each object.

for q in ALL_OBJECTS:
    if rs.IsObjectHidden(q) == False:
        EACH_OBJECT = rhinoscriptsyntax.coercebrep(q) # Grab actual objects from GUIDs "coerced" as breps.
        OBJECTS_CONTAINER.append(EACH_OBJECT)

ObjectsFromInputLayer = OBJECTS_CONTAINER

scriptcontext.doc = ghdoc # Return Python state of speaking to Grasshopper

Ah, thanks, I only looked in rhinocommon.chm not also RhinoScript.chm!

It's also in RhinoIronPython.chm.

Just to round this one off. I'm fairly certain that rs.IsObjectHidden() is simple a wrapper around the RhinoObject property IsHidden. You can always check the RhinoScriptSyntax source directly, on my system it is located here:

C:\Users\adel\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript

Indeed, in object.py is this:

def IsObjectHidden(object_id):
    """Verifies that an object is hidden. Hidden objects are not visible, cannot
    be snapped to, and cannot be selected
    Parameters:
      object_id: String or Guid. The identifier of an object
    Returns:
      True if the object is hidden
      False if the object is not hidden
    """
    rhobj = rhutil.coercerhinoobject(object_id, True, True)
    return rhobj.IsHidden

I've noticed this bug before as well. As far as I can recall, checking both "Include Locked Objects" and "Include Hidden Objects" will get the Rhino doc objects though. The good thing about the Pipeline is that you do not have to monitor events yourself (which can be rather complex)..

I'm already leaving the solver disabled to allow a Rhino user to work unencumbered by "creepy" Grasshopper until he manually issues a Recompute menu command to invoke a single cycle of Grasshopper. For any Grasshopper script that is rather slow it's the only way to go. It's not in the manual that Recompute still works with the solver disabled, but then there is no manual in the first place.

Ah see. In that case it properly actually does make a lot of sense to explicitly manage when objects are loaded into Grasshopper from the the Rhino doc (using Python or one of the other scripting components). I've previously used this approach quite extensively using formalized Rhino layering conventions (naming, color, parent/child relationships) and a simple button to reload the Rhino objects at will.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service