Python - move layer set under new parent layer


#1

OK, lets say I have a set of hierarchical layers/sublayers (leave them empty for now), and I want to create a new parent layer and move the entire existing layer hierarchy under it:

I’m having trouble doing this - I thought it would be sufficient to get the full path name to each layer and then add the parent layer name to that at the front: parentName+"::"+layerpathName, then add a layer to the document with that full path. But it doesn’t work… Anyone have a logic for doing this?

Thanks, --Mitch

LayerHierarchy1.3dm (35.7 KB)

LayerHierarchy2.3dm (36.0 KB)


#2

OK, I think I got it more or less -

  1. Get all top-level parent layers from layer table - ignore others
  2. Get ID of new parent layer
  3. Use layer.ParentLayerId=(ID of new parent layer above) to set new parent layer
  4. layer.CommitChanges() to “finalize” the changes
    Rhino’s internal layer managment system takes care of the sublayer moves, all I have to do is move the top-level parents.

I have to run out now, so I need to see how this works and integrates in the script I’m working on (as this is just a part of it)

–Mitch


(Dale Fugier) #3

You got it…