autocad二次开发2
单个实体旋转
旋转对象使用变换矩阵的Rotation()函数,该函数要求输入用弧度表示的旋转角度、旋转轴和旋转基点。旋转轴用Vector3d对象表示,旋转基点用Point3d对象表示。旋转角度表示相对于当前位置将对象围绕基点旋转多远。
设立旋转轴
csharp
//设置旋转轴为z轴
Matrix3d curUCSMatrix = doc.Editor.CurrentUserCoordinateSystem;
CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d;
Vector3d axis = curUCS.Zaxis;
给定旋转角度
旋转角度为弧度制
csharp
double angle = 90.0;
double radian = angle * Math.PI / 180.0;
设立基点
实体绕基点旋转
csharp
Point3d basePoint = new Point3d(0, 0, 0);
旋转
csharp
entity.TransformBy(Matrix3d.Rotation(radian, axis, basePoint));
多对象集合旋转
创建集合
csharp
//建立曲线集合
ObjectIdCollection enCollect = new ObjectIdCollection();
enCollect.Add(entity.Id);
enCollect.Add(entity.Id);
enCollect.Add(entity.Id);
...
迭代旋转
csharp
for (int i = 0; i < enCollect.Count; i++)
{
using (Arc arc = trans.GetObject(enCollect[i], OpenMode.ForWrite) as Arc)
{
using (Arc arcr = arc.Clone() as Arc)
{
arcr.TransformBy(Matrix3d.Rotation(Math.PI, axis, basePoint));
btr.AppendEntity(arcr);
trans.AddNewlyCreatedDBObject(arcr, true);
}
}
}