Reputation: 4240
I'm trying to programmatically rotate the purple block in AutoCAD shown here by 90 degrees so that it lines up with the orange block.
The purple block's base point is the lower left hand corner. Using AutoCAD's built in rotate function gives me the result that I want shown here:
But when I try to rotate it programmatically with this function
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;
}
}
I get this result
And have no idea why...
Upvotes: 2
Views: 465
Reputation: 8594
I believe you should change the BlockReference.Rotation property instead.
From the help file:
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.
Upvotes: 1