Code Red => .NET => Topic started by: Pepe on November 06, 2019, 09:56:42 AM

Title: Command "_.TRIM"
Post by: Pepe 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]
        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;

            // 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 );