Jozef13 Posted July 23, 2018 Share Posted July 23, 2018 Dear all, I am looking for a lisp for Sum of Length for selected PolyLines and Lines by their Linetype. E.g.: LineType.....Length Cu10-6.......25.0 Cu12-6.......20.0 Cu16-6.......0.0 Cu16-10......35.0 Cu18-10......12.0 Cu22-10......10.0 Or in csv format, to be able to copy/export it to excel Quote Link to comment Share on other sites More sharing options...
Grrr Posted July 23, 2018 Share Posted July 23, 2018 Basically you need to use: group code 6 this tutorial and this: (vlax-curve-getdistatparam o (vlax-curve-getendparam o)) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 23, 2018 Share Posted July 23, 2018 This is code by lee-mac and I have added a bit to it its nearly there but I need some time to fix. Grrr bylayer has no assoc 6 ;; Displays the total length of selected objects at the ;; ;; command line. ;; ;;--------------------=={ Total Length }==--------------------;; ;; ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;; ;;------------------------------------------------------------;; (princ "\nType Tlen to run") (defun c:tLen ( / lts lt) ;; © Lee Mac 2010 (setq lts (list "Cu10-6" "Cu12-6" "Cu16-6" "Cu16-10" "Cu18-10" "Cu22-10" )) (repeat (setq x (length lts)) (setq lt (nth (setq x (- x 1)) lts)) ( (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 6 lt) (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.0 -1 ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 23, 2018 Share Posted July 23, 2018 Beware: very old code... http://www.cadtutor.net/forum/showthread.php?42734-Line-Length-Calculator Quote Link to comment Share on other sites More sharing options...
Jozef13 Posted July 23, 2018 Author Share Posted July 23, 2018 (edited) This is code by lee-mac and I have added a bit to it its nearly there but I need some time to fix. Grrr bylayer has no assoc 6 ;; Displays the total length of selected objects at the ;; ;; command line. ;; ;;--------------------=={ Total Length }==--------------------;; ;; ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;; ;;------------------------------------------------------------;; (princ "\nType Tlen to run") (defun c:tLen ( / lts lt) ;; © Lee Mac 2010 (setq lts (list "Cu10-6" "Cu12-6" "Cu16-6" "Cu16-10" "Cu18-10" "Cu22-10" )) (repeat (setq x (length lts)) (setq lt (nth (setq x (- x 1)) lts)) ( (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 6 lt) (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.0 -1 ) ) (princ) ) I have also modified Lee-Mac code and my working result is here: (vl-load-com) (defun c:tlenLT (/ e i l s ltlist lt ltname) ;;; (setq LTfilter "TZB*,BYLAYER") (setq LTfilter "*") (if (setq s (ssget '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE") (-4 . "<NOT") (-4 . "<AND") (0 . "POLYLINE") (-4 . "&") (70 . 80) (-4 . "AND>") (-4 . "NOT>") ) ) ) (progn ;;; vvv Generate Linetypes List from selection (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) ltname (cdr (assoc 6 (entget e))) ) (if (= ltname nil) (setq ltname "BYLAYER")) (if (and (not (member ltname ltlist)) (wcmatch ltname LTfilter) ) (progn (setq ltlist (cons ltname ltlist)) ;adds linetype name to list ) ) ) ;;;repeat ;;; ^^^^ Generate Linetypes List from selection (foreach lt ltlist (setq l 0.0) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) ltname (cdr (assoc 6 (entget e))) ) (if (= ltname nil) (setq ltname "BYLAYER")) (if (= ltname lt) (setq l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e) ) ) ) ) ) ;;; (princ "\nTotal Length: ") (princ (strcat lt "," (rtos (/ l 1000.0)))) (princ "\n") ) ) ) (textscr) (princ) ) (princ) Edited July 24, 2018 by Jozef13 Added code tags Quote Link to comment Share on other sites More sharing options...
Jozef13 Posted July 23, 2018 Author Share Posted July 23, 2018 Beware: very old code... http://www.cadtutor.net/forum/showthread.php?42734-Line-Length-Calculator Perfectly, Lee as usual. Unfortunately I need to calculate it just from selection, not from whole drawing Quote Link to comment Share on other sites More sharing options...
Grrr Posted July 23, 2018 Share Posted July 23, 2018 implementing my tought into code.. (defun C:test ( / SS aL i e itm ltp b ) (if (setq SS (ssget "_:L-I" '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE") (-4 . "<NOT") (-4 . "<AND") (0 . "POLYLINE") (-4 . "&") (70 . 80) (-4 . "AND>") (-4 . "NOT>") ) ) ) (progn (setq aL '()) (repeat (setq i (sslength SS)) (setq e (ssname SS (setq i (1- i)))) (setq itm (cons (setq ltp (cond ( (cdr (assoc 6 (entget e))) ) ( "ByLayer" ) )) (+ (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) (setq b (cond ( (cdr (assoc ltp aL)) ) (0.)))) ) ) (if (zerop b) (setq aL (cons itm aL)) (setq aL (subst itm (assoc (car itm) aL) aL)) ) ) (princ "\n============\n") (foreach x (vl-sort aL ''((a b) (apply '< (mapcar 'car (list a b)))) ) (princ (car x)) (princ " : ") (princ (rtos (cdr x) 2 4)) (princ "\n") ) (princ "============") (textscr) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Jozef13 Posted July 23, 2018 Author Share Posted July 23, 2018 implementing my tought into code.. (defun C:test ( / SS aL i e itm ltp b ) (if (setq SS (ssget "_:L-I" '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE") (-4 . "<NOT") (-4 . "<AND") (0 . "POLYLINE") (-4 . "&") (70 . 80) (-4 . "AND>") (-4 . "NOT>") ) ) ) (progn (setq aL '()) (repeat (setq i (sslength SS)) (setq e (ssname SS (setq i (1- i)))) (setq itm (cons (setq ltp (cond ( (cdr (assoc 6 (entget e))) ) ( "ByLayer" ) )) (+ (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) (setq b (cond ( (cdr (assoc ltp aL)) ) (0.)))) ) ) (if (zerop b) (setq aL (cons itm aL)) (setq aL (subst itm (assoc (car itm) aL) aL)) ) ) (princ "\n============\n") (foreach x (vl-sort aL ''((a b) (apply '< (mapcar 'car (list a b)))) ) (princ (car x)) (princ " : ") (princ (rtos (cdr x) 2 4)) (princ "\n") ) (princ "============") (textscr) ) ) (princ) ) Hmm... nice short code and well working. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted July 24, 2018 Share Posted July 24, 2018 Please read the Code Posting Guidelines and have your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 24, 2018 Share Posted July 24, 2018 implementing my tought into code.. (defun C:test ( / SS aL i e itm ltp b ) (if (setq SS (ssget "_:L-I" '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE") (-4 . "<NOT") (-4 . "<AND") (0 . "POLYLINE") (-4 . "&") (70 . 80) (-4 . "AND>") (-4 . "NOT>") ) ) ) (progn (setq aL '()) (repeat (setq i (sslength SS)) (setq e (ssname SS (setq i (1- i)))) (setq itm (cons (setq ltp (cond ( (cdr (assoc 6 (entget e))) ) ( "ByLayer" ) )) (+ (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) (setq b (cond ( (cdr (assoc ltp aL)) ) (0.)))) ) ) (if (zerop b) (setq aL (cons itm aL)) (setq aL (subst itm (assoc (car itm) aL) aL)) ) ) (princ "\n============\n") (foreach x (vl-sort aL ''((a b) (apply '< (mapcar 'car (list a b)))) ) (princ (car x)) (princ " : ") (princ (rtos (cdr x) 2 4)) (princ "\n") ) (princ "============") (textscr) ) ) (princ) ) Nice Grrr .. maybe a little addition (princ "============") (if (> (length al) 1) (princ (strcat "\nTOTAL : " (vl-princ-to-string (apply '+ (mapcar 'cdr al))) ) ) ) (textscr) Quote Link to comment Share on other sites More sharing options...
Grrr Posted July 24, 2018 Share Posted July 24, 2018 Nice Grrr .. maybe a little addition C O D E Thanks Ron, nice addition! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.