Your loop has a hiccup, it keeps going until the counter exceeds the number of items in the set, then it error out. I think you need to change just 1 line;
(while ct1 ssmembers
to
(while (< ct1 ssmembers)
Registered forum members do not see this ad.
It adds everything up alright, but I get that error when it finishes. Can anyone help?
Code:(defun c:takeoff () ;(setvar "cmdecho" 0) ;TRYING TO COUNT PIPE ON PIPE LAYERS HERE ;CREATE SELECTION SET OF ALL LINES ON WHICHEVER LAYER" (NEED TO CREATE A LIST OF LAYERS TO CYCLE THROUGH) (setq ss1 (ssget "X" '((0 . "line") (8 . "0")))) ;GETS THE NUMBER OF ITEMS IN THE SELECTION SET (setq ssmembers (sslength ss1)) ;sets counter to zero (setq ct1 0) (setq totallenth 0) ;(repeat ssmembers (while ct1 ssmembers ;GETS THE FIRST ITEM FROM THE SELECTION SET (setq ent1 (entget (ssname ss1 ct1))) ;FINDS THE X AND Y COORDINATES OF THE FIRST ITEM (setq pt1 (cdr (assoc 10 ent1))) (setq pt2 (cdr (assoc 11 ent1))) ;FINDS THE DISTANCE BETWEEN THOSE POINTS (setq lenth1 (distance pt1 pt2)) ;sets up a variable to add the lengths into (setq totallenth (+ lenth1 totallenth)) ;increases counter by one (setq ct1 (1+ ct1)) ) ) ;_ end of defun




Your loop has a hiccup, it keeps going until the counter exceeds the number of items in the set, then it error out. I think you need to change just 1 line;
(while ct1 ssmembers
to
(while (< ct1 ssmembers)
Code:(defun c:takeoff2 (/ adoc selset res) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) res 0.0 ) ;_ end of setq (vla-startundomark adoc) (if (setq selset (ssget "_X" '((0 . "LINE,LWPOLYLINE") (8 . "0")))) (foreach item (vl-remove-if 'listp (mapcar 'cadr (ssnamex selset))) (setq res (+ res (vla-get-length (vlax-ename->vla-object item)))) ) ;_ end of foreach ) ;_ end of if (vla-endundomark adoc) (princ (strcat "\nSum length : " (rtos res 2))) (princ) ) ;_ end of defun
All I say is only my opinion.
Thanks guys -
kpblc - you just jumped way over my head. I've never quite figured out how to use any of that vl- vla- stuff.
Carl - I think I've tried that, but I'll go back and look at it again.
It's simple very much
And I don't know another simple way to get length of lightweightpolyline or 3d-polyline - only (vla-get-length).
All I say is only my opinion.
It is time for me to learn something new.
Can you use the same thing to add arc lengths too? Those are the three I usually have, lines, polylines and arcs.
Registered forum members do not see this ad.
Why not?
Code:(defun c:takeoff3 (/ adoc selset res) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) res 0.0 ) ;_ end of setq (vla-startundomark adoc) (if (setq selset (ssget "_X" '((0 . "LINE,LWPOLYLINE,ARC") (8 . "0")))) (foreach item (vl-remove-if 'listp (mapcar 'cadr (ssnamex selset))) (cond ((= (cdr (assoc 0 (entget item))) "ARC") (setq res (+ res (vla-get-arclength (vlax-ename->vla-object item)))) ) (t (setq res (+ res (vla-get-length (vlax-ename->vla-object item)))) ) ) ;_ end of cond ) ;_ end of foreach ) ;_ end of if (vla-endundomark adoc) (princ (strcat "\nSum length : " (rtos res 2))) (princ) ) ;_ end of defun
All I say is only my opinion.
Bookmarks