Lisp adjustment

Lisp adjustment

Anonymous
Not applicable
899 Views
2 Replies
Message 1 of 3

Lisp adjustment

Anonymous
Not applicable

Hi,

 

Here I have a lisp to calculate length of the polylines, could some one help me, here the problem is i am getting different length value. 

 

(defun c:TLlength ( / ss la rv i op)

(while (not ss)
(princ "\nPick the layer")
(setq ss (ssget)))

(initget "Length")
(setq rv "Length")

(setq la (cdr (assoc 8 (entget (ssname ss 0))))
ss (ssget "X" (list (cons 0 "*POLYLINE")
(cons 8 la)))
i (sslength ss)
op 0)

(princ(prompt (alert(strcat "\nTotal " rv
" of the polylines is"
" = " (rtos (cvunit i "inches" "metres") 2 2)
" meters in " (itoa (sslength ss)) "polylines\n"
(if (/= rv "Length")
(strcat (itoa op) " with open polylines") "")))))
(prin1))

 

Thanks,

Vijay

0 Likes
Accepted solutions (2)
900 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this code below. There is number of ways you could do that. And number of routines you can find on internet.

 

(defun c:TLlength ( / ss la rv i op ln)

  (while (not (setq en (car (entsel "\nPick the layer")))))
  (setq rv "Length")
  (setq la (cdr (assoc 8 (entget en)))
        ss (ssget "X" (list (cons 0 "*POLYLINE")
                            (cons 8 la)
                            (cons 410 (getvar 'CTAB)))) ; current tab (just a Model if it's current and not Layout)
        ln 0.
        op 0)
  
  (repeat (setq i (sslength ss))
    (setq en (ssname ss (setq i (1- i))))
    (command "_area" "_e" en)
    (setq ln (+ ln (getvar 'perimeter)))              ; get and count length
    (if (= 0 (logand (cdr (assoc 70 (entget en))) 1)) ; is a polyline opened?
      (setq op (1+ op))))

  (alert (strcat "\nTotal " rv
                 " of the polylines is"
                 " = " (rtos (cvunit ln "inch" "m") 2 2)
                 " meters in " (itoa (sslength ss)) "polylines\n"
                 (strcat (itoa op) " with open polylines") ""))
  (prin1))

 

 

 

 

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

Thank you!

0 Likes