Extract/list line properties - urgent!

Discussion in 'AutoCAD' started by Andrew Thelwell, Oct 2, 2007.

  1. Hi,

    We've hit a pretty big problem with some in-house software we were
    using to parse DXF data. We therefore need to find a quick fix. This
    involves being able to list the StartX, EndX, StartY and EndY
    properties of a load of lines on a specific layer. We then need to
    output these as a CSV file, so we need to list like this:

    startX, endX, startY, endY
    startX, endX, startY, endY

    If necessary, we could just have this dumped to the text window and we
    could save it off using notepad. however, we've got to do this for
    quite a lot of different blocks, so it would be good if it could
    actually save the text file... I have no idea if this is possible
    though?

    So in summary, we need to list and output the startX, endX, startY and
    endY values for a number of lines. We need to do this across a number
    of blocks too.

    Any help would be greatly appreciated and would save me from going
    crazy with stress!!

    Many thanks in advance,

    AT
     
    Andrew Thelwell, Oct 2, 2007
    #1
  2. Here is a modified version of the cadalyst addlines code. This should do
    what you're after but it does not look inside blocks. I dont have time to
    write something up for blocks but to include lines from inside blocks you
    would need to write something that looks inside the block definition for the
    lines and then finds each instance of the block in the drawing and adds the
    x and y value of insertion point to the x and y values inside the block.

    (defun c:extractlines (/ ss1 count n1 n2 outfile start_x end_x start_y
    end_y)
    (graphscr)
    (setq filter_layer "strucad_01") ; Change this to the layer you want to
    output
    ;(prompt "\nSelect the Lines to be Added together:")
    ;(setq ss1 (ssget (list (cons 0 "line")))) ; Select lines Manually (does
    not filter by layer)
    (setq ss1 (ssget "X" (list (cons 0 "line")(cons 8 filter_layer)))) ;
    Automatically select ALL lines on ths specified layer
    (setq count (sslength ss1))
    (setq outfile (open "c:\\temp\\lines.txt" "w"))
    (while (/= count 0)
    (setq N1 (ssname ss1 0))
    (setq N2 (entget N1))
    (setq start_x (rtos (cadr (assoc 10 N2))))
    (setq end_x (rtos (caddr (assoc 10 N2))))
    (setq start_y (rtos (cadr (assoc 11 N2))))
    (setq end_y (rtos (caddr (assoc 11 N2))))
    (princ (strcat "\nLine: " start_x ", " end_x ", " start_y ", " end_y ))
    (write-line (strcat start_x ", " end_x ", " start_y ", " end_y ) outfile)
    (ssdel n1 ss1)
    (setq count (1- count))
    );end while
    (close outfile)
    (terpri)
    (princ)
    ); end program
     
    Michael Everson, Oct 9, 2007
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.