; ALENGTH - Determine length of an arc.
;
; Written by Stephen Barsky -- 10/05/87 -- 714/544-0790
;
; This program implements a new Autocad command called ALENGTH (Arc Length).
; When invoked, ALENGTH prompts the user to select an entity on the screen.
; If the entity selected is an arc, it displays the length of the arc.
; If the entity selected is a circle, it displays the circumference.
; If the entity selected is a line, it displays the length.
; The structure of C:ALENGTH makes it easy to add routines for other
; types of entities.  

(defun C:ALENGTH ( / x pickpoint ent etype )
	(setq x (entsel))					; Prompt user for an entity on screen.
	(setq pickpoint (cadr x))		; Save the pick point.
	(setq ent (entget (car x)))	; Get info for the selected entity.
	(setq etype (cdr (assoc 0 ent)))	; Determine the type of entity picked.
	(cond ((= etype "ARC") (arclength ent))		; For arcs...
			((= etype "LINE") (linelength ent))		; For lines...
			((= etype "CIRCLE") (circlength ent))	; For circles...
			(t (command "AREA" "E" pickpoint ))		; Default, invoke AREA command.
	)
)

(defun circlength ( ent )
	(* 2 (* pi (cdr (assoc 40 ent))))
)

(defun linelength ( ent / p1 p2 )
	(setq p1 (cdr (assoc 10 ent)))
	(setq p2 (cdr (assoc 11 ent)))
	(distance p1 p2)
)

(defun arclength ( ent / r sa ea delta )
	(setq r (cdr (assoc 40 ent)))
	(setq sa (cdr (assoc 50 ent)))
	(setq ea (cdr (assoc 51 ent)))
	(setq delta (cond ((> sa ea) (- (* 2 pi) (- sa ea))) (t (- ea sa))))
	(* delta r)
)
1