.NET

Reply
Active Contributor
stardust1611
Posts: 40
Registered: ‎11-29-2008
Message 1 of 5 (158 Views)

How to use TRIM command with acedCmd

158 Views, 4 Replies
03-31-2014 11:41 AM

Hello. I'm trying to execute the TRIM command with acedCmd, but without success as of yet. Can someone tell me please what parameters do I need to pass to the command to make it work. This is what I do:

 

var rb = new ResultBuffer();
rb.Add(new TypedValue(5005, "_.trim"));
rb.Add(new TypedValue(5006, plineId));
rb.Add(new TypedValue(5005, ""));
rb.Add(new TypedValue(5006, h.ObjectId));
rb.Add(new TypedValue(5005, ""));
acedCmd(rb.UnmanagedObject);

 Do I need to pass a point rather than ObjectId for the object to be trimmed? When using TRIM manually, one needs to click on an object that is supposed to be trimmed. That point perhaps identifys the object, as well as the side that needs to be trimmed off.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 5 (144 Views)

Re: How to use TRIM command with acedCmd

03-31-2014 12:51 PM in reply to: stardust1611

May be I'm wrong but acedCmd does not support nanaged selection,

Try lisp-like command instead:

        //ads_queueexpr
        [DllImport("accore.dll", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "ads_queueexpr")]
        extern static private int ads_queueexpr(byte[] command);
        [CommandMethod("trimq")]
        public void testTrim()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;
            ObjectId plineId = ed.GetEntity("Select first object: ").ObjectId;
            ObjectId hId = ed.GetEntity("Select second object: ").ObjectId;
            string handles = "";
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                  Entity ent1 = tr.GetObject(plineId, OpenMode.ForWrite) as Entity;
                  string hdl=string.Format("(handent \"{0}\")",ent1.Handle.ToString());
                        handles= handles + hdl + " ";
                Entity ent2 = tr.GetObject(hId, OpenMode.ForWrite) as Entity;
                  hdl=string.Format("(handent \"{0}\")",ent2.Handle.ToString());
                  handles= handles + hdl + " ";
                
                    System.Text.UnicodeEncoding uEncode = new System.Text.UnicodeEncoding();
                    ads_queueexpr(uEncode.GetBytes("(COMMAND \"_.TRIM\" " + handles  +  "\"\"" +  "\"pause\"" + "\"\"" +  "\"\")"));
                tr.Commit();
    }
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
stardust1611
Posts: 40
Registered: ‎11-29-2008
Message 3 of 5 (133 Views)

Re: How to use TRIM command with acedCmd

03-31-2014 04:22 PM in reply to: Hallex

Hi Hallex, thank you for the reply. I'm actually selecting automatically entities that need to be trimmed off with ed.SelectCrossingPolygon(verts). I have a polyline as the main object, and would like to trim selected objects automatically against that polyline. What I don't know is how to pass those selected objects to acedCmd as a parameter.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 5 (118 Views)

Re: How to use TRIM command with acedCmd

03-31-2014 10:48 PM in reply to: stardust1611

Sorry I hate acedCMD way, still usung lisp-like command, see edited version

      [CommandMethod("trimq", CommandFlags.UsePickSet | CommandFlags.Redraw)]
        public void SelectTrimTest()
        {
            var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
           var id = ObjectId.Null;
            PromptSelectionOptions pso = new PromptSelectionOptions();
            pso.MessageForRemoval = "\nWrong object type, select Curves.";
            pso.MessageForAdding = "\nSelect All Curves, main one and that to be trimmed in or out,\npush Enter after trimmed ends is picked.";
            TypedValue[] filter = new TypedValue[] {
                    new TypedValue(0,"*LINE,CIRCLE,ARC,ELLIPSE")};
            Point3dCollection pts = new Point3dCollection();
            var sf = new SelectionFilter(filter);

            var res = ed.GetSelection(pso, sf);

            if (res.Status != PromptStatus.OK)
            {
                return;
            }
            SelectionSet sset = res.Value;
            string handles = string.Empty;
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                foreach (SelectedObject sobj in res.Value)
                {
                    id = sobj.ObjectId;
                    Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite) as Entity;
                    string hdl = string.Format("(handent \"{0}\")", ent.Handle.ToString());
                    handles = handles + hdl + " ";

                }
                System.Text.UnicodeEncoding uEncode = new System.Text.UnicodeEncoding();
                ads_queueexpr(uEncode.GetBytes("(COMMAND \"_.TRIM\" " + handles + "\"\"" + "\"pause\"" + "\"\"" + "\"\")"));
                tr.Commit();
            }
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
stardust1611
Posts: 40
Registered: ‎11-29-2008
Message 5 of 5 (111 Views)

Re: How to use TRIM command with acedCmd

03-31-2014 11:40 PM in reply to: Hallex

Thank you Hallex, this is useful, but it still doesn't tell me how to pass the second group of entities into the command, the entities that are supposed to be trimmed. Your example still expects the user to manually pick objects that need to be trimmed. I don't know how to pass objects programatically. Do I need to input points on the objects intead of object Ids?

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!