- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("CreateOrdinateDimension","cdom", CommandFlags.Modal | CommandFlags.UsePickSet)]
public static void testOrdinateDimension()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
ObjectId id = ObjectId.Null;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
PromptPointOptions ppo = new PromptPointOptions("\n >> Select point for ordinate dimension >>");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
double gap = db.Dimtxt * 2;
Point3d pt = ppr.Value;
Point3d tpt = new Point3d(pt.X, pt.Y + gap, pt.Z);
Matrix3d mx = ed.CurrentUserCoordinateSystem.Inverse();
Vector3d mXPrev = Vector3d.XAxis;
// build custom dimension text
string dstr = string.Format("X = {0:f3}\\PY = {1:f3}", pt.X, pt.Y);// set precision to 3 decimals {:f3}
OrdinateDimension odim = new OrdinateDimension(false, pt, tpt, dstr, db.Dimstyle);
double ohrot = odim.HorizontalRotation;
// get the old Xaxis and transform it to current plane
Matrix3d mMat = Matrix3d.PlaneToWorld(odim.Normal); //ECS
mXPrev.TransformBy(mMat); //get the ECS xaxis in the world coordinates
mXPrev.TransformBy(mx); //transform current xaxis to plane defined by mx
// transform the dimension entity by the given transformation matrix
odim.TransformBy(mx);
// get the xAxis after transformation of the dimension entity
mMat= Matrix3d.WorldToPlane(odim.Normal);
// transform the old axis to the current ECS.
mXPrev.TransformBy(mMat);
// get the angle of the old xaxis with respect to the current xaxis
double newhrot = - Math.Atan2(mXPrev.X, mXPrev.Y);
odim.HorizontalRotation = ohrot + newhrot;
postToModelSpace(odim);
tr.AddNewlyCreatedDBObject(odim, true);
tr.Commit();
}
}
static void postToModelSpace(Entity ent)
{
BlockTableRecord btr;
Database db = HostApplicationServices.WorkingDatabase;
btr = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(ent);
} |
|