- 积分
- 5155
- 明经币
- 个
- 注册时间
- 2003-1-15
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2009-6-30 18:13:00
|
显示全部楼层
大版主不在线,小二子顶一下。没处理UCS,也没进行仔细的调试。- using System;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.GraphicsInterface;
- using Autodesk.AutoCAD.Runtime;
- namespace CsMgd29
- {
- public class Class1 : DrawJig
- {
- // 声明多段线对象
- private Polyline ent;
- // 声明多段线的起点、终点
- private Point3d pt1, pt2;
- [CommandMethod("abc")]
- public void Testabc()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- // 普通的点交互操作.
- PromptPointOptions optPoint = new PromptPointOptions("\n请指定起点: ");
- PromptPointResult resPoint = ed.GetPoint(optPoint);
- if (resPoint.Status != PromptStatus.OK)
- return;
- pt1 = resPoint.Value;
- Point2d[] pt = new Point2d[2];
- pt[0] = new Point2d(0, 0);
- pt[1] = new Point2d(0, 0);
- Point2dCollection pts = new Point2dCollection(pt);
- ent = (Polyline)new Polyline();
- for (int i = 0; i <= 1; i++)
- ent.AddVertexAt(i, pts[i], 0, 0, 0);
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- // 开始拖拽.
- PromptResult resJig = ed.Drag(this);
- if (resJig.Status == PromptStatus.OK)
- {
- // 将对象加入到图形数据库中.
- btr.AppendEntity(ent);
- trans.AddNewlyCreatedDBObject(ent, true);
- trans.Commit();
- }
- }
- }
- // Sampler函数用于检测用户的输入.
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- // 定义一个点拖动交互类.
- JigPromptPointOptions optJigPoint = new JigPromptPointOptions("\n请指终点:");
- // 设置拖拽光标类型.
- optJigPoint.Cursor = CursorType.RotatedCrosshair;
- // 用AcquirePoint函数得到用户输入的点.
- PromptPointResult resJigPoint1 = prompts.AcquirePoint(optJigPoint);
- Point3d curPt = resJigPoint1.Value;
- short ORTHOMODE = (short)(Application.GetSystemVariable("ORTHOMODE"));
- if (ORTHOMODE == 1)
- {
- double dx = Math.Abs(curPt.X - pt1.X);
- double dy = Math.Abs(curPt.Y - pt1.Y);
- if (dx >= dy)
- {
- curPt = new Point3d(curPt.X, pt1.Y, curPt.Z);
- }
- else
- {
- curPt = new Point3d(pt1.X, curPt.Y, curPt.Z);
- }
- }
-
- if (curPt != pt2)
- {
- // 重新设置参数--------------------------------------------.
- Point2d p0 = new Point2d(pt1.X, pt1.Y);
- Point2d p1 = new Point2d(curPt[0], curPt[1]);
- ent.SetPointAt(0, p0);
- ent.SetPointAt(1, p1);
- ent.SetStartWidthAt(0, 30);
- ent.SetEndWidthAt(0, 30);
- ent.SetStartWidthAt(1, 30);
- ent.SetEndWidthAt(1, 30);
- pt2 = curPt;
- return SamplerStatus.OK;
- }
- else
- return SamplerStatus.NoChange;
- }
- // WorldDraw函数用于刷新屏幕上显示的图形.
- protected override bool WorldDraw(WorldDraw draw)
- {
- // 刷新画面.
- draw.Geometry.Draw(ent);
- return true;
- }
- }
- }
|
|