I’ve written a quite simple C# component for Grasshopper.
It creates a new layer in Rhino, and I now want to make that layer ‘Current’ (in order to then write certain geometry to that Layer) – however I cannot get this working.
where ‘index’ is an integer, and is the ‘LayerIndex’ of my newly created layer. (Checked this, and I’m very sure it’s the correct number).
The error I get is:
Error (CS0120): An object reference is required for the non-static field, method, or property 'Rhino.DocObjects.Tables.LayerTable.SetCurrentLayerIndex(int, bool)' (line 137)
I’ve read up on this problem over at StackOverflow (surprise!) and a few other places, and tried to implement some of their suggested solutions like putting this Method into a new class, defining it as ‘static’, etc, etc. No methods working yet.
Any ideas?
(and apologies if this is a really simple question – I’ve only been using C# for a few weeks.)
No solution there either! (give me the same ‘Non-Static field error’…)
The full code is:
// Create a child layer -------------------------------------
string child_name = "TempPatchLayer";
Rhino.DocObjects.Layer JNewLayer = new Rhino.DocObjects.Layer();
JNewLayer.Name = child_name;
JNewLayer.Color = System.Drawing.Color.Red;
int index = 100;
JNewLayer.LayerIndex = index;
// Bring New layer into Rhino ----------------------
RhinoDoc.ActiveDoc.Layers.Add(JNewLayer);
JNewLayer.CommitChanges();
// Make New Layer 'current' ---------------------------------
// option (1) not working ---- Rhino.DocObjects.Tables.LayerTable.SetCurrentLayerIndex(index, quiet);
// option (2) not working
RhinoDoc.ActiveDoc.Layers.SetCurrentLayerIndex(index, true);
Hi Jeg,
I am using python, so can’t help you out with your c# syntax.
I would advise you not to set the LayerIndex property, but instead to use the one that RhinoDoc.ActiveDoc.Layers.Add(JNewLayer); returns. Then supply that index to the SetCurrentLayerIndex method.