获取实体的坐标以其UCS为基点

时间:2017-08-02 13:27:21

标签: c# .net vb.net autocad autocad-plugin

我正在尝试将UCS移动到特定点,然后获取实体的坐标,在这种情况下为圆形,基于我刚刚移动的UCS作为其基点。从代码获得的坐标结果不正确(X3.0,Y5.5,Z0),这是没有意义的。它们应该是(X2.5,Y0.0,Z0.0)。 我的代码运行后,我可以在AutoCad中手动检查坐标,这是正确的。不知道是什么问题。任何帮助将不胜感激。

    private static void UcsBaseCoords(Circle circle, Point3d newBasePoint)
    {
        var acDoc = Active.Document;

        CoordinateSystem3d coordSystem = new CoordinateSystem3d(newBasePoint, new Vector3d(0, -1, 0),new Vector3d(1, 0, 0));

        CoordinateSystem3d cosy = acDoc.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d;

        var ecs = Matrix3d.AlignCoordinateSystem(cosy.Origin, cosy.Xaxis, cosy.Yaxis, cosy.Zaxis, coordSystem.Origin, coordSystem.Xaxis, coordSystem.Yaxis, coordSystem.Zaxis);

        acDoc.Editor.CurrentUserCoordinateSystem = ecs;

        acDoc.Editor.UpdateTiledViewportsInDatabase();

        var coodrsBasedOnUcs = circle.Center.TransformBy(ecs);
        acDoc.Editor.WriteMessage(String.Format("X{0}, Y{1}, Z{2}", coodrsBasedOnUcs.X, coodrsBasedOnUcs.Y, coodrsBasedOnUcs.Z));
    }

在我运行程序之前,这是我的dwg。 enter image description here

这是在我的程序运行后它是正确的。我的UCS已被移动,如果我检查圆的坐标是正确的。(X2.5,Y0.0,Z0.0) enter image description here

1 个答案:

答案 0 :(得分:0)

相关问题