Lisp to insert block at specific location and layer

Lisp to insert block at specific location and layer

Anonymous
Not applicable
7,642 Views
40 Replies
Message 1 of 41

Lisp to insert block at specific location and layer

Anonymous
Not applicable

I am interested in a lisp that will insert a block "4x6" (Which requires no scaling) and place it at both ends of a selected line. offset 2" from that line and give the option of which side of that line they will be placed.  finally the inserted "4x6" will be placed on the "s-plan-rcol" layer.   I've included an image for disired result. No scaling or annotations or anything, just would like to show posts at the end of shear walls without having to place them manually.

 

thanks for any help

0 Likes
Accepted solutions (1)
7,643 Views
40 Replies
Replies (40)
Message 41 of 41

ВeekeeCZ
Consultant
Consultant
Accepted solution

@Anonymous wrote:

Having that limitation would likely be helpful


Since Kent probably overlooked this requirement (sorry if not) I made this adjustment for you.

 

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