Export Layer States

Can we export layer states using Grasshopper.
I can export it using a Rhino script or manually. But I need to customize the data before saving to a file. That’s why I’m looking for a way to do it in Grasshopper.

Grasshopper doesn’t itself work with layers and it doesn’t run Rhino Commands. It is however possible to write a VB/C#/Python script that executes inside Grasshopper, but it seems like going the long way around for what you need.

I’d recommend using RhinoScript, RhinoPython or VB/C#+VisualStudio for this.

David Rutten

Hi Madhurya,

Here is a RhinoScript python example:

exportLayerState.gh (10.6 KB)

1 Like

@djordje - Thank you very much.
Is there a way that I can read the layer state values and change them before saving the file.
What I want to do is without saving the info like Layer0=Default;0;1;0;-1;0;0.00;1;0;1;0;0;0.00 I want to save it as a XML to be used in another software.

Sorry, that sounds too advanced for me.
You can export the LayerState as .xml, then read it back to component:

import rhinoscriptsyntax as rs

string = " _-LayerStateManager _Export " + path + "\\" + lyrStateName + ".xml" + " _Enter"

if export:
    filePath = path + "\\" + lyrStateName + ".xml"
    xmlFile = open(filePath, 'r')
    lyrState = xmlFile.readlines()

That will give you a list, where maybe you could perform some list.split(";") in order to receive each of those numbers as a separate item. This will require some additional coding on editing these numbers.
But that’s just my modest thought.
Wait for the more experienced coder’s advice.

exportLayerStateXML.gh (9.1 KB)

1 Like

@djordje - Thank you very much for your scripts.
With the help of that I created a c# version since I’m not familiar with Python, and then generated a xml using the data.
Thanks again :slight_smile:
MyExportLayerTest.gh (19.6 KB)

1 Like