It seems that the Region class in .NET does not have the getAreaProp method.So I decide to P/Invoke it:
public class Class1
{
[SuppressUnmanagedCodeSecurity]
[DllImport(
"acdb17.dll",
CallingConvention = CallingConvention.ThisCall,
EntryPoint = "?getAreaProp@AcDbRegion@@UBE?AW4ErrorStatus@Acad@@ABVAcGePoint3d@@ABVAcGeVector3d@@1AAN2AAVAcGePoint2d@@QAN24QAVAcGeVector2d@@433@Z"
)]
private static extern void GetAreaProp(IntPtr region,
out Point3d origin,
out Vector3d xAxis,
out Vector3d yAxis,
out double perimeter,
out double area,
out Point2d centroid,
double[] momInertia,
out double prodInertia,
double[] prinMoments,
Vector2d[] prinAxes,
double[] radiiGyration,
out Point2d extentsLow,
out Point2d extentsHigh);
[CommandMethod("Test")]
public void Test()
{
Database db=HostApplicationServices.WorkingDatabase;
Document doc=Application.DocumentManager.MdiActiveDocument;
Editor ed=doc.Editor;
ObjectId id=ed.GetEntity("ent").ObjectId;
Point3d origin;
Vector3d xAxis;
Vector3d yAxis;
double perimeter;
double area;
Point2d centroid;
double[] momInertia=new double[2];
double prodInertia;
double[] prinMoments=new double[2];
Vector2d[] prinAxes=new Vector2d[2];
double[] radiiGyration=new double[2];
Point2d extentsLow;
Point2d extentsHigh;
using (Transaction trans=db.TransactionManager.StartTransaction())
{
DBObject region=trans.GetObject(id, OpenMode.ForRead);
GetAreaProp(region.UnmanagedObject, out origin,
out xAxis,
out yAxis,
out perimeter,
out area,
out centroid,
momInertia,
out prodInertia,
prinMoments,
prinAxes,
radiiGyration,
out extentsLow,
out extentsHigh);
trans.Commit();
}
ed.WriteMessage(area.ToString());
}
}
But the return values are always 0.