Astro Posted November 2, 2009 Posted November 2, 2009 Hi all, I am sure my request already exist somewhere but could not find it:oops:. I have a lot of drawings (over 1000) containing dynamic blocks with attributes from our symbol library. And our symbol library has been updated. Now i have to update all these drawings with the updated blocks I need a lisp to do this tasks: open drawings one by one stored in a folder scan the drawing for blocks from a predifined list (e.g. block1, block2, block3,...) if this blocks exists, replace it by new block with the same name (new block is stored in a drawing or folder) keep the block rotation, the block visibility, flip state, scale (if old block was rotated by 90°, the new one will also be rotated by 90°; if visibility state was open the new one will also be open...) keep the attribute values from old blocks and update the new block when inserted Maybe exporting all these informations to excell with the attribute extraction tool from autocad and then reuse these informations could be a godd idea Hope somebody can help me out. This will save my life Quote
Freerefill Posted November 2, 2009 Posted November 2, 2009 This sounds like a job for my batch engine, though I don't have much experience with dynamic blocks. If someone could figure out how to do it for one drawing, it would be easy to do it for all of them. *EDIT* I just whipped this up, run it on a drawing and let me know if it works. Just replace the "C:/" with whatever directory your blocks are in. Be sure to use a forward-slash, not the usual Windows back-slash. (defun c:blkrep2( / ss blkPth blkLst blkNam) (setq blkPth "C:/") (setq ss (ssget "X" '((410 . "MODEL")(0 . "INSERT")))) (if ss (setq blkLst (mapcar '(lambda (x) (cdr (assoc 2 (entget x)))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))) (while blkLst (setq blkLst (vl-remove (setq blkNam (car blkLst)) blkLst)) (if (findfile (strcat blkPth blkNam)) (progn (vl-cmdf "-insert" (strcat blkNam "=" blkPth blkNam) "Y")(vl-cmdf)) ) ) (princ) ) Quote
Astro Posted November 3, 2009 Author Posted November 3, 2009 Thank's for your help. Unfortunatly it's not working... Maybe i am doing something wrong? Quote
Freerefill Posted November 3, 2009 Posted November 3, 2009 Are you getting an error message of some sort? Also, I've set the filter to only select blocks on Modelspace. Are your blocks in Paperspace? Quote
alanjt Posted November 3, 2009 Posted November 3, 2009 Last edited by Freerefill : Yesterday at 02:16 pm. Reason: Note to self: don't submit code without first making sure it's awesome. LoL Awesome. Quote
Astro Posted November 3, 2009 Author Posted November 3, 2009 No, i'm not getting any error message. My symbols are in modelspace. What i do, In the lisp i replaced the "C:/" by "C:/PID/" ("new" block is inside) I open the drawing containing the "old" blocks i load the lisp when i type the command on the command line, nothing seem to happen:oops: Thank you so much for your help Quote
Freerefill Posted November 3, 2009 Posted November 3, 2009 That means it's either not finding a selection set, or the selection set isn't returning a list of blocks. For some reason, I'm betting on the former. Would it be possible to upload a sample drawing so I could see what you're working with? It wouldn't need to be extravagant, just have at least three "old" blocks in the drawing. Quote
Astro Posted November 3, 2009 Author Posted November 3, 2009 In attachments a drawing containig 3 old blocks inside OLDdrawing2.dwg Quote
Freerefill Posted November 3, 2009 Posted November 3, 2009 Thanks! Made a few tweaks. First problem was what I thought: I wasn't properly getting the name of the dynamic block, so naturally it wouldn't find the file. Second thing was that I didn't include the extension when I checked to see if the file was there, so naturally it wouldn't work >>' Anyway, try this now: (defun c:blkrep2( / ss blkPth blkLst blkNam) (vl-load-com) (setq blkPth "C:/") (setq ss (ssget "X" '((410 . "MODEL")(0 . "INSERT")))) (if ss (setq blkLst (mapcar '(lambda (x) (vla-get-effectivename (vlax-ename->vla-object x))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))) (while blkLst (setq blkLst (vl-remove (setq blkNam (car blkLst)) blkLst)) (if (findfile (strcat blkPth blkNam ".dwg")) (progn (vl-cmdf "-insert" (strcat blkNam "=" blkPth blkNam ".dwg") "Y")(vl-cmdf)) ) ) (princ) ) Quote
Astro Posted November 3, 2009 Author Posted November 3, 2009 Thank you for your quick answer. I try it, but have this message now, Block TEST references itself *Invalid* Unknown command "Y". Press F1 for help. Quote
Freerefill Posted November 3, 2009 Posted November 3, 2009 That error occurs when you have a block nested within a block (say, a block "TEST" nested inside a block named "TEST"). I think it may also pop up if you try to insert a block named "TEST" inside of a drawing named "TEST," but I'm not positive on that one. Check to make sure your blocks aren't referencing themselves. That might not be the case, as I tried it and it worked for me. Also, as a tip, when dealing with blocks and replacing blocks, PURGE often! Too many times, I've tried to replace a block and gotten a slew of errors, only to find out that the old block definition was hanging around. > *EDIT* Think I got it. Do you have your blocks saved as blocks within a file of the same name as the block? That is to say, if you open up TEST.dwg, does it contain a block named TEST? *EDIT AGAIN* I did some snooping, seems this problem is common and the trick to inserting dynamic blocks is to create them using wblock. I don't really understand it as, again, I've got zero experience with dynamic blocks, but here are two links I found that should help: http://www.cadtutor.net/forum/showthread.php?t=33335 http://discussion.autodesk.com/forums/thread.jspa?threadID=749883&tstart=0 Quote
sanzoghenzo Posted August 19, 2016 Posted August 19, 2016 Hi freerefill, Thanks a lot for your great script! I faced the same problem with the block placed in a drawing with the same name. Using WBLOCK with the block selected and saving it with the same name did the trick (obviously the starting block was on a different DWG). I think only one thing is missing: calling ATTSYNC to reload all the blocks. I also removed the filter on the modelspace since I'm using it to replace the titles block on the layout. Hope this can help someone else: (defun c:blkrep2( / ss blkPth blkLst blkNam) (vl-load-com) (setq blkPth "C:/") (setq ss (ssget "X" '((0 . "INSERT")))) (if ss (setq blkLst (mapcar '(lambda (x) (vla-get-effectivename (vlax-ename->vla-object x))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))) (while blkLst (setq blkLst (vl-remove (setq blkNam (car blkLst)) blkLst)) (if (findfile (strcat blkPth blkNam ".dwg")) (progn (vl-cmdf "-insert" (strcat blkNam "=" blkPth blkNam ".dwg") "Y")(vl-cmdf)) ) ) (command "_attsync" "_Name" "*") (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.