Last active
January 19, 2021 16:22
-
-
Save fstwn/1f7e06ca9e8a787cc05056da1294a226 to your computer and use it in GitHub Desktop.
GhPython script for getting the names of a children of a Layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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