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 { }
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
And still not available in 2014.
Thanks Jeff...was hoping for progress since then lol
Hi area51visitor, Jeff,
Did you guys check this API -
LabelGroupSubEntity.SetReferenceTextTarget()
I thought this would help here.
Thanks,
I missed to add the link to API ref doc -
Thanks,
Thanks Partha I'll give it a shot 🙂
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 { } } }
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.
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!
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
Not sure I can grab the labelgroupsubentity without label group
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
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.
oY ...Geez... thanks Jeff... for always clearing up the confusion (and providing solutions at the same time)... we'd be lost without ya
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.