lisp to export polyline lengths to excel

lisp to export polyline lengths to excel

Anonymous
Not applicable
5,251 Views
8 Replies
Message 1 of 9

lisp to export polyline lengths to excel

Anonymous
Not applicable

I need a lisp that will export polyline lengths in my selected order to excel... i have a lisp that will export lenghts to a csv, but re-orders them based on the x-cord, i would like to list them based on how i select them. is this possible? 

Thank you.

 

0 Likes
5,252 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

this lisp i found on these forums, but its exporting based on the x-coordinate.

thanks for any help.

 

(defun c:TryMe (/ s i e l fn)
  (if (and(setq s (ssget '((0 . "LWPOLYLINE"))))
	  (setq fn (getfiled "Create Output File" "" "csv" 1)))
    (progn
      (setq s (_SortSSByXValue s))
      (setq i (sslength s))
      (while (setq e(ssname s (setq i (1- i))))
	(setq l (cons (vla-get-length (vlax-ename->vla-object e)) l))
	(ssdel e s)
      )
    )
  )
  (setq l (list (cd:CON_All2Str l nil)))
  (if (LM:WriteCSV l fn)
                (startapp "explorer" fn)
            )
  (princ)
)


; =========================================================================================== ;
;;www.CAD.PL
;;part of CADPL-Pack-v1.lsp

; Zmiana elementow listy na lancuchy tekstowe / Convert list elements onto strings            ;
;  Lst  [LIST]  - lista wejsciowa / input list                                                ;
;  Mode [T/nil] - nil = jak wynik z funkcji princ / as a result of the princ function         ;
;                 T   = jak wynik z funkcji prin1 / as a result of the prin1 function         ;
; ------------------------------------------------------------------------------------------- ;
; (cd:CON_All2Str '("A" "B" 1 3) nil) --> ("A" "B" "1" "3")                                   ;
; (cd:CON_All2Str '("A" "B" 1 3) T)   --> ("\"A\"" "\"B\"" "1" "3")                           ;
; =========================================================================================== ;
(defun cd:CON_All2Str (Lst Mode)
  (mapcar
    (function
      (lambda (%)
        (if Mode
          (vl-prin1-to-string %)
          (vl-princ-to-string %)
        )
      )
    )
    Lst
  )
)


  
;;sort SS by Xcoord
(defun _SortSSByXValue (ss / lst i e add)
  (if (eq (type ss) 'PICKSET)
    (progn
      (repeat (setq i (sslength ss))
        (setq lst (cons (cons (setq e (ssname ss (setq i (1- i))))
                              (cadr (assoc 10 (entget e)))
                        )
                        lst
                  )
        )
      )
      (setq add (ssadd))
      (foreach e (vl-sort lst (function (lambda (a b) (< (cdr a) (cdr b))))) (ssadd (car e) add))
      (if (> (sslength add) 0)
        add
      )
    )
  )
)

;; Write CSV  -  Lee Mac
;; Writes a matrix list of cell values to a CSV file.
;; lst - [lst] list of lists, sublist is row of cell values
;; csv - [str] filename of CSV file to write
;; Returns T if successful, else nil
 
(defun LM:writecsv ( lst csv / des sep )
    (if (setq des (open csv "w"))
        (progn
            (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))
            (foreach row lst (write-line (LM:lst->csv row sep) des))
            (close des)
            t
        )
    )
)
 
;; List -> CSV  -  Lee Mac
;; Concatenates a row of cell values to be written to a CSV file.
;; lst - [lst] list containing row of CSV cell values
;; sep - [str] CSV separator token
 
(defun LM:lst->csv ( lst sep )
    (if (cdr lst)
        (strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep))
        (LM:csv-addquotes (car lst) sep)
    )
)
 
(defun LM:csv-addquotes ( str sep / pos )
    (cond
        (   (wcmatch str (strcat "*[`" sep "\"]*"))
            (setq pos 0)    
            (while (setq pos (vl-string-position 34 str pos))
                (setq str (vl-string-subst "\"\"" "\"" str pos)
                      pos (+ pos 2)
                )
            )
            (strcat "\"" str "\"")
        )
        (   str   )
    )
)
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hello @Anonymous
You can try this:

http://www.lee-mac.com/polyinfo.html

 

 

 

Júnior Nogueira.

Por favor,  Aceitar como Solução se meu post te ajudar.

Please Accept as Solution if my post helps you.

0 Likes
Message 4 of 9

Anonymous
Not applicable

First of all I want to thanks for the coding.......

I want additional column after which can show length of Polyline.

 

Thanks in Advance...

0 Likes
Message 5 of 9

jtohill
Advocate
Advocate

you could just use the extraction tool and it will send what you want to exce


@Anonymous wrote:

First of all I want to thanks for the coding.......

I want additional column after which can show length of Polyline.

 

Thanks in Advance...



l or create table in acad

0 Likes
Message 6 of 9

msalazarGKDLH
Community Visitor
Community Visitor

I'm having a problem selecting more then one polyline when I run this.  It will only allow me to select one line but I would like to select multiple polylines to extract to either a table or excel.

0 Likes
Message 7 of 9

Sea-Haven
Mentor
Mentor

This request rates in the top ten most asked for help, it has so many responses and sucked me in too. Did you google its there just look.

0 Likes
Message 8 of 9

devitg
Advisor
Advisor

Hi @msalazarGKDLH  , did you try DATAEXTRACTION , ACAD command ??

0 Likes
Message 9 of 9

amis.electricals
Community Visitor
Community Visitor

its code

0 Likes