DavidP Posted 15 hours ago Posted 15 hours ago (edited) MyBlocks.zip (defun c:foo ( / a1 a2 oldCMDECHO s r pt folderPath BlockNames oldEnt newEnt blk ) (setq oldCMDECHO (getvar "CMDECHO") a1 (getvar "ATTDIA") a2 (getvar "ATTREQ") pt (list 0.0 0.0) s 0.5 r 0.0) (setvar "CMDECHO" 0) (setvar "ATTDIA" 0) (setvar "ATTREQ" 0) (setq folderPath "C:/MyBlocks/" BlockNames (list "BLK1.dwg" "BLK2.dwg" "BLK3.dwg")) (setq oldEnt (entlast)) (foreach blk BlockNames (setq blk (strcat folderPath blk)) (command "_.-insert" blk pt s s r) (setq newEnt (entlast)) (if (and newEnt (/= oldEnt newEnt)) (entdel newEnt) ) ) (setvar "ATTDIA" a1) (setvar "ATTREQ" a2) (setvar "CMDECHO" oldCMDECHO) (princ "\nBlocks inserted successfully.") (princ) ) Edited 15 hours ago by DavidP Attach Blocks Quote
DavidP Posted 15 hours ago Author Posted 15 hours ago (edited) I have drawing with blocks some of which have be change by the drafters... I want to re-insert & redefine the blocks from a local folder. What I'm I missing? My blocks are Dynamic blocks. Edited 15 hours ago by DavidP Added additional info Quote
Koz Posted 9 hours ago Posted 9 hours ago you may try to change: (command "_.-insert" blk pt s s r) (setq newEnt (entlast)) (if (and newEnt (/= oldEnt newEnt)) (entdel newEnt) ) to (command "_.-insert" (strcat (vl-filename-base blk) "=" blk) pt) (while (> (getvar "CMDACTIVE") 0) (command "")) (entdel(entlast)) ; Delete the temp insert block This will force AutoCAD to update a block from a drawing. you will need to make sure the block name is same as the DWG's name. Since you are working wirth dynamic blocks, the safer way is to get the dynamic property values for each block reference before update it and apply the data back to blocks after the definition is updated, in case dynamic parameters may have been changed in definition. Quote
Saxlle Posted 4 hours ago Posted 4 hours ago Hi @DavidP From this part of code, you're file path is incorrect. Instend of "C:/MyBlocks/" need to be "C:/Users/"Your Name"/Desktop/MyBlocks/" or do Support File Search Path in Option -> File inside the AutoCAD to add that folder "MyBlocks". 10 hours ago, DavidP said: (setq folderPath "C:/MyBlocks/" BlockNames (list "BLK1.dwg" "BLK2.dwg" "BLK3.dwg")) From this part of code, if I open the blank drawing where the nothing is inside, the inserted blocks "BLK1, BLK2 and BLK3" will be erased, because there isn't "oldEnt" inside the drawing. 10 hours ago, DavidP said: (if (and newEnt (/= oldEnt newEnt)) (entdel newEnt) ) So, can you provide the drawing where you want to insert desired blocks? Quote
Lee Mac Posted 2 hours ago Posted 2 hours ago I had written & posted a 'redefine all blocks' program here: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-blocks-amp-attributes-lisp/m-p/4423983#M315011 But for some reason I no longer appear to be able to access that thread... I'll see if I have a copy in my library. Quote
Lee Mac Posted 2 hours ago Posted 2 hours ago Found it - ;; Redefine All Blocks - Lee Mac (defun c:redefall ( / bln dir doc dwg lst obj org spc ) (setq dir nil) ;; Directory of Block Library; nil to use Support Path (if dir (setq dir (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir)) "\\")) (setq dir "") ) (cond ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer)))))) (princ "\nCurrent layer locked.") ) ( (setq doc (vla-get-activedocument (vlax-get-acad-object)) spc (vla-get-modelspace doc) org (vlax-3D-point 0 0) ) (vlax-for blk (vla-get-blocks doc) (if (and (= :vlax-false (vla-get-isxref blk)) (= :vlax-false (vla-get-islayout blk)) (not (wcmatch (setq bln (vla-get-name blk)) "`**,_*,*|*")) (setq dwg (findfile (strcat dir bln ".dwg"))) ) (progn (setq obj (vla-insertblock spc org dwg 1.0 1.0 1.0 0.0)) (if (= :vlax-true (vla-get-hasattributes obj)) (setq lst (vl-list* "," bln lst)) ) (vla-delete obj) ) ) ) (if lst (vl-cmdf "_.attsync" "_N" (apply 'strcat (cdr lst)))) (vla-regen doc acallviewports) ) ) (princ) ) (vl-load-com) (princ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.