- 积分
- 9376
- 明经币
- 个
- 注册时间
- 2021-11-26
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 d1742647821 于 2023-2-9 18:20 编辑
画圆Jig示例,包括2点画圆和3点画圆
帮助大家学习使用IFox
- public static class TestClass
- {
- [CommandMethod(nameof(DrawCircle))]
- public static void DrawCircle()
- {
- var ppo1=new PromptPointOptions("\n指定圆的圆心或") { AllowNone= true };
- ppo1.Keywords.Add("3P", "3P", "三点(3P)");
- ppo1.Keywords.Add("2P", "2P", "两点(2P)");
- var ed = Env.Editor;
- var r1 = ed.GetPoint(ppo1);
- if (r1.Status == PromptStatus.Keyword)
- {
- switch (r1.StringResult)
- {
- case "3P":
- DrawCircle3P();
- return;
- case "2P":
- DrawCircle2P();
- return;
- }
- }
- else if (r1.Status!=PromptStatus.OK)
- return;
- var pt1 = r1.Value.Ucs2Wcs();
- var circle = new Circle(pt1,Vector3d.ZAxis, 1);
- circle.SetDatabaseDefaults();
- bool isRaidus = true;
- using var jig = new JigEx((mpw, _) =>
- {
- var dist = pt1.DistanceTo(new Point3d(mpw.X, mpw.Y, pt1.Z));
- if (dist > 0)
- circle.Radius = isRaidus? dist:dist*0.5;
- });
- jig.DatabaseEntityDraw(wd=>wd.Geometry.Draw(circle));
- var jppo= jig.SetOptions(pt1,msg:"\n指定圆的半径或");
- jppo.Keywords.Add("D","D","直径(D)");
- while (true)
- {
- var r2 = ed.Drag(jig);
- if (r2.Status == PromptStatus.Keyword&&r2.StringResult.ToUpper()=="D")
- {
- isRaidus = false;
- circle.Radius*=0.5;
- jppo.Keywords.Clear();
- jppo.Message = "\n指定圆的直径";
- continue;
- }
- if (r2.Status == PromptStatus.OK)
- {
- using var tr = new DBTrans();
- tr.CurrentSpace.AddEntity(circle);
- }
- return;
- }
- }
- private static void DrawCircle3P()
- {
- var ed = Env.Editor;
- var r1 = ed.GetPoint("\n指定圆上的第一个点");
- if(r1.Status!=PromptStatus.OK)
- return;
- var pt1 = r1.Value.Ucs2Wcs();
- var r2 = ed.GetPoint("\n指定圆上的第二个点");
- if(r2.Status!=PromptStatus.OK)
- return;
- var pt2=r2.Value.Ucs2Wcs().SetZ(pt1.Z);
- if(pt1==pt2)
- return;
- var circle = new Circle();
- var right=false;
- var angle = pt1.GetAngle(pt2)%Math.PI;
- using var jig = new JigEx((mpw, _) =>
- {
- var pt3 = mpw.SetZ(pt1.Z);
- if(pt3==pt1||pt3==pt2 || Math.Abs(angle - pt1.GetAngle(pt3) % Math.PI) < 1e-6)
- {
- right = false;
- return;
- }
- var cr3d = new CircularArc3d(pt1, pt2, pt3);
- circle.Radius=cr3d.Radius;
- circle.Center=cr3d.Center;
- circle.Normal=cr3d.Normal;
- right=true;
- });
- jig.DatabaseEntityDraw(wd =>
- {
- if (right)
- wd.Geometry.Draw(circle);
- });
- var jppo= jig.SetOptions("\n指定圆上的第三个点");
- jppo.Keywords.Clear();
- var r3 = ed.Drag(jig);
- if(r3.Status!=PromptStatus.OK||!right)
- return;
- using var tr = new DBTrans();
- tr.CurrentSpace.AddEntity(circle);
- }
- private static void DrawCircle2P()
- {
- var ed = Env.Editor;
- var r1 = Env.Editor.GetPoint("\n指定圆直径的第一个端点");
- if(r1.Status!=PromptStatus.OK)
- return;
- var pt1 = r1.Value.Ucs2Wcs();
- var circle = new Circle();
- circle.SetDatabaseDefaults();
- bool right = false;
- using var jig = new JigEx((mpw, _) =>
- {
- var pt2 = mpw.SetZ(pt1.Z);
- if(pt1==pt2)
- {
- right = false;
- return;
- }
- circle.Center = pt1.GetMidPointTo(pt2);
- circle.Diameter = pt1.DistanceTo(pt2);
- right=true;
- });
- jig.DatabaseEntityDraw(wd => wd.Geometry.Draw(circle));
- jig.SetOptions(pt1, CursorType.Crosshair, "指定圆直径的第二个端点");
- var r2=ed.Drag(jig);
- if(r2.Status!=PromptStatus.OK||!right)
- return;
- using var tr = new DBTrans();
- tr.CurrentSpace.AddEntity(circle);
- }
- private static Point3d SetZ(this Point3d pt, double z=0) => new (pt.X, pt.Y, z);
- }
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
评分
-
查看全部评分
|