- 积分
- 577
- 明经币
- 个
- 注册时间
- 2012-3-15
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 白糖 于 2012-9-21 00:21 编辑
交互方式新建一个UCS,指定原点,指定Y轴,旋转90°为X轴
- [CommandMethod("newUCS")]
- public static void NewUCS()
- {
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
-
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- UcsTable ut = trans.GetObject(db.UcsTableId,OpenMode.ForRead) as UcsTable;
- UcsTableRecord utr;
- if (ut.Has("New_UCS") == false)
- {
- utr = new UcsTableRecord();
- utr.Name = "New_UCS";
- utr.UpgradeOpen();
- ut.Add(utr);
- trans.AddNewlyCreatedDBObject(utr,true);
- }else
- {
- utr = trans.GetObject(ut["New_UCS"],OpenMode.ForWrite) as UcsTableRecord;
- }
- //指定原点
- PromptPointOptions pPtOpts = new PromptPointOptions("\n指定原点");
- PromptPointResult pPtRes = ed.GetPoint(pPtOpts);
- if (pPtRes.Status == PromptStatus.OK)
- {
- utr.Origin = pPtRes.Value;
- }
-
- //指定Y轴
- pPtOpts = new PromptPointOptions("指定Y轴方向");
- pPtRes = ed.GetPoint(pPtOpts);
- if (pPtRes.Status == PromptStatus.OK)
- {
- Vector3d vec = pPtRes.Value - utr.Origin;
- utr.YAxis = vec.GetNormal();
- }
-
- //Y轴旋转90°为X轴
- utr.XAxis = utr.YAxis.RotateBy(Math.PI/2,Vector3d.ZAxis);
-
- Matrix3d mt = Matrix3d.AlignCoordinateSystem(Point3d.Origin,Vector3d.XAxis,Vector3d.YAxis,Vector3d.ZAxis,utr.Origin,utr.XAxis,utr.YAxis,Vector3d.ZAxis);
- ed.CurrentUserCoordinateSystem = mt;
- trans.Commit();
- }
- }
|
|