Results 1 to 2 of 2

Thread: Joining Polylines in AutoCAD with C#

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2016-10
    Posts
    1
    Login to Give a bone
    0

    Default Joining Polylines in AutoCAD with C#

    I am trying to select all polylines of a specific layer and then join them with the normal autocad _JOIN command. For some reason i just cant get it to work.

    The selection set is properly found as i could loop through it and change the color of each (just did that for testing purpose)
    But for the join command it seems to only select the first polyline of the layer.
    What am i missing/doing wrong here?

    (i can also not use
    Code:
    ed.Command("_.PEDIT", "_Multiple", ss, "", "_Join", 0.0, "");
    instead as i have a mixture of 3d polylines and 2d polylines wildly floating around in the modelspace)

    Thanks in advance for any help!
    Code:
        [CommandMethod("JOINPOLY", 
                            CommandFlags.UsePickSet |
                            CommandFlags.Redraw |
                            CommandFlags.Modal)]
        public void SelectAllPolylineByLayer(string layerName)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
    
            using (Transaction tr = db.TransactionManager.StartTransaction())
            { 
                try
                {
                    // create the typevalue (criteria what should be selected)
                    TypedValue[] tvs = new TypedValue[] {
                                    new TypedValue(Convert.ToInt32(DxfCode.Operator), "<and"),
                                    new TypedValue(Convert.ToInt32(DxfCode.LayerName), layerName),
                                    new TypedValue(Convert.ToInt32(DxfCode.Operator), "<or"),
                                    new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE"),
                                    new TypedValue(Convert.ToInt32(DxfCode.Start), "LWPOLYLINE"),
                                    new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE2D"),
                                    new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE3d"),
                                    new TypedValue(Convert.ToInt32(DxfCode.Operator), "or>"),
                                    new TypedValue(Convert.ToInt32(DxfCode.Operator), "and>")
                    };
    
                    // create a selectionfilter out of our created typevalue
                    SelectionFilter oSf = new SelectionFilter(tvs);
                    PromptSelectionResult selRes = ed.SelectAll(oSf);
    
                    // if there is a problem with the promtselection stop here
                    if (selRes.Status != PromptStatus.OK)
                    {
                        ed.WriteMessage("\nError in getting the selectAll");
                        return;
                    }
    
                    SelectionSet ss = selRes.Value;
    
                    ed.Command("_JOIN", ss, "");
                    tr.Commit();                                       
                }
                //Catch the error and write the errormessage
                catch (System.Exception ex)
                {
                    ed.WriteMessage(Convert.ToString(ex));
                }
            }
        }
    Last edited by alexander.lisikow737242; 2016-10-20 at 09:07 AM.

  2. #2
    Member
    Join Date
    2016-10
    Posts
    5
    Login to Give a bone
    0

    Default Re: Joining Polylines in AutoCAD with C#

    Are you sure that its possible to join 3d-polylines with the command pedit?
    I mean not: Only 2d-polylines with the same z-level, connected by one point with identical coordinate.

Similar Threads

  1. joining polylines with matching object data
    By hortonjames in forum AutoCAD Map 3D - General
    Replies: 5
    Last Post: 2010-04-15, 06:10 PM
  2. joining 3d polylines
    By Davied2 in forum AutoCAD 3D (2006 or below)
    Replies: 6
    Last Post: 2009-10-15, 09:31 PM
  3. Joining polylines
    By tom.scott in forum AutoCAD General
    Replies: 8
    Last Post: 2009-10-01, 05:08 PM
  4. Replies: 14
    Last Post: 2006-06-13, 05:03 PM
  5. Joining non touching Polylines
    By rossi in forum AutoCAD General
    Replies: 7
    Last Post: 2005-06-06, 08:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •