Jump to content

Length of grouped lines


wimal

Recommended Posts

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)
)

Link to comment
Share on other sites

(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 by hanhphuc
removed 'and'
Link to comment
Share on other sites

(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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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...