Author Topic: Merge/Join Line and Arc Segments into a Poyline  (Read 2758 times)

0 Members and 1 Guest are viewing this topic.

Xander

  • Guest
Merge/Join Line and Arc Segments into a Poyline
« on: October 16, 2009, 12:38:37 AM »
I've recently come across a rather annoying problem.  I've developed some source for drawing steel/concrete members and sections through a series of dialogs but have drawn the members as 2D line segments.  I'm attempting to convert these segments (after drawing) into PolyLines.

At the moment my source retrieves and tracks all Object IDs, but I cannot seem to merge them.  I've even attempted to send  a string, with no luck...

Any ideas?

Bryco

  • Water Moccasin
  • Posts: 1850
Re: Merge/Join Line and Arc Segments into a Poyline
« Reply #1 on: October 16, 2009, 09:35:03 AM »
If the list of objectids is sequential in that each line starts at the previous line's endpont then you can make a new polyline and add the endpoint of each line by .AddVertexAt, delete the line then continue.

fixo

  • Guest
Re: Merge/Join Line and Arc Segments into a Poyline
« Reply #2 on: October 16, 2009, 12:24:49 PM »
I've recently come across a rather annoying problem.  I've developed some source for drawing steel/concrete members and sections through a series of dialogs but have drawn the members as 2D line segments.  I'm attempting to convert these segments (after drawing) into PolyLines.

At the moment my source retrieves and tracks all Object IDs, but I cannot seem to merge them.  I've even attempted to send  a string, with no luck...

Any ideas?

You can add Tony Tanzillo's class into your project
from here:

http://www.caddzone.com/CommandLine.cs

Then test the following code:
Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using System.Collections;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace JoinArcsNLines
{
    public class Class1
    {
        [CommandMethod("jn")]
        public static void Test()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                PromptSelectionOptions pso = new PromptSelectionOptions();
                pso.MessageForRemoval = "\nNothing selected";
                pso.MessageForAdding = "\nSelect lines and/or arcs only:";
                PromptSelectionResult pres = ed.GetSelection(pso);
                if (pres.Status != PromptStatus.OK) return;
                SelectionSet ss = pres.Value;
                int res = CaddZone.ApplicationServices.CommandLine.Command
                    ("._PEDIT", "_m", "_p", "", "_y", "_join", "", "");
                ed.Regen();
                tr.Commit();
            }
        }
}

~'J'~

Xander

  • Guest
Re: Merge/Join Line and Arc Segments into a Poyline
« Reply #3 on: October 18, 2009, 07:25:59 PM »
Hmm,  I'm getting the feeling I'm going to have to just draw a polyline from Scratch without the lines.  I was looking at avoiding use of existing commands in case the user changes their alias (which I do).  Thanks for the help!

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: Merge/Join Line and Arc Segments into a Poyline
« Reply #4 on: October 19, 2009, 04:33:47 PM »
I'll keep that commandline class handy, but there is no reason i see to use it.
I draw plines all the time from line and arc data.
I guess you will have to go through the part of matching up endpoints to other enpoints, since you don't necessarily know the order of segments if just objectids.
I think the pline join in acad is just an interface to gather data to feed into a new entity, so you must do the same.
Here is my code for reference, but you will have to substitute various portions to your needs, because I use objects not provided here, but you can see whats going on.
Code: [Select]
public static bool DrawPl(this CE.Glist glist, string layer, int color, out object objectId)
    {
      objectId = null;
      //Add the pline object
      AcDb.Polyline pline = new Polyline();
      pline.Closed = false;
      //add verticies
      for (int i = 0; i < glist.Segments.Count; i++) {
        //Segments is an arraylist, so test for object type
        if (glist.Segments[i] is CE.Line) {
          CE.Line line = (CE.Line)glist.Segments[i];
          if (i == 0)
            pline.AddVertexAt(0, new Point2d(line.StartPt.X, line.StartPt.Y), 0.0, 0.0, 0.0);
          pline.AddVertexAt(i + 1, new Point2d(line.EndPt.X, line.EndPt.Y), 0.0, 0.0, 0.0);
        }
        else {
          CE.Arc arc = (CE.Arc)glist.Segments[i];
          CE.Point stpt;
          CE.Point endpt;
          if (arc.Direction == "CCW") {
            stpt = CEG.Polar(arc.CenPt, arc.StartAng, arc.Radius);
            endpt = CEG.Polar(arc.CenPt, arc.EndAng, arc.Radius);
          }
          else {
            stpt = CEG.Polar(arc.CenPt, arc.EndAng, arc.Radius);
            endpt = CEG.Polar(arc.CenPt, arc.StartAng, arc.Radius);
          }
          double bulge;
          if (arc.Delta <= 0.0000000001) {
            bulge = 0.0;
          }
          else {
            bulge = (arc.Radius - (SM.Cos(arc.Delta / 2.0) * arc.Radius)) / (CEG.Distance(stpt, endpt) / 2.0);
            if (arc.Direction == "CW") bulge = bulge * -1.0;
          }
          if (i == 0)
            pline.AddVertexAt(0, new Point2d(stpt.X, stpt.Y), 0.0, 0.0, 0.0);
          pline.AddVertexAt(i + 1, new Point2d(endpt.X, endpt.Y), 0.0, 0.0, 0.0);
          pline.SetBulgeAt(i, bulge);
        }
      }
      //set color
      pline.Color = AcCo.Color.FromColorIndex(AcCo.ColorMethod.ByAci, Convert.ToInt16(color));
      ObjectId id;
      bool ret =  HADR.AddEntityToDB(pline, layer, out id);
      objectId = (object)id;
      return ret;
    }
James Maeding