Hi,
Good day.
Im trying to find a solution to get the exact elevation of the profile but the data that I get is sometimes not the data that I wanted.
The reason is there are 2 or more profiles are listed and I cannot identify which is the correct data.
c3d_ProfIDCol = c3d_Alignment.GetProfileIds() <- Here 2 or more profiles are listed C3D_Profile = acTrans.GetObject(c3d_ProfIDCol.Item(0), OpenMode.ForRead) C3D_Profile.ElevationAt(RefPtStation)
What Im trying to get is the PGL elevation base on the provided PtStation. And to Identify the profile name.
Thanks and best regards,
Alexis
Solved! Go to Solution.
Solved by alexisgacia. Go to Solution.
Solved by Jeff_M. Go to Solution.
One way, use an extension method to get the desired Profile.
public static class AlignmentExtensions { public static ObjectId GetProfileIdByName(this Alignment align, string name) { var retval = ObjectId.Null; using (OpenCloseTransaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartOpenCloseTransaction()) { foreach (ObjectId id in align.GetProfileIds()) { var prof = (Profile)tr.GetObject(id, OpenMode.ForRead); if (prof.Name == name) { retval = id; break; } } } return retval; } }
Then you can be sure to get the correct Profile:
var profId = align.GetProfileIdByName("B31-VA"); if (profId == ObjectId.Null) return; var prof = (Profile)tr.GetObject(profId, OpenMode.ForRead);
Hi Jeff,
Thanks for the reply.
Is it possible to identify the "B31-VA" from the selected label?
What I'm trying to achieve is to extract the profile data from the selected label.
Thanks and best regards,
Alex
OK, Alex. This can be done, but is a bit odd how to get it. This is a snip out of larger code where I test the selected object as being various object types. This is where it's determined to be a StationOffset label.
if (ent.GetType() == typeof(CivDb.StationOffsetLabel)) { var lbl1 = (CivDb.StationOffsetLabel)ent; var txtcmpntIds = lbl1.GetTextComponentIds(); foreach(ObjectId txtId in txtcmpntIds) { var txt = tr.GetObject(txtId, OpenMode.ForRead) as CivDb.Styles.LabelStyleReferenceTextComponent; if (txt == null || txt.General.ReferenceTextObjectType != "Profile") continue; var profId = lbl1.GetReferenceTextTarget(txtId); var prof = (CivDb.Profile)tr.GetObject(profId, OpenMode.ForRead); var profName = prof.Name; } }
Hi Jeff,
What I did is similar to your code. The below code what I used to extract the elevation from profile.
I am new to dotnet and still trying to understand the process.
Private Function getPGLElevationAtPtStation(acTrans As Transaction, pStationLabel As DatabaseServices.Label, mRefPtStation As Double) As Double Dim obj As Object Dim oRefId As ObjectId Dim C3D_LSTC As DatabaseServices.Styles.LabelStyleTextComponent Dim C3D_LSRTC As DatabaseServices.Styles.LabelStyleReferenceTextComponent Dim C3D_Profile As DatabaseServices.Profile getPGLElevationAtPtStation = vbNull For Each obj In pStationLabel.GetTextComponentIds() obj = obj.GetObject(OpenMode.ForRead) If (obj.GetType.Name.ToString() = "LabelStyleTextComponent") Then C3D_LSTC = obj 'ListBox1.Items.Add(" Components Name : " & C3D_LSTC.Name.ToString()) ElseIf (obj.GetType.Name.ToString() = "LabelStyleReferenceTextComponent") Then C3D_LSRTC = obj 'Debug.Print(C3D_LSRTC.Name) If Not (C3D_LSRTC Is Nothing) Then oRefId = pStationLabel.GetReferenceTextTarget(C3D_LSRTC.ObjectId) If (oRefId.ToString = "(0)") Then Exit Function obj = acTrans.GetObject(oRefId, OpenMode.ForRead) If (TypeOf obj Is DatabaseServices.Profile) Then C3D_Profile = obj getPGLElevationAtPtStation = C3D_Profile.ElevationAt(mRefPtStation).ToString() End If End If End If Next End Function
Thank you for your support. Its a huge help again.
Can't find what you're looking for? Ask the community or share your knowledge.