Layer table index vs. Layer ID

While looking at layer table methods for another thread, I came across this:

However, when trying to get an object’s layer via object attributes, there is no method currently available other than using the layer index…

The above statement in the RhinoCommon api guide then seems contradictory… If it really is the direction we are going, doesn’t object attributes need an additional property LayerId ?

2 Likes

@Helvetosaur, there is a different between “We are moving towards…” and “We have moved…”.

– Dale

Yep… but it you want to pave the way for the move, you need to provide the bricks… :stuck_out_tongue_winking_eye:

I can provide some bricks the day when layer indices stop working and i have to rewrite everything :flushed:

_
c.

Hi

So if I want to set the layer to an object I understand I need to do it through the attributes.

But the attributes only takes layer index, and the method to obtain the layer index from the layer name is obsolete.

So how can I do this?

Hi @n.leguina,

How about this:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var layer_index = doc.Layers.FindByFullPath("MyLayer", 0);
  
  var circle = new Circle(Plane.WorldXY, 5.0);

  var attributes = doc.CreateDefaultAttributes();
  attributes.LayerIndex = layer_index;

  doc.Objects.AddCircle(circle, attributes);
  doc.Views.Redraw();

  return Result.Success;
}

– Dale

Thanks so much Dale!!!