新建UCS,帮忙看下哪里不对?
本帖最后由 白糖 于 2012-9-21 00:21 编辑交互方式新建一个UCS,指定原点,指定Y轴,旋转90°为X轴
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();
}
}
line 16 ,有个笔误
utr.UpgradeOpen();----》 ut.UpgradeOpen();
页:
[1]