# Sort layers RhinoScript

**URL:** <https://discourse.mcneel.com/t/sort-layers-rhinoscript/10975>\
**Category:** Scripting\
**Created:** [August 17, 2014, 9:51am UTC](https://discourse.mcneel.com/t/sort-layers-rhinoscript/10975 "2014-08-17T09:51:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hughes\_Tooling](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hughes_tooling/32/717703_2.png) [@Hughes\_Tooling](https://discourse.mcneel.com/u/Hughes_Tooling)\
**Post date:** [August 17, 2014, 9:51am UTC](https://discourse.mcneel.com/t/sort-layers-rhinoscript/10975/1 "2014-08-17T09:51:11Z")

</div>

I have a couple of scripts that add layers to the current layer, is there some way to sort just the current layer after the new layers have been added.

Thanks Mark

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/772741_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [August 25, 2014, 9:37pm UTC](https://discourse.mcneel.com/t/sort-layers-rhinoscript/10975/2 "2014-08-25T21:37:21Z")

</div>

> [@Hughes\_Tooling](#):
>
> add layers to the current layer

I’m not sure I understand this. Are you adding sub-layers of the current layer?

> [@Hughes\_Tooling](#):
>
> is there some way to sort just the current layer after the new layers have been added

You could sort the layer names before adding them…

---

<div class="post-metadata">

**Author:** ![Hughes\_Tooling](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hughes_tooling/32/717703_2.png) [@Hughes\_Tooling](https://discourse.mcneel.com/u/Hughes_Tooling)\
**Post date:** [August 26, 2014, 11:30am UTC](https://discourse.mcneel.com/t/sort-layers-rhinoscript/10975/3 "2014-08-26T11:30:40Z")

</div>

One of the scripts adds 3 layers Crvs, Dims and Model to the current layer, they are added alphabetically. The second script adds 3 layers I use when I export to my CAM program and I’d like all six layer in alphabetical order. I guess what would be useful is some way to sort all the sublayers of just the current layer.  
I don’t want to add all six layers at the same time because the CAM layers are not always needed.

Thanks Mark

---

<div class="post-metadata">

**Author:** ![djordje](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/djordje/32/747634_2.png) [@djordje](https://discourse.mcneel.com/u/djordje)\
**Post date:** [August 26, 2014, 1:05pm UTC](https://discourse.mcneel.com/t/sort-layers-rhinoscript/10975/4 "2014-08-26T13:05:14Z")

</div>

It would be nice if RhinoCommon [Layer.SortIndex](http://4.rhino3d.com/5/rhinocommon/html/P_Rhino_DocObjects_Layer_SortIndex.htm) method could be used to set the new sortindex value also, not only to return its current value.
