Lengths of multiple lines to excel

Lengths of multiple lines to excel

Anonymous
Not applicable
1,934 Views
3 Replies
Message 1 of 4

Lengths of multiple lines to excel

Anonymous
Not applicable

Hi guys.

 

I have a vertical line group and I need an autolisp to export line lengths to excel in order from left to right. 

0 Likes
1,935 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

I have found the solution, thanks anyway for anyone interested.

0 Likes
Message 3 of 4

krzysztof.psujek
Advocate
Advocate

Hi,

welcome on forum.

Try if this is what you wanted. It writes lengths to CSV format.

 

 

(defun c:TryMe (/ s i e l fn)
  (if (and(setq s (ssget '((0 . "LINE"))))
	  (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   )
    )
)
;;written by psujek.krzysztof@gmail.com

 

0 Likes
Message 4 of 4

MikeW44
Explorer
Explorer
what was your solution?
0 Likes