.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use TRIM command with acedCmd

4 REPLIES 4
Reply
Message 1 of 5
stardust1611
1179 Views, 4 Replies

How to use TRIM command with acedCmd

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.

Tags (1)
4 REPLIES 4
Message 2 of 5
Hallex
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
Message 3 of 5
stardust1611
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.

Message 4 of 5
Hallex
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
Message 5 of 5
stardust1611
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?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost