Author Topic: send command multiple extrim  (Read 1206 times)

0 Members and 1 Guest are viewing this topic.

daboho

  • Newt
  • Posts: 40
send command multiple extrim
« on: November 13, 2021, 11:32:17 AM »
i want using extrim with sendcommand but if only single rectangle is succsess but if using multiple rectangle result not correct
i want xtrim all line,polyline,etc inside of rectangle/circle
Code: [Select]
[CommandMethod("xtrim")]
        public void multextrim()
        {
            var doc = CadApp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = CadApp.DocumentManager.MdiActiveDocument.Editor;
            var op = new PromptSelectionOptions();
            op.MessageForAdding = "\nselect closed object to trim :";
            var psr = ed.GetSelection(op);
            if (psr.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in psr.Value.GetObjectIds())
                {
                    //get center point of rectangle or circle
                    var cur = tr.GetObject(id, OpenMode.ForRead) as Curve;
                    var ext = new Extents3d();
                    ext = cur.GeometricExtents;
                    var center = new Point3d((ext.MinPoint.X + ext.MaxPoint.X) / 2, (ext.MinPoint.Y + ext.MaxPoint.Y) / 2, (ext.MinPoint.Z + ext.MaxPoint.Z) / 2).TransformBy(ed.CurrentUserCoordinateSystem);
                    string x = ((ext.MinPoint.X + ext.MaxPoint.X) / 2).ToString().Replace(',', '.');
                    string y = ((ext.MinPoint.Y + ext.MaxPoint.Y) / 2).ToString().Replace(',', '.');
                    string z = ((ext.MinPoint.Z + ext.MaxPoint.Z) / 2).ToString().Replace(',', '.');
                    string pt = x + "," + y + "," + z;

                    // string pt = center.ToString().Trim('(', ')');
                    ed.WriteMessage($"\npoint center {pt}");
                    ed.SetImpliedSelection(new ObjectId[] { id });
                    var sget = ed.SelectImplied();
                    doc.SendStringToExecute($"_extrim\n{"_P"}\n{pt}\n", false, false, false);
                    ed.WriteMessage($"\npoint center {pt}");
                   

                }
            }
        }