Professional Documents
Culture Documents
;; ;;
;; This program allows the user to dynamically construct a ;;
;; straight-segmented polyline whose overall length may optionally be ;;
;; limited to a given value. ;;
;; ;;
;; Upon issuing the command syntax 'tlpline' at the AutoCAD ;;
;; command-line, the program will first prompt the user to specify ;;
;; an optional length limit. At this prompt, the user may press ;;
;; 'Enter' to dismiss the prompt and proceed without restricting the ;;
;; polyline length. ;;
;; ;;
;; The user may then proceed to dynamically construct a polyline with ;;
;; linear segments, with the overall polyline length automatically ;;
;; restricted to the specified limit. After three vertices have been ;;
;; specified, the user may choose to close the polyline, with the ;;
;; length remaining within the given limit. ;;
;; ;;
;; Whilst constructing the polyline, the overall polyline length is ;;
;; displayed in real-time beside the AutoCAD cursor as a visual aid. ;;
;; ;;
;; The program also utilises my GrSnap utility to enable Object Snap ;;
;; functionality in conjunction with the dynamic visual effect. ;;
;; ;;
;; The program is also designed to perform successfully under all ;;
;; UCS and View settings. ;;
;; ;;
;;----------------------------------------------------------------------;;
;; Author: Lee Mac, Copyright � 2016 - www.lee-mac.com ;;
;;----------------------------------------------------------------------;;
;; Version 1.0 - 2016-06-23 ;;
;; ;;
;; - First release. ;;
;;----------------------------------------------------------------------;;
(defun c:tlpline ( / *error* cls col dis gr1 gr2 len lim lst msg ocs ort osf osm
pt1 pt2 str tmp ucx )
(initget 6)
(setq lim (cond ((getdist "\nSpecify length limit <none>: ")) (1e308)))
(defun LM:grsnap:snapfunction ( )
(eval
(list 'lambda '( p o / q )
(list 'if '(zerop (logand 16384 o))
(list 'if
'(setq q
(cdar
(vl-sort
(vl-remove-if 'null
(mapcar
(function
(lambda ( a / b )
(if (and (= (car a) (logand (car a)
o)) (setq b (osnap p (cdr a))))
(list (distance p b) b (car a))
)
)
)
'(
(0001 . "_end")
(0002 . "_mid")
(0004 . "_cen")
(0008 . "_nod")
(0016 . "_qua")
(0032 . "_int")
(0064 . "_ins")
(0128 . "_per")
(0256 . "_tan")
(0512 . "_nea")
(2048 . "_app")
(8192 . "_par")
)
)
)
'(lambda ( a b ) (< (car a) (car b)))
)
)
)
(list 'LM:grsnap:displaysnap '(car q)
(list 'cdr
(list 'assoc '(cadr q)
(list 'quote
(LM:grsnap:snapsymbols
(atoi (cond ((getenv "AutoSnapSize"))
("5")))
)
)
)
)
(cond
( (LM:OLE->ACI
(if (= 1 (getvar 'cvport))
(atoi (cond ((getenv "Layout AutoSnap
Color")) ("117761")))
(atoi (cond ((getenv "Model AutoSnap
Color")) ("104193")))
)
)
)
( 94 )
)
)
)
)
'(cond ((car q)) (p))
)
)
)
(defun LM:grsnap:snapsymbols ( p / -p -q -r a c i l q r )
(setq -p (- p) q (1+ p)
-q (- q) r (+ 2 p)
-r (- r) i (/ pi 6.0)
a 0.0
)
(repeat 12
(setq l (cons (list (* r (cos a)) (* r (sin a))) l)
a (- a i)
)
)
(setq c (apply 'append (mapcar 'list (cons (last l) l) l)))
(list
(list 1
(list -p -p) (list p -p) (list p -p) (list p p) (list p p) (list -p p)
(list -p p) (list -p -p)
(list -q -q) (list q -q) (list q -q) (list q q) (list q q) (list -q q)
(list -q q) (list -q -q)
)
(list 2
(list -r -q) (list 0 r) (list 0 r) (list r -q)
(list -p -p) (list p -p) (list p -p) (list 0 p) (list 0 p) (list -p
-p)
(list -q -q) (list q -q) (list q -q) (list 0 q) (list 0 q) (list -q
-q)
)
(cons 4 c)
(vl-list* 8 (list -r -r) (list r r) (list r -r) (list -r r) c)
(list 16
(list p 0) (list 0 p) (list 0 p) (list -p 0) (list -p 0) (list 0 -p)
(list 0 -p) (list p 0)
(list q 0) (list 0 q) (list 0 q) (list -q 0) (list -q 0) (list 0 -q)
(list 0 -q) (list q 0)
(list r 0) (list 0 r) (list 0 r) (list -r 0) (list -r 0) (list 0 -r)
(list 0 -r) (list r 0)
)
(list 32
(list r r) (list -r -r) (list r q) (list -q -r) (list q r) (list -r
-q)
(list -r r) (list r -r) (list -q r) (list r -q) (list -r q) (list q
-r)
)
(list 64
'( 0 1) (list 0 p) (list 0 p) (list -p p) (list -p p) (list -p
-1) (list -p -1) '( 0 -1)
'( 0 -1) (list 0 -p) (list 0 -p) (list p -p) (list p -p) (list p
1) (list p 1) '( 0 1)
'( 1 2) (list 1 q) (list 1 q) (list -q q) (list -q q) (list -q
-2) (list -q -2) '(-1 -2)
'(-1 -2) (list -1 -q) (list -1 -q) (list q -q) (list q -q) (list q
2) (list q 2) '( 1 2)
)
(list 128
(list (1+ -p) 0) '(0 0) '(0 0) (list 0 (1+ -p))
(list (1+ -p) 1) '(1 1) '(1 1) (list 1 (1+ -p))
(list -p q) (list -p -p) (list -p -p) (list q -p)
(list -q q) (list -q -q) (list -q -q) (list q -q)
)
(vl-list* 256 (list -r r) (list r r) (list -r (1+ r)) (list r (1+ r)) c)
(list 512
(list -p -p) (list p -p) (list -p p) (list p p) (list -q -q) (list q
-q)
(list q -q) (list -q q) (list -q q) (list q q) (list q q) (list -q
-q)
)
(list 2048
(list -p -p) (list p p) (list -p p) (list p
-p)
(list (+ p 05) -p) (list (+ p 06) -p) (list (+ p 05) -q) (list (+ p 06)
-q)
(list (+ p 09) -p) (list (+ p 10) -p) (list (+ p 09) -q) (list (+ p 10)
-q)
(list (+ p 13) -p) (list (+ p 14) -p) (list (+ p 13) -q) (list (+ p 14)
-q)
(list -p -p) (list p -p) (list p -p) (list p p) (list p p) (list -p p)
(list -p p) (list -p -p)
(list -q -q) (list q -q) (list q -q) (list q q) (list q q) (list -q q)
(list -q q) (list -q -q)
)
(list 8192 (list r 1) (list -r -q) (list r 0) (list -r -r) (list r q) (list
-r -1) (list r r) (list -r 0))
)
)
(if
(and
(setq lst (mapcar 'distof (str->lst str)))
(vl-every 'numberp lst)
(< 1 (length lst) 4)
)
(mapcar '+ bpt lst)
)
)
(defun LM:OLE->ACI ( c )
(apply 'LM:RGB->ACI (LM:OLE->RGB c))
)
(defun LM:OLE->RGB ( c )
(mapcar '(lambda ( x ) (lsh (lsh (fix c) x) -24)) '(24 16 8))
)
(defun LM:RGB->ACI ( r g b / c o )
(setq c
(vl-catch-all-apply
'(lambda nil
(setq o (vla-getinterfaceobject (LM:acapp) (strcat
"autocad.accmcolor." (substr (getvar 'acadver) 1 2))))
(vla-setrgb o r g b)
(vla-get-colorindex o)
)
)
)
(if (= 'vla-object (type o)) (vlax-release-object o))
(if (not (vl-catch-all-error-p c)) c)
)
(defun LM:colorbook->ACI ( b n / c o )
(setq c
(vl-catch-all-apply
'(lambda nil
(setq o (vla-getinterfaceobject (LM:acapp) (strcat
"autocad.accmcolor." (substr (getvar 'acadver) 1 2))))
(vla-setcolorbookcolor o b n)
(vla-get-colorindex o)
)
)
)
(if (= 'vla-object (type o)) (vlax-release-object o))
(if (not (vl-catch-all-error-p c)) c)
)
;;----------------------------------------------------------------------;;
(vl-load-com)
(princ
(strcat
"\n:: TotalLengthPolyline.lsp | Version 1.0 | \\U+00A9 Lee Mac "
(menucmd "m=$(edtime,0,yyyy)")
" www.lee-mac.com ::"
"\n:: Type \"tlpline\" to Invoke ::"
)
)
(princ)
;;----------------------------------------------------------------------;;
;; End of File ;;
;;----------------------------------------------------------------------;;