Python

Introduction

The CurveVector class is a great way to work with lines, curves and shapes independently of the restrictions of DGN elements.

MicroStation: CurveVector.WireCentroid

If you want to find the centroid of a DGN shape, convert it to a CurveVector and use CurveVector.WireCentroid to calculate the shape's perimeter and centroid. Given an ElementHandle (eh) you've obtained from somewhere …

from MSPyDgnPlatform import *
from MSPyMstnPlatform import *
from MSPyDgnView import *

curve = ICurvePathQuery.ElementToCurveVector(eh)
print (f"CurveVector type '{curve.GetBoundaryType()}' ID {eh.GetElementId()}")
# Calculate the centroid of the shape
# WireCentroid returns a tuple (bool, float, DPoint3d)
status, length, centroid = curve.WireCentroid ()
if status:
    # Use the centroid
     …

CurveVector.WireCentroid() return tuple

CurveVector.WireCentroid () is documented as returning a tuple, but the documentation doesn't tell us what is in that tuple. It contains three members: (bool, float, DPoint3d) …

As you should expect, the length and centroid components are expressed in the DGN model's units-of-resolution (UORs).


Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.