MicroStation line-string and shape elements contain an array of 3D points. Each point is a vertex of the line or shape.
The same structure represents Shape Elements (type 6), Curve Elements (type 11), and Conic Elements (type 13). Shapes differ from line strings in that shape elements always start and end at the same point. Curve and conic elements use the first and last vertices to establish the slope at the beginning and end.
DGN line elements, in contrast to line-string elements, have only two vertices: the start and end points.
LineStringHandler and ShapeHandlerThe MicroStation Python LineStringHandler provides many useful functions. Unfortunately, it does not provide those most basic properties: vertex count and vertex indexing (i.e. the [] operator).
Many DGN elements contain useful geometric information, and line-string and shape elements are no exception.
The element structure includes an array of 3D points (Python DPoint3d) and the vertex count.
In response to a question on the
Be Communities Programming Forum,
Robert Hook
and
Leonard Jones
suggested this solution …
def GetLineStringVertices(element_id: int, dgn_model):
''' Get the DPoint3d vertex array directly from line-string or shape element. '''
eeh = EditElementHandle(element_id, dgn_model)
# Get DGN raw element
element = eeh.GetElement ()
element_type = eeh.GetElementType ()
if element_type not in [ICurvePrimitive.eCURVE_PRIMITIVE_TYPE_LineString, ICurvePrimitive.eCURVE_PRIMITIVE_TYPE_Shape,]:
MessageCenter.StatusMessage = "Element not a linear string"
return
# Get vertex count from DGN element data
vertex_count = element.line_string_3d.numverts
print (f"Element Type: {element_type} - Total Vertices: {vertex_count}")
# Get vertices from DGN element data
for i in range (0, vertex_count):
print (f"[{i+1}] - X:{element.line_string_3d.vertice[i].x/uor},
Y:{element.line_string_3d.vertice[i].y/uor},
Z:{element.line_string_3d.vertice[i].z/uor}")
Post questions about MicroStation Python programming to the MicroStation Programming Forum.