wimal Posted June 25, 2018 Posted June 25, 2018 I have a group containing lines and arcs only.Can I get the total length of lines and arcs with lisp. Quote
JuniorNogueira Posted June 25, 2018 Posted June 25, 2018 Try this: (defun tlines () (setq lbeg (cdr (assoc '10 ent))) (setq lend (cdr (assoc '11 ent))) (setq llen (distance lbeg lend)) (setq tlen (+ tlen llen)) (ssdel sn ss1) ) (defun tarcs () (setq cen (cdr (assoc '10 ent))) (setq rad (cdr (assoc '40 ent))) (setq dia (* rad 2.0)) (setq circ (* (* rad pi) 2.0)) (setq sang (cdr (assoc '50 ent))) (setq eang (cdr (assoc '51 ent))) (if (< eang sang) (setq eang (+ eang (* pi 2.0))) ) (setq tang (- eang sang)) (setq tang2 (* (/ tang pi) 180.0)) (setq circ2 (/ tang2 360.0)) (setq alen (* circ2 circ)) (setq tlen (+ tlen alen)) (princ) (ssdel sn ss1) ) (defun tplines () (command "area" "e" sn) (setq tlen (+ tlen (getvar "perimeter"))) (ssdel sn ss1) ) (defun tsplines () (command "area" "e" sn) (setq tlen (+ tlen (getvar "perimeter"))) (ssdel sn ss1) ) (DEFUN C:TOTLEN (/ tlen ss1 sn sn2 et) (setq cmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (setq tlen 0) (prompt "\nSelect only the entities you want for the total length:" ) (setq ss1 (ssget)) (while (> (sslength ss1) 0) (setq sn (ssname ss1 0)) (setq ent (entget sn)) (setq et (cdr (assoc '0 ent))) (cond ((= et "LINE") (tlines)) ((= et "ARC") (tarcs)) ((= et "LWPOLYLINE") (tplines)) ((= et "POLYLINE") (tplines)) ((= et "SPLINE") (tsplines)) ((or (/= et "LINE") (/= et "ARC") (/= et "LWPOLYLINE") (/= et "POLYLINE") (/= et "SPLINE") ) (ssdel sn ss1) ) ) ) (alert (strcat "\nThe total length of selected rows, polylines and arcs is:" (rtos tlen 2 2) ) ) (setvar "cmdecho" cmdecho) (prompt "\nAplicativo de terceiros!! ") (princ) ) Quote
hanhphuc Posted June 25, 2018 Posted June 25, 2018 (edited) (vl-load-com) (defun c:gsum (/ l len ) (if (vlax-for x (vla-get-groups (vla-get-activedocument (vlax-get-acad-object))) (setq len 0. l (cons (list "Group " (vla-get-Name x) " Length = " (vlax-for x x (if (wcmatch (strcase (vla-get-ObjectName x)) "*BARC,*BLINE") (setq len (+ len (vlax-curve-getdistatparam x (vlax-curve-getendparam x)))) ) (rtos len 2) ) ) l ) ) ) (foreach x l (terpri) (princ (apply 'strcat x))) (alert "\nOops! No group found?") ) (textscr) (princ) ) Edited June 25, 2018 by hanhphuc removed 'and' Quote
wimal Posted June 26, 2018 Author Posted June 26, 2018 (vl-load-com) (defun c:gsum (/ l len ) (if (vlax-for x (vla-get-groups (vla-get-activedocument (vlax-get-acad-object))) (setq len 0. l (cons (list "Group " (vla-get-Name x) " Length = " (vlax-for x x (if (wcmatch (strcase (vla-get-ObjectName x)) "*BARC,*BLINE") (setq len (+ len (vlax-curve-getdistatparam x (vlax-curve-getendparam x)))) ) (rtos len 2) ) ) l ) ) ) (foreach x l (terpri) (princ (apply 'strcat x))) (alert "\nOops! No group found?") ) (textscr) (princ) ) Program is working . But I need to first select the group and find the total length of that group. Quote
wimal Posted June 26, 2018 Author Posted June 26, 2018 Try this: (defun tlines () (setq lbeg (cdr (assoc '10 ent))) (setq lend (cdr (assoc '11 ent))) (setq llen (distance lbeg lend)) (setq tlen (+ tlen llen)) (ssdel sn ss1) ) (defun tarcs () (setq cen (cdr (assoc '10 ent))) (setq rad (cdr (assoc '40 ent))) (setq dia (* rad 2.0)) (setq circ (* (* rad pi) 2.0)) (setq sang (cdr (assoc '50 ent))) (setq eang (cdr (assoc '51 ent))) (if (< eang sang) (setq eang (+ eang (* pi 2.0))) ) (setq tang (- eang sang)) (setq tang2 (* (/ tang pi) 180.0)) (setq circ2 (/ tang2 360.0)) (setq alen (* circ2 circ)) (setq tlen (+ tlen alen)) (princ) (ssdel sn ss1) ) (defun tplines () (command "area" "e" sn) (setq tlen (+ tlen (getvar "perimeter"))) (ssdel sn ss1) ) (defun tsplines () (command "area" "e" sn) (setq tlen (+ tlen (getvar "perimeter"))) (ssdel sn ss1) ) (DEFUN C:TOTLEN (/ tlen ss1 sn sn2 et) (setq cmdecho (getvar "cmdecho")) (setvar "cmdecho" 0) (setq tlen 0) (prompt "\nSelect only the entities you want for the total length:" ) (setq ss1 (ssget)) (while (> (sslength ss1) 0) (setq sn (ssname ss1 0)) (setq ent (entget sn)) (setq et (cdr (assoc '0 ent))) (cond ((= et "LINE") (tlines)) ((= et "ARC") (tarcs)) ((= et "LWPOLYLINE") (tplines)) ((= et "POLYLINE") (tplines)) ((= et "SPLINE") (tsplines)) ((or (/= et "LINE") (/= et "ARC") (/= et "LWPOLYLINE") (/= et "POLYLINE") (/= et "SPLINE") ) (ssdel sn ss1) ) ) ) (alert (strcat "\nThe total length of selected rows, polylines and arcs is:" (rtos tlen 2 2) ) ) (setvar "cmdecho" cmdecho) (prompt "\nAplicativo de terceiros!! ") (princ) ) Thanks It is working perfectlly. Quote
hanhphuc Posted June 26, 2018 Posted June 26, 2018 Program is working . But I need to first select the group and find the total length of that group. what do you mean "group' here ? if it is merely a selection not 'ACAD_GROUP' ? then quick & dirty VL (vl-load-com) (defun c:sum ( / l ) (if (and (ssget '((0 . [color="purple"]"LINE,ARC"[/color])))[color="green"] ; <-- add selection filter with comma e.g: *POLYLINE,SPLINE,etc.. [/color] (vlax-for x (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) (setq l (cons (vlax-curve-getdistatparam x (vlax-curve-getendparam x)) l) ) ) ) (alert (strcat "\nTotal length = " (rtos (apply '+ l ) 2 ))) (princ "\nNothing selected?") ) (princ) ) FWIW here is Lee's version Quote
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.