- 积分
- 967
- 明经币
- 个
- 注册时间
- 2011-4-13
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
用了置顶里的方法
public void RotateEntity()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
// First we prompt for the entity to rotate
PromptEntityOptions peo =
new PromptEntityOptions(
"\nSelect entity to rotate: "
);
PromptEntityResult per =
ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
DBObject obj =
tr.GetObject(per.ObjectId, OpenMode.ForRead);
Entity ent = obj as Entity;
// Use the origin as the default center
Point3d rotationPoint = Point3d.Origin;
// If the entity is a polyline,
// assume it is rectangular and then
// set the rotation point as its center
Polyline pl = obj as Polyline;
if (pl != null)
{
LineSegment3d ps0 =
pl.GetLineSegmentAt(0);
LineSegment3d ps1 =
pl.GetLineSegmentAt(1);
Vector3d vec =
((ps0.EndPoint - ps0.StartPoint) / 2.0) +
((ps1.EndPoint - ps1.StartPoint) / 2.0);
rotationPoint = pl.StartPoint + vec;
}
// Get the base rotation angle stored with the
// entity, if there was one (default is 0.0)
double baseAngle = GetStoredRotation(obj);
if (ent != null)
{
// Get the current UCS, to pass to the Jig
Matrix3d ucs =
ed.CurrentUserCoordinateSystem;
// Create our jig object
RotateJig jig =
new RotateJig(
ent,
rotationPoint,
baseAngle,
ucs
);
PromptResult res = ed.Drag(jig);
if (res.Status == PromptStatus.OK)
{
// Get the overall rotation angle
// and dispose of the temp clone
double newAngle = jig.GetRotation();
jig.GetEntity().Dispose();
// Rotate the original entity
Matrix3d trans =
Matrix3d.Rotation(
newAngle - baseAngle,
ucs.CoordinateSystem3d.Zaxis,
rotationPoint);
ent.UpgradeOpen();
ent.TransformBy(trans);
// Store the new rotation as XData
SetStoredRotation(ent, newAngle);
}
}
tr.Commit();
}
}
}
但没有动态旋转效果,并且运行到ent.UpgradeOpen() 就退出了,我的实体是一个块图形 |
|