Author Topic: Command "_.TRIM"  (Read 71 times)

0 Members and 1 Guest are viewing this topic.

Pepe

  • Newt
  • Posts: 78
Command "_.TRIM"
« on: November 06, 2019, 09:56:42 AM »
Learning C#.NET for Autocad.

A simple exercise to deal with built-in commands of Autocad: trim a bunch of lines by a fence. I get an exemption at "ed.command("_.TRIM")", and I can't find anywhere what I'm doing wrong.
Any advices and ideas?

Code: [Select]
[CommandMethod("TST2")]
        public void Tst2()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            Line obj;

            PromptEntityOptions peo = new PromptEntityOptions("\nSelect edge: ");
            peo.SetRejectMessage("\nSelect a LINE for edge...");
            peo.AddAllowedClass(typeof(Line), true);
            PromptEntityResult per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                obj = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Line;
                obj.Highlight();
                tr.Commit();
            }

            // Prompt for the start point
            PromptPointOptions ppt = new PromptPointOptions("\nFirst point of the edge: ");
            PromptPointResult pep = doc.Editor.GetPoint(ppt);
            Point3d pini = pep.Value;
            if (pep.Status == PromptStatus.Cancel) return;

            // Prompt for the end point
            ppt.Message = "\nSecond point of the edge: ";
            ppt.UseBasePoint = true;
            ppt.BasePoint = pini;
            pep = doc.Editor.GetPoint(ppt);
            Point3d pfin = pep.Value;
            if (pep.Status == PromptStatus.Cancel) return;

            ed.Command("_.TRIM", obj, "_F", pini, pfin );

            obj.Unhighlight();

        }