In this
particular example we will see how to access Civil 3D Surface Spot Elevation
Child label style. Suppose there is a Surface Spot Elevation Child label style
named "Foot Meter_Child" in a Civil 3D DWG file and we try to use the
following VB.NET code snippet to find out the number of Spot Elevation label
style in the same DWG file, child label styles won't be shown or counted as
shown in the screenshot below –
Dim surfaceSpotElevnLblStyle As LabelStyleCollection = civilDoc.Styles.LabelStyles.SurfaceLabelStyles.SpotElevationLabelStyles
MsgBox("This DWG File has : " + surfaceSpotElevnLblStyle.Count.ToString + " Surface Spot Elevn Label Styles !")
Above code
snippet shows the count of 'Spot Elevation' labels as two omitting the child label
style. So how do we access Child
Object Style using .NET API ?
We can access
child label style from the parent label style's ObjectId using [index]. Here is
the relevant VB.NET code snippet –
Try
Dim surfaceSpotElevnLblStyle As LabelStyleCollection = civilDoc.Styles.LabelStyles.SurfaceLabelStyles.SpotElevationLabelStyles
'MsgBox("This DWG File has : " + surfaceSpotElevnLblStyle.Count.ToString + " Surface Spot Elevn Label Styles !")
Dim surfaceLblStyleId As ObjectId = Nothing
Dim osurfaceElevnLabelStyle As LabelStyle = Nothing
For Each surfaceLblStyleId In surfaceSpotElevnLblStyle
osurfaceElevnLabelStyle = trans.GetObject(surfaceLblStyleId, OpenMode.ForRead)
MsgBox("Style Name : " + osurfaceElevnLabelStyle.Name.ToString + " " + "Children Style Count : " + osurfaceElevnLabelStyle.ChildrenCount.ToString)
If (osurfaceElevnLabelStyle.ChildrenCount >0) then
Dim childLblStyleId As ObjectId = osurfaceElevnLabelStyle(0)
Dim childLblStyle As LabelStyle = trans.GetObject(childLblStyleId, OpenMode.ForRead)
MsgBox("Child Style Name :" + childLblStyle.Name.ToString)
End If
Next
trans.Commit()
Catch ex As Exception
ed.WriteMessage("Exception Message is : " + ex.Message.ToString())
Exit Sub
End Try
Hope this is
useful to you!



Leave a Reply