DavidP Posted 12 hours ago Posted 12 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 11 hours ago by DavidP Attach Blocks Quote
DavidP Posted 12 hours ago Author Posted 12 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 12 hours ago by DavidP Added additional info Quote
Koz Posted 6 hours ago Posted 6 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 1 hour ago Posted 1 hour 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
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.