Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to Set the Reference for Reference Text c#

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
brianchapmandesign
955 Views, 20 Replies

Trying to Set the Reference for Reference Text c#

Can't seem to find where to set the actual reference for a reference text... I've drilled down to the specific component but don't see any options

Anyone know how to do this?

 

                                        foreach (ObjectId parts in mycomponents)
                                        {
                                            try
                                            {
                                                LabelStyleComponent mytext = tr.GetObject(parts, OpenMode.ForWrite) as LabelStyleComponent;
                                                 if (mytext.GetType().ToString() == "Autodesk.Civil.DatabaseServices.Styles.LabelStyleReferenceTextComponent")
                                                {
                                                    LabelStyleReferenceTextComponent fnltext = mytext as LabelStyleReferenceTextComponent;
                                                    
                                                    
                                                }

                                            }
                                            catch
                                            {
                                            }

 


"Very funny, Scotty. Now beam down my clothes.
20 REPLIES 20
Message 2 of 21
Jeff_M
in reply to: brianchapmandesign

Message 3 of 21
brianchapmandesign
in reply to: Jeff_M

Thanks Jeff...was hoping for progress since then lol


"Very funny, Scotty. Now beam down my clothes.
Message 4 of 21
Anonymous
in reply to: brianchapmandesign

Hi area51visitor, Jeff,

 

Did you guys check this API -

 

LabelGroupSubEntity.SetReferenceTextTarget()

 

I thought this would help here.

 

Thanks,

 

Message 5 of 21
Anonymous
in reply to: Anonymous

Message 6 of 21
brianchapmandesign
in reply to: Anonymous

Thanks Partha I'll give it a shot 🙂


"Very funny, Scotty. Now beam down my clothes.
Message 7 of 21
brianchapmandesign
in reply to: Anonymous

Appears I'm doing something wrong below in the last part for setting the reference... for some reason it's not doing it.... anyone care to school me? I can set the referene manually to my alignment, but not this way.

 

                                    ObjectId lblId = GeneralSegmentLabel.Create(pselect.ObjectId, 0.00001, linelabelstyle, curvelabelstyle);

                                    using (Transaction tr = database.TransactionManager.StartTransaction())
                                    {
                                        GeneralSegmentLabel style = lblId.GetObject(OpenMode.ForRead) as GeneralSegmentLabel;
                                        ObjectIdCollection mycomponents = style.GetTextComponentIds() as ObjectIdCollection;
                                        foreach (ObjectId parts in mycomponents)
                                        {
                                            try
                                            {
                                                LabelStyleComponent mytext = tr.GetObject(parts, OpenMode.ForWrite) as LabelStyleComponent;
                                                 if (mytext.GetType().ToString() == "Autodesk.Civil.DatabaseServices.Styles.LabelStyleReferenceTextComponent")
                                                {
                                                    LabelStyleReferenceTextComponent fnltext = mytext as LabelStyleReferenceTextComponent;
                                                    if (fnltext.Name == "Station")
                                                    {
                                                        LabelGroup mylabelgroup = tr.GetObject(parts, OpenMode.ForWrite) as LabelGroup;
                                                        foreach (LabelGroupSubEntity stationsub in mylabelgroup.SubEntities)
                                                        {        
                                                                ObjectId stationidtext = fnltext.ObjectId;
                                                                stationsub.SetReferenceTextTarget(fnltext.ObjectId, alignmentId);
                                                        }
                                                        
                                                    }

                                                }

                                            }
                                            catch
                                            {
                                            }
                                        }
                                    }

 


"Very funny, Scotty. Now beam down my clothes.
Message 8 of 21
Jeff_M
in reply to: brianchapmandesign

Brian, this is only available in 2014 at this point.

 

Partha, thanks for correcting me on this. I obviously missed this when looking for new/updated things in the 2014 API.

 

Note that this method, along with  GetReferenceTextTarget(), is also applicable to a Label object.

Jeff_M, also a frequent Swamper
EESignature
Message 9 of 21

Thanks Jeff...using 2014 but not sure it works.

 

Partha... the docs say get the object ID of the civil 3d object I want to use. I'm assuming using my alignment object ID would be correct in this circumstance right?  If that's the case can you see a reason why my code above isn't working?  I tried commiting the transaction as well just to see but still no change in the reference.

 

Thanks!


"Very funny, Scotty. Now beam down my clothes.
Message 10 of 21
Jeff_M
in reply to: brianchapmandesign

No time for testing right now, but the first thing I'd do is step through the code while running to see where it fails.... Once I get this rush job to the printer at 2 this afternoon I'll have a closer look at it.
Jeff_M, also a frequent Swamper
EESignature
Message 11 of 21
brianchapmandesign
in reply to: Jeff_M

Right... thanks bud... did the same thing, I step all the way successfully
through to the last part where it's trying to set the reference.
Appreciate it 🙂

"Very funny, Scotty. Now beam down my clothes.
Message 12 of 21

To be specific the part that's failing is here:

 

  LabelGroup mylabelgroup = tr.GetObject(parts, OpenMode.ForWrite) as LabelGroup;                                                       
                                                        foreach (LabelGroupSubEntity stationsub in mylabelgroup.SubEntities)
                                                        {
                                                                ObjectId stationidtext = fnltext.ObjectId;
                                                                stationsub.SetReferenceTextTarget(fnltext.ObjectId, alignmentId);
                                                                tr.Commit();
                                                        }

 

I'm not sure my LabelGroup is correct


"Very funny, Scotty. Now beam down my clothes.
Message 13 of 21
Jeff_M
in reply to: brianchapmandesign

If you have a label, you don't need/want a labelgroup....use the Label object
Jeff_M, also a frequent Swamper
EESignature
Message 14 of 21

Not sure I can grab the labelgroupsubentity without label group


"Very funny, Scotty. Now beam down my clothes.
Message 15 of 21
Jeff_M
in reply to: brianchapmandesign

If it is a label, you just use the Label.SetReferenceTextTarget() method.
Jeff_M, also a frequent Swamper
EESignature
Message 16 of 21
brianchapmandesign
in reply to: Jeff_M

Thanks Jeff... but I'm trying to set the specific reference for two difference reference text in a label.  The references are different for each, which is why I think I need to use the group, then get the entity from that group as Partha recommended.. not sure... I'll need to beat my head against the desk a little more before it clicks


"Very funny, Scotty. Now beam down my clothes.
Message 17 of 21
Jeff_M
in reply to: brianchapmandesign

Brian,

The LabelGroup is used when you have a number of labels that are grouped together, such as the AlignmentLabels. A GeneralSegmentLabel is not a group.

 

You should be able to get what you need from this:

        [CommandMethod("CreateRefLabel")]
        public void editrefobj()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database database = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityOptions opts = new PromptEntityOptions("\nSelect a line:");
            PromptEntityResult pselect = ed.GetEntity(opts);
            if (pselect.Status != PromptStatus.OK)
                return;
            CivilDocument civdoc = CivilApplication.ActiveDocument;
            ObjectId linelabelstyle = civdoc.Styles.LabelStyles.GeneralLineLabelStyles[0];
            ObjectId curvelabelstyle = civdoc.Styles.LabelStyles.GeneralCurveLabelStyles[0];
            ObjectId alignmentId = civdoc.GetAlignmentIds()[0];
            ObjectId lblId = GeneralSegmentLabel.Create(pselect.ObjectId, 0.00001, linelabelstyle, curvelabelstyle);

            using (Transaction tr = database.TransactionManager.StartTransaction())
            {
                GeneralSegmentLabel label = lblId.GetObject(OpenMode.ForRead) as GeneralSegmentLabel;
                ObjectIdCollection mycomponents = label.GetTextComponentIds() as ObjectIdCollection;
                foreach (ObjectId parts in mycomponents)
                {
                    LabelStyleReferenceTextComponent fnltext = tr.GetObject(parts, OpenMode.ForRead) as LabelStyleReferenceTextComponent;
                    if (fnltext == null)
                        continue;
                    if (fnltext.Name == "Station")
                    {
                        label.UpgradeOpen();
                        label.SetReferenceTextTarget(fnltext.ObjectId, alignmentId);
                        label.DowngradeOpen();
                    }
                }
                tr.Commit();
            }
        }

 This works correctly.

Jeff_M, also a frequent Swamper
EESignature
Message 18 of 21
Jeff_M
in reply to: Jeff_M

And if you also have a component for "Offset", you just need to change one line of code:

 

if (fnltext.Name == "Station" || fnltext.Name == "Offset")

 and they both will get updated.

Jeff_M, also a frequent Swamper
EESignature
Message 19 of 21
brianchapmandesign
in reply to: Jeff_M

oY ...Geez... thanks Jeff... for always clearing up the confusion (and providing solutions at the same time)... we'd be lost without ya


"Very funny, Scotty. Now beam down my clothes.
Message 20 of 21
Jeff_M
in reply to: brianchapmandesign

Glad to help, Brian! One thing I should note which I caught after posting the code, since we are creating the label with a known style that we know we are going to be setting the ReferenceId, I would just Open the label for Write and remove the UpgradeOpen and DowngradeOpen calls.

Jeff_M, also a frequent Swamper
EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report