Grasshopper

algorithmic modeling for Rhino

Hallo guys,

i'm a beginner with C# so sorry for the noob question.

I have a series of polylines and i need to create for each polyline a text on a new layer (named by an input series of strings).I'm having problems moving text elements on a new layer.Do i have to use the layerIndex?Please Can sombody help me?

I already searched in the forum looking for a solution without having success.

Attached rhino and the piece of code.

Thak you all and have a nice day!

Paolo

Views: 2154

Attachments:

Replies to This Discussion

Ciao Paolo,
i've added a short method to ensure the Layer. It returns the index in any case (layer exists/ new layer added). that's it...

 

  private void RunScript(bool toggle, Polyline contour, string tag, ref object A, ref object B, ref object C)
{
if(toggle){
Plane textLoc = Plane.WorldXY;
textLoc.Origin = contour.CenterPoint();

Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
att.Name = tag;
att.LayerIndex = ensureLayer(tag);

Rhino.Display.Text3d t = new Rhino.Display.Text3d(tag, textLoc, 0);
doc.Objects.AddText(t, att);

}
}

//<Custom additional code>
private int ensureLayer(string lay){
int i = doc.Layers.Find(lay, true);
if(i < 0)
return doc.Layers.Add(lay, Color.Black);
else
return i;
}
//</Custom additional code>

}

Hope this helps...buon lavoro

Cheers

FF

Attachments:

Thank you very much for the fast answer!When i create a new layer,it has always index -1 before being added to doc.Layers right?Thanks again!

Ciao!

No it has -1 if it doesn't exist. The Find method returns the index of the layer if it already exists...if not -1 will return.

So if -1, create a new layer with that name and return the index of that new layer. Layers.Add(...,...) has as a return value the index of the created layer.

---sure, you're welcome

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service