C# 旋转函数的奇怪行为

Odd behavior from C# rotating function

我正在尝试以编程方式将此处显示的 AutoCAD 中的紫色块旋转 90 度,使其与橙色块对齐。

紫色方块的基点是左下角。使用 AutoCAD 的内置旋转功能可以得到我想要的结果:

但是当我尝试使用此函数以编程方式旋转它时

public static BlockReference RotateBlockWithAttributes(ObjectId passedIdOfBlockToRotate)
{
    Transaction tr = _database.TransactionManager.StartTransaction();
    DocumentLock docLock = _activeDocument.LockDocument();

    using (tr)
    using (docLock)
    {
        BlockReference blockToRotate = tr.GetObject(passedIdOfBlockToRotate, OpenMode.ForWrite) as BlockReference;
        blockToRotate.TransformBy(Matrix3d.Rotation(Math.PI / 2, blockToRotate.Normal, blockToRotate.Position));
        tr.Commit();
        return blockToRotate;
    }
}

我得到这个结果

不知道为什么...

我认为您应该改用 BlockReference.Rotation 属性。

来自帮助文件:

Accesses the rotation value (in radians) of the block reference. The rotation value is relative to the X axis of a coordinate system that is parallel to the OCS of the block reference, but has its origin at the position point of the block reference. The rotation axis is the Z axis of this coordinate system with positive rotations going counterclockwise when looking down the Z axis towards the origin.