This code works on a non-closed polyline:
Curve curve = objId.GetObject(OpenMode.ForRead) as Curve;
double ratio = 0.5; if (curve != null) for (int i = 0; i < curve.EndParam; i++) GeneralSegmentLabel.Create(objId, i + ratio, lineLabelStyleObjId, curveLabelStyleObjId);
However, it fails with the exception "The ratio should be in the range [0, 0]." on closed polylines. I can't think of any 'good' workarounds for this.
Well it looks like it's time to write a business case to get a Feature Request to fix this issue.
Well the first business case is Autodesk's reputation. If bugs continue to be called "Feature Requests" and require a business justification in order to get fixed, I'll continue to tell stories to who ever will listen that Autodesk doesn't stand behind their API and give examples exactly like this one. In addition time is of the essance. If it takes forever to get bugs fixed, and three plus months is too long, I'll continue to regail stories of API bugs found months and even years ago that haven't been fixed. Especially when I have to tell my customers, and Autodesk's, that I can't program something because Autodesk doesn't want to fix, or add to, the API. For number of users this will effect I'm sure Jeff, Tyronebk, and myself have a need to be able to add labels to closed features. I'm sure all of the routines will be utlized by nearly all users of the software since the products can be added to the App Store and I'm sure our Apps will sell like hotcakes.
Thank you all for bring up this issue, I've reported it to development for investigation and evalutation, thank you for your understanding.
It has been reported to development team, unfortunately I do not have the information when it will be addressed. Sorry about that.
😕 I didn't have this problem.
ObjectId id = new ObjectId(); id = GeneralSegmentLabel.Create(polyline2.ObjectId, 0.0, linelabelstyle, curvelabelstyle); GeneralSegmentLabel mylbl = transaction.GetObject(id, OpenMode.ForWrite) as GeneralSegmentLabel; mylbl.LabelLocation = new Point3d(pointd3.X, pointd3.Y, 0.0);
I defined the label location and seems to work fine.
....awe...wait nm... I saw your code and saw you're looking to grab a specific point. Haven't tried that myself.