(vl-load-com); if needed
(defun C:ShearPosts (/ *error* doc svnames svvals esel ent edata pt1 pt2 side rot)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
); if
(mapcar 'setvar svnames svvals); reset System Variables
(vla-endundomark doc)
(princ)
); defun - *error*
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark doc)
(setq ; System Variable saving/resetting without separate variables for each:
svnames '(osmode cmdecho orthomode blipmode clayer); list of System Variable Names
svvals (mapcar 'getvar svnames); get initial Values
); setq
(if (and (setq esel (entsel "\nSelect Line at which to add Shear Posts: "))
(setq ent (car esel)
edata (entget ent))
(= (cdr (assoc 0 edata)) "LINE")
(tblsearch "LAYER" "s-plan-rcol")
(tblsearch "BLOCK" "ShearPost")
); and
(progn
(setq
pt1 (cdr (assoc 10 edata)); start
pt2 (cdr (assoc 11 edata)); end
side (getpoint pt1 "\nPick to side of Line on which to add shear posts: ")
rot (* (/ (angle (vlax-curve-getClosestPointTo ent side T) side) pi) 180); ROTation angle for Insert commands
); setq
(mapcar 'setvar svnames '(0 0 0 0 "s-plan-rcol"))
; turn off osnap, command echoing, ortho, blips; set Layer
(command
"_.insert" "ShearPost"
"_none" (polar pt1 (angle pt1 pt2) 1.75); half-post-width in from start
"" "" rot
"_.insert" ""
"_none" (polar pt2 (angle pt2 pt1) 1.75); from other end
"" "" rot
); command
); progn
(cond ((not esel) (princ "\nError: Wrong selection of a line."))
((not (tblsearch "LAYER" "s-plan-rcol")) (princ "\nError: \"s-plan-rcol\" layer doesn't exist in the drawing. "))
((not (tblsearch "BLOCK" "ShearPost")) (princ "\nError: \"ShearPost\" block doesn't exist in the drawing. "))
); cond
); if
(mapcar 'setvar svnames svvals); reset System Variables
(vla-endundomark doc)
(princ)
); defun