Jump to content

Help counting lines lenght


kalamees

Recommended Posts

Hello, i need to count the lenght of all selected lines but my script keeps giving me this error: lentityp nil.

 

Can anyone help?

 

(defun c:joontepikkus()

 

(setq SS2 (ssget '((0 . "LINE"))))

(if SS2

(progn

(setq enttext (entget text))

(setq objekt (cdr (assoc 0 enttext)))

(if (= objekt "LINE")

(progn

(setq kogupikkus 0)

(setq ss1len (sslength SS2))

(setq a 0)

(setq i 0)

(repeat ss1len

(setq element (ssname SS2 i))

(setq aa (+ a aa))

(setq algkoords (assoc 10 enttext))

(setq algkoords (cdr algkoords))

(setq x (car algkoords))

(setq y (cadr algkoords))

(setq z (caddr algkoords))

(setq loppkoords (assoc 11 enttext))

(setq loppkoords (cdr loppkoords))

(setq x1 (car loppkoords))

(setq y1 (cadr loppkoords))

(setq z1 (caddr loppkoords))

(setq a2 (+ (+ (* (- x x1) (- x x1)) (* (- y y1) (- y y1))) (* (- z z1) (- z z1))))

(setq a (sqrt a2))

(setq kogupikkus (+ a kogupikkus))

(setq i (+ i 1))

)

(setq lause (strcat "Joonte kogupikkus on : " (rtos kogupikkus 2 3)))

 

)

(alert lause)

))))

Link to comment
Share on other sites

try this... i got this from off this forum but cant remember who though :)

apologies

 

(defun C:TLEN (/ ss tl n ent itm obj l)
 (setq ss (ssget)
       tl 0
       n (1- (sslength ss)))
 (while (>= n 0)
   (setq ent (entget (setq itm (ssname ss n)))
         obj (cdr (assoc 0 ent))
         l (cond
             ((= obj "LINE")
               (distance (cdr (assoc 10 ent))(cdr (assoc 11 ent))))
             ((= obj "ARC")
               (* (cdr (assoc 40 ent))
                  (if (minusp (setq l (- (cdr (assoc 51 ent))
                                         (cdr (assoc 50 ent)))))
                    (+ pi pi l) l)))
             ((or (= obj "CIRCLE")(= obj "SPLINE")(= obj "POLYLINE")
                  (= obj "LWPOLYLINE")(= obj "ELLIPSE"))
               (command "_.area" "_o" itm)
               (getvar "perimeter"))
             (T 0))
         tl (+ tl l)
         n (1- n)))
 (alert (strcat "Total length of selected objects is " (rtos tl)))
 (princ)
)

Link to comment
Share on other sites

Something like this perhaps:

 

(defun c:tLen nil
 ;; © Lee Mac 2010

 (
   (lambda ( SelSet Total i / entity )
     (if SelSet
       (princ
         (strcat "\nTotal Length: "
           (rtos
             (while (setq entity (ssname SelSet (setq i (1+ i))))
               (setq Total
                 (+
                   (vlax-curve-getDistAtParam entity
                     (vlax-curve-getEndParam entity)
                   )
                   Total
                 )
               )
             )
           )
         )
       )
     )
   )
   (ssget
     (list (cons 0 "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
       (cons -4 "<NOT")
         (cons -4 "<AND")
           (cons 0 "POLYLINE")
           (cons -4 "<OR")
             (cons -4 "&=") (cons 70 16)
             (cons -4 "&=") (cons 70 64)
           (cons -4 "OR>")
         (cons -4 "AND>")
       (cons -4 "NOT>")
     )
   )
   0 -1
 )

 (princ)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...