本帖最后由 d1742647821 于 2023-3-7 10:46 编辑
看标题没写语言要求,.net区来凑热闹,短短30行,需要使用ifox
- [CommandMethod(nameof(CS5))]
- public static void CS5()
- {
- var r1 = Env.Editor.GetEntity("\n选择对象");
- if (r1.Status != PromptStatus.OK)
- return;
- var r2 = Env.Editor.GetEntity("\n选择要替换的对象");
- if (r2.Status != PromptStatus.OK || r2.ObjectId == r1.ObjectId)
- return;
- using var tr = new DBTrans();
- var ent1 = (Entity)tr.GetObject(r1.ObjectId);
- var ent2= (Entity)tr.GetObject(r2.ObjectId);
- var pt1 = ent1.GeometricExtents.MidPoint();
- var pt2 = ent2.GeometricExtents.MidPoint();
- var ent3=(Entity)ent1.Clone();
- ent3.Move(pt1, pt2);
- tr.CurrentSpace.AddEntity(ent3);
- Env.Editor.Redraw(ent3);
- var pko = new PromptKeywordOptions("\n是否替换?<Y>");
- pko.Keywords.Add("Y", "Y", "是(Y)");
- pko.Keywords.Add("N", "N", "否(N)");
- var r3 = Env.Editor.GetKeywords(pko);
- if(r3.Status==PromptStatus.OK && r3.StringResult.ToUpper() == "Y")
- {
- ent2.ForWrite(e => e.Erase());
- }
- else
- {
- tr.Abort();
- }
- }
|