Unable to place general segment labels on closed feature lines

Unable to place general segment labels on closed feature lines

adamg23
Participant Participant
1,255 Views
5 Replies
Message 1 of 6

Unable to place general segment labels on closed feature lines

adamg23
Participant
Participant

I am trying to automate the creation of general segment labels for linetypes through the .Net Api. I have had success working with polylines, lines and alignment but am struggling when working with featurelines.

The specific issue is that I am unable to place a label on a closed featureline. The error occurs when I try to set the label.Ratio to a given parameter and reads "The ratio should be in the range [0, 0]." This occurs no matter what the actual parameter value I pass in is. I am noticing when running this code on open feature lines I am getting a featureline.StartParam of 0 and a featureline.EndParam of however many segments the line has, say 5. When working with a closed featureline I am seeing that the featureline.StartParam is 0 and the featureline.EndParam would be 5 for this example, but when calling featureline.GetParameterAtPoint(featureline.EndPoint) I am seeing the value returned as 0 which struck me as odd.

I have thought about trying to add a point a very small distance from the actual end point and breaking the featureline to allow it to run properly and then returning it to it's original closed state but that feels like it will introduce it's own issues and inaccuracies. Any insight or advice would be greatly appreciated, thank you!

0 Likes
Accepted solutions (1)
1,256 Views
5 Replies
Replies (5)
Message 2 of 6

Jeff_M
Consultant
Consultant
Accepted solution

@adamg23 what release of Civil 3D are you using? I recall this being an issue but was corrected in newer releases...2022+? This code works:

        [CommandMethod("TestCreateLabels")]
        public void createlabels()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var opts = new PromptEntityOptions("\nSelect a curve object to label: ");
            opts.SetRejectMessage("..not a Curve type object, try again.");
            opts.AddAllowedClass(typeof(Polyline), true);
            opts.AddAllowedClass(typeof(FeatureLine), true);
            opts.AddAllowedClass(typeof(Line), true);
            opts.AddAllowedClass(typeof(Arc), true);
            var entsel = ed.GetEntity(opts);
            if (entsel.Status != PromptStatus.OK)
                return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var p = (Curve)tr.GetObject(entsel.ObjectId, OpenMode.ForRead);
                if (p.GetType() == typeof(Line) || p.GetType() == typeof(Arc))
                {
                    GeneralSegmentLabel.Create(p.ObjectId, 0.5);
                }
                else
                {
                    var endp = p.EndParam;
                    if (p.Closed)
                        endp = p.EndParam - 1;
                    for (int i = (int)p.StartParam; i < endp; i++)
                    {
                        GeneralSegmentLabel.Create(p.ObjectId, i + 0.5);
                    }
                    if (p.Closed)
                    {
                        GeneralSegmentLabel.Create(p.ObjectId, endp + 0.5);
                    }
                }
                tr.Commit();
            }
        }
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 6

adamg23
Participant
Participant

I was running into this issue when testing in 2022 and previous versions. Trying this workflow in 2023 and 2024 it appears to be working as expected. I appreciate the quick and informative response!

0 Likes
Message 4 of 6

rgrainer
Collaborator
Collaborator

Hey @Jeff_M 
Is a feature line's open or closed state available through lisp?
Thanks

0 Likes
Message 5 of 6

Jeff_M
Consultant
Consultant

@rgrainer no, not without a .NET helper tool.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 6 of 6

rgrainer
Collaborator
Collaborator

Thanks. That's what I suspected

0 Likes