- [CommandMethod("DFX")]
- public void Test()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- int n;
- string ts = "\r请选择线条(圆弧、直线或者多义线):";
- PromptEntityOptions opt = new PromptEntityOptions(ts);
- //PromptEntityOptions opt = New PromptEntityOptions(ts);
- //opt.SetRejectMessage();
- //opt.SetRejectMessage(intCount & "只能线条");
- opt.SetRejectMessage("只能线条");
- opt.AddAllowedClass(typeof(Polyline), true);
- opt.AddAllowedClass(typeof(Arc), true);
- opt.AddAllowedClass(typeof(Line), true);
- PromptEntityResult res = ed.GetEntity(opt);
- if (res.Status != PromptStatus.OK)
- {
- ed.WriteMessage("\r用户自行退出!");
- }
- else
- {
- PromptIntegerOptions iop = new PromptIntegerOptions("指定等分段的数量:");
- iop.DefaultValue = 10;
- PromptIntegerResult irt = ed.GetInteger(iop);
- if (irt.Status != PromptStatus.OK || irt.Value < 2)
- {
- return;
- }
- else
- {
- n = irt.Value;
- }
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- Curve cv = (Curve)(trans.GetObject(res.ObjectId, OpenMode.ForWrite));
- double len = cv.GetDistanceAtParameter(cv.EndParam);
- int i;
- for (i = 0; i <= n; i++)
- {
- Point3d p = cv.GetPointAtDist(i * len / n);
- Vector3d kp = cv.GetFirstDerivative(cv.GetParameterAtDistance(i * len / n));
- double ka = kp.GetAngleTo(Vector3d.XAxis) - Math.PI / 2;
- AddText(p, "等分点" + i.ToString(), 3, ka, 1, 1);
- }
- trans.Commit();
- }
- }
- }
|