Hi, How can i add labels to a Polyline by .NET?
For example i have a Polyline and i want to add labels to Polyline segments.
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
Thank you, many codes were in that topic.
I tested the first one, it put a text on the middle of each segment.
I am looking for a label instead of text.
does that topic have some thing for associate labels to polyline segments?
I can add general segment label to one line, arc or feature line. But i need to add label to all of segments of a polyline.
Actually i have some parcels, Alignment and feature line in my drawing. I have to label(tag) all their segments (image attached).
I used GeneralSegmentLabel.Create(object id , rate) for labeling. It works perfect for single segment only. my alignments include many lines and arcs.So i decided to label their base curve (for my drawing always are Polyline). but i don't know how to label a polyline in .NET. If you have better suggestion , guide me please.
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var entsel = ed.GetEntity("\nSelect a polyline: ");
if (entsel.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
var p = (Polyline)tr.GetObject(entsel.ObjectId, OpenMode.ForRead);
for (int i = (int)p.StartParam; i < p.EndParam; i++)
{
GeneralSegmentLabel.Create(p.ObjectId, i + 0.5);
}
tr.Commit();
}
THANK YOU SO MUCH, WORKS PERFECT :)))
EVERY ONE NEED A TEACHER LIKE YOU. :))
Thank you again for code you sent.
Can i used this method for a Basecurve of a civil 3d object?
for example i have an alignment. can i add labels(by your method) to alignment basecurve instead of an individual polyline?
Thank you
what about parcels and feature lines?
Do they have something similar methods like AlignmentCurveLabel.Create() and AlignmentTangentLabel.Create() for Labeling their segments?
I tried to use your method for alignment labeling.
but i got this error . Would you please help me to fix that? (error image attached)
filterlist = new TypedValue[1];
filterlist[0] = new TypedValue(0, "AECC_ALIGNMENT");
filter = new SelectionFilter(filterlist);
Promptentity = editor.SelectAll(filter);
sval = Promptentity.Value;
CivilDocument civildoc = CivilApplication.ActiveDocument;
ObjectId curvelblstid = civildoc.Styles.LabelStyles.GeneralCurveLabelStyles["ericsCurveStandard"];
ObjectId linelblstid = civildoc.Styles.LabelStyles.GeneralCurveLabelStyles["ericsLineStandard"];
if (sval != null)
{
foreach (ObjectId j in sval.GetObjectIds())
{
Autodesk.AutoCAD.DatabaseServices.DBObject dbobj = ts.GetObject(j, OpenMode.ForRead);
Autodesk.Civil.DatabaseServices.Entity prs = dbobj as Autodesk.Civil.DatabaseServices.Entity;
Polyline v = prs.BaseCurve as Polyline;
for (int i = 0; i < v.NumberOfVertices; i++)
{
SegmentType sgtn = v.GetSegmentType(i);
if (sgtn == SegmentType.Arc)
{
AlignmentArc item = v.GetArcSegment2dAt(i);
AlignmentCurveLabel.Create(item, curvelblstid);
}
if (sgtn == SegmentType.Line)
{
AlignmentLine item = v.GetLineSegment2dAt(i);
AlignmentTangentLabel.Create(item, linelblstid);
}
}
}
}
Try this:
[CommandMethod("TestCreateAlignLabels")]
public void createalignlabels()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var filterlist = new TypedValue[1];
filterlist[0] = new TypedValue(0, "AECC_ALIGNMENT");
var filter = new SelectionFilter(filterlist);
var Promptentity = doc.Editor.SelectAll(filter);
var sval = Promptentity.Value;
CivilDocument civildoc = CivilApplication.ActiveDocument;
ObjectId curvelblstid = civildoc.Styles.LabelStyles.GeneralCurveLabelStyles[0];
ObjectId linelblstid = civildoc.Styles.LabelStyles.GeneralLineLabelStyles[0];
if (sval != null)
{
using (Transaction ts = doc.Database.TransactionManager.StartTransaction())
{
foreach (ObjectId j in sval.GetObjectIds())
{
Alignment prs = (Alignment)ts.GetObject(j, OpenMode.ForRead);
foreach(AlignmentEntity seg in prs.Entities)
{
switch (seg.EntityType)
{
//this example does not take into account a spiral
case AlignmentEntityType.Arc:
var arcent = (AlignmentCurve)seg;
AlignmentCurveLabel.Create((AlignmentSubEntityArc)arcent[0], curvelblstid);
break;
case AlignmentEntityType.Line:
AlignmentTangentLabel.Create((AlignmentLine)seg, linelblstid);
break;
}
}
}
ts.Commit();
}
}
}
@mehdi-guida wrote:what about parcels and feature lines?
The GeneralSegmentLabel.Create() can be used with lines, arcs, polylines, and featurelines.
For parcels, I'm not seeing any way to add those labels.
Thank you SO MUCH.
I checked it up , i worked perfect.
what about parcels and feature lines?
Do they have something similar methods like AlignmentCurveLabel.Create() and AlignmentTangentLabel.Create() for Labeling their segments?
@mehdi-guida for the ParcelSegment labels, there is a method in the COM API to do this. Using the dynamic Type you could likely accomplish what you need. I don't have time right now to look further into it.
Hi, Three weeks ago you did me a favor and sent me this code.
It was really perfect.
I have question about this code.
Why it doesn't work for closed Polylines?
And how can i change it to works for closed Polylines?
Thank you
Can't find what you're looking for? Ask the community or share your knowledge.