Skip to content

Instantly share code, notes, and snippets.

@fstwn
Last active January 19, 2021 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fstwn/1f7e06ca9e8a787cc05056da1294a226 to your computer and use it in GitHub Desktop.
Save fstwn/1f7e06ca9e8a787cc05056da1294a226 to your computer and use it in GitHub Desktop.
GhPython script for getting the names of a children of a Layer
"""
Returns all child layers of a specified layer.
Inputs:
Layer: The layer to check for children.
{item, str}
Output:
Children: The child layers of the specified layer.
{item/list/tree, str}
Remarks:
Author: Max Eschenbach
License: MIT License
Version: 210119
"""
# import rhino and gh stuff
import rhinoscriptsyntax as rs
import scriptcontext
import Rhino
import Grasshopper
# get documents
ghd = ghenv.Component.OnPingDocument()
rhd = Rhino.RhinoDoc.ActiveDoc
# set rhinodoc as active document
scriptcontext.doc = rhd
# check for layer children
if rs.IsLayer(Layer) and rs.LayerChildCount(Layer):
full_names = rs.LayerChildren(Layer)
Children = []
for fn in full_names:
Children.append(fn.split("::")[-1])
else:
Children = Grasshopper.DataTree[object]()
# set rhinodoc as active document
scriptcontext.doc = ghd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment