Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

LISP App to Replace Blocks in a Drawing??

Status
Not open for further replies.

mfleming

Structural
Oct 24, 2004
64
Hello.

ACAD 2005/2006

I'm having huge downtime when we have changes. For example, when I do building sections we have blocks for 32" , 34" ect. Joists.

I want to be able to replace all current blocks ie. "JST-30" with "JST-32" at all locations or selected /w window? All my blocks have the same insertion point ie. Jst. BRG centre. Can anyone help me out with this? I'm sure there are lots of people that would find this handy, thanks

Matt
 
Replies continue below

Recommended for you

If you INSERT Existing Block Name = New Block Name, they will all be redefined. For instance: INSERT JST-30=C:\Temp\JST-32 will do what you need. Incorporating it into a LISP routine would be something like this:

(DEFUN C:J30to32 ()
(COMMAND "INSERT" "JST-30=C:\Temp\JST-32" "Y" "0,0" "1" "1" "0")
(COMMAND "ERASE" "L" "")
(princ)
)
 
Save this as "rblock.lsp"

; Kerry L. Helmer
; AutoLisp Programming & AutoCad Drafting
; 3995 Hollansburg-Tampico Rd.
; Hollansburg, Ohio 45332
; 513-997-4488
;
(defun c:rblock (/ Lyr LList e1 dh clayer cancel nlayer update selection accept change ced cnt what_next cmd)(setq cmd (getvar "cmdecho"))(setvar "cmdecho" 0)(setq Lyr (tblnext "block" t))(while Lyr (if (not LList)(setq LList (list (cdr (assoc 2 Lyr))))(setq LList (cons (cdr (assoc 2 Lyr)) LList)))(setq Lyr (tblnext "block")))(setq LList (sort LList))(setq LList (removecharcter llist))(setq dh (load_dialog "rblock.dcl"))(new_dialog "replace" DH)(start_list "blocks")(mapcar 'add_list LList)(end_list)(action_tile "cancel" "(setq cancel t)")(action_tile "accept" "(setaccept)")(start_dialog)(done_dialog)(unload_dialog DH)(if accept (if (= selection "1")(progn (setq change nil)(setq change (entsel))(while (not change)(terpri)(princ "No entity Picked. Please re-select: ")(setq change (entsel)))(setq change (ssget "x" (list (assoc 2 (entget (car change)))))))(setq change (ssget))))(if accept (progn (setq what_next 3)(setq accept nil)(while (= what_next 3)(setq dh (load_dialog "rblock.dcl"))(new_dialog "rblock" DH)(start_list "blocks")(mapcar 'add_list LList)(end_list)(if nlayer (progn (setq llist (get_list_minus_element llist (cdr nlayer)))(setq llist (cons (cdr nlayer) llist)) (start_list "blocks")(mapcar 'add_list LList)(end_list)))(set_tile "msg" (strcat (itoa (sslength change)) " Blocks Selected"))(action_tile "cancel" "(setq cancel t)")(action_tile "accept" "(acceptfunb)") (action_tile "pick" "(done_dialog 3)")(setq what_next (start_dialog))(if (= what_next 3)(setblk))(done_dialog 3))(done_dialog)(unload_dialog DH)))(if accept (progn (setq e1 (subst nlayer clayer e1))(entmod e1)(setq cnt 0) (setq ced (ssname change 0))(while ced (setq ced (entget ced))(setq clayer (assoc 2 ced))(setq ced (subst nlayer clayer ced))(entmod ced)(setq cnt (1+ cnt))(setq ced (ssname change cnt)))))(setvar "cmdecho" cmd)(princ))(defun setblk (/ temp)(setq temp nil)(setq accept t)(setq temp (entsel))(while (not temp)(terpri)(princ "No entity Picked. Please re-select: ")(setq temp (entsel)))(setq temp (entget (car temp)))(setq nlayer (assoc 2 temp)))(defun acceptfunb ()(setq accept t)(setq nlayer (cons 2 (nth (atoi (get_tile "blocks")) LList)))(done_dialog 1)) (defun setaccept ()(setq accept t)(setq selection (get_tile "rb2"))(done_dialog 1)) (defun sort (LST / LST1 LO HI A) (if (> (length LST) 1)(progn (setq LO (car LST))(foreach x (cdr LST)(if (< x LO) (setq A LO LO x x A))(if (> x HI) (setq A HI HI x x A))(if x (setq LST1 (cons x LST1))))(append (list LO) (sort LST1) (if HI (list HI))))))(defun sort (LST / LST1 LSTLO LSTHI LO HI A) (repeat (/ (length LST) 2)(setq LO (car LST) HI nil LST1 nil)(foreach x LST (if (< x LO) (setq A LO LO x x A))(if (> x HI) (setq A HI HI x x A))(if x (setq LST1 (cons x LST1))))(setq LSTLO (append LSTLO (list LO)) LSTHI (append LSTHI (if HI (list HI))) LST (cdr(reverse LST1))))(append LSTLO LST (reverse LSTHI)))(defun xsort (LST)(sort (mapcar '(lambda (x)(if (numberp x) (rtos x 2 0) (strcase x))) LST)))(defun getposition ( variable list / elementnum ev)(setq elementnum 0)(setq ev (nth elementnum list))(while (/= variable ev)(setq elementnum (1+ elementnum))(setq ev (nth elementnum list)))(itoa elementnum))(defun getposition ( variable list / elementnum ev)(setq elementnum 0)(setq ev (nth elementnum list))(while (/= variable ev)(setq elementnum (1+ elementnum))(setq ev (nth elementnum list)))(itoa elementnum))(defun get_list_minus_element (list element / temp nlist cnt)(setq cnt 0)(setq nlist nil)(setq temp (nth 0 list))(while temp (if (/= temp element)(if (listp nlist)(setq nlist (cons temp nlist))(setq nlist (list temp))))(setq cnt (1+ cnt))(setq temp (nth cnt list)))(reverse nlist))(defun removecharcter (plist / charcter element cnt test nlist)(setq charcter "*")(setq cnt 0)(setq element (nth cnt plist))(while element (setq test (substr element 1 1))(if (/= test charcter)(if (listp nlist)(setq nlist (cons element nlist))(setq nlist (list element))))(setq cnt (1+ cnt))(setq element (nth cnt plist)))(reverse nlist))

And this as "rblock.dcl"

//; Kerry L. Helmer
//; AutoLisp Programming & AutoCad Drafting
//; 3995 Hollansburg-Tampico Rd.
//; Hollansburg, Ohio 45332
//; 513-997-4488
//;

rblock : dialog {label="Replace Block";:boxed_column {: text { alignment=centered;value="";key="msg";}: text { value=" ";}:text {label = "Replace with:";}: popup_list {key = "blocks";}: text { value=" ";}: button {label= "Pick Block in Drawing <";key="pick";}}: text { value=" ";}ok_cancel;allow_acept="true";}replace : dialog {label="Replace Block Command";:row {:boxed_column {:radio_column {:radio_button{label="Pick blocks to be replaced.";key="rb1";value=1;} :radio_button{label="Pick one block, all blocks of that type will be replaced."; key="rb2";}}ok_cancel;allow_acept="true";}:column{ :text { label="Kerry L. Helmer"; }:text { label="AutoLISP Programming";}:text { label="and AutoCAD Drafting"; }:text { label="513-997-4488"; }}}}

You might might want to throw Kerry L. Helmer a bone.
 
lpseifert - I'm new at this LISP stuff and am not getting an output from your code. I copied both sets of text to the same folder and named them as you said - then I used appload to throw rblock into CAD at the command line. But when I type rblock into the command line, nothing happens.
 
I think the routine is missing a (DEFUN in front of the C:rblock
 
thundrcunkydan - When you loaded the .lsp file did you get any error messages? Make sure you copy all of the code (see below)and that the 2 files are in a directory that is in Acad's support path.

IFRs - The (defun is there- way to the right. When I copied/pasted the formatting hid it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor