jim78b Posted February 16, 2022 Posted February 16, 2022 i need a macro or a lisp to permit to select a block, refedit and then in silent change all lines and elements color to bylayer. Then when i exit from refedit the entities color turn back on byblock. is possible with a macro? Quote
Steven P Posted February 16, 2022 Posted February 16, 2022 Trying to think how to do all this in a single routine, I assume while you are editing the block you are changing it, not just opening the block, seeing all the elements change colour, close the block and see the elements go back to ByBlock. The tricky part is editing the block and then setting the elements back to byblock when you close the block. You can do this with 2 LISPS I reckon, one to open the block to edit, ssget all the block elements and set them to bylayer, and then a second LISP once you have edited the block to set the elements to byblock, save and close the block editor... but a single LISP could be tricky. Quote
mhupp Posted February 16, 2022 Posted February 16, 2022 (edited) Correct me if I'm wrong but i don't think you can do this in just one lisp. because you can only run one lisp at a time. This is half of it just don't know how to change everything back to byblock before exit. ssget "_x" maybe? everything outside block won't get changed. this lisp will ask you to select a block to change its colors and refedit that block. You have to use the command again to save/exit if you want the colors to change back. or You could set up a reactor. (defun C:BlkEdit (/ Drawing ent blk) (vl-load-com) (setq Drawing (vla-get-activedocument (vlax-get-acad-object))) (if (/= (getvar 'refeditname) "") (progn (setq blk (vla-item (vla-get-blocks Drawing) (getvar 'refeditname))) (vl-cmdf "_.Refclose" "S") (vlax-for x blk (vla-put-Color x 0) ) (vla-Regen Drawing acAllViewports) ) (progn (if (eq (cdr (assoc 0 (setq ent (entget (car (entsel "\nSelect Blocks")))))) "INSERT") (progn (setq blk (vla-item (vla-get-blocks Drawing) (cdr (assoc 2 ent)))) (vlax-for x blk (vla-put-Color x 256) ) (sssetfirst nil (ssadd (cdr (assoc -1 ent)))) (vl-cmdf "-REFEDIT" "O" "A" "N") ) (Prompt "\nNothing Selected") ) ) ) (princ) ) Edited February 16, 2022 by mhupp 1 Quote
jim78b Posted February 16, 2022 Author Posted February 16, 2022 (edited) Yes right when i will exit from refedit i think load another routine .tomorrow i will try. But this lisp must chance in automatic color to bylayer when i refedit i hope?....thanks for your big help Edited February 17, 2022 by jim78b Quote
jim78b Posted February 17, 2022 Author Posted February 17, 2022 hello thanks i tried your code work perfectly! for exit from refedit and set all color to byblock can i make a macro right? Quote
mhupp Posted February 17, 2022 Posted February 17, 2022 38 minutes ago, jim78b said: hello thanks i tried your code work perfectly! for exit from refedit and set all color to byblock can i make a macro right? Just run the same macro to exit. 1 Quote
jim78b Posted February 17, 2022 Author Posted February 17, 2022 Sorry but i did it with no success. All my block return to byblock but the color that i assigned (purple) is turned on byblock. Another request if possible ...can you edit the code even with line and line scale to return bylayer ? Thanks a lot Quote
Steven P Posted February 17, 2022 Posted February 17, 2022 (edited) I am not brilliant at VLA, however in mhupps code above he has this which is the settings when you exit the refedit (if (/= (getvar 'refeditname) "") (progn (setq blk (vla-item (vla-get-blocks Drawing) (getvar 'refeditname))) (vl-cmdf "_.Refclose" "S") (vlax-for x blk (vla-put-Color x 0) ) (vla-Regen Drawing acAllViewports) ) If you add the settings you want in this part of the code then that should set up what you want as you exit. (vlax-for x blk (vla-put-Color x 0) ;; - ADDING THIS FOR LINETYPE AS AN EXAMPLE. THE LINE TYPE HAS TO BE LOADED FOR THIS TO WORK (vla-put-Linetype x "DASHDOT") ;; ) vla-put-Color x 0, change the '0' for the colour code you want if you want it all to be purple. I think vla-put-linetypescale doeslinetype scale... follow the above to add that in. Pretty sure I am going to be corrected in a moment or 2, but try that as a start Edited February 17, 2022 by Steven P 1 Quote
jim78b Posted February 17, 2022 Author Posted February 17, 2022 Ok thanks but must have i add this code in which point ? Have nice day Quote
mhupp Posted February 17, 2022 Posted February 17, 2022 (edited) On 2/16/2022 at 11:32 AM, jim78b said: Then when i exit from refedit the entities color turn back on byblock. if you want to ignore a color and set everything else back to byblock. (vlax-for x blk (if (/= (vla-get-color x) #) ;if not color purple # change it back to byblock (vla-put-Color x 0) ) (vla-put-linetype x "ByLayer") ;line type must be loaded to work (vla-put-linetypescale x #) ) 6 hours ago, Steven P said: I am not brilliant at VLA, ... Same, coming here each day is mostly to learn from everyone and have some light bulb moments from time to time if I'm lucky. just so happened to have this lisp already made up just had to edit it a little bit. Edited February 17, 2022 by mhupp 2 Quote
jim78b Posted February 17, 2022 Author Posted February 17, 2022 THANKS TO ALL you are the best! Quote
jim78b Posted March 12, 2022 Author Posted March 12, 2022 (edited) Cancel Edited March 17, 2022 by jim78b Quote
jim78b Posted March 13, 2022 Author Posted March 13, 2022 (edited) sorry mhupp last question .does this code work with nested blocks ? Edited March 17, 2022 by jim78b Quote
jim78b Posted March 18, 2022 Author Posted March 18, 2022 Please can you you make it work with nested blocks ?have a nice day Quote
mhupp Posted March 18, 2022 Posted March 18, 2022 5 minutes ago, jim78b said: Please can you you make it work with nested blocks ?have a nice day update this line of code. (if (eq (cdr (assoc 0 (setq ent (entget (car (nentsel "\nSelect Blocks")))))) "INSERT") ;entsel to nentsel aka nested entsel 1 Quote
jim78b Posted March 18, 2022 Author Posted March 18, 2022 Thanks your help is precious. Now i must pay !! Quote
mhupp Posted March 18, 2022 Posted March 18, 2022 Donate to the website I just do this for fun, self learning, and to kill time. Oh and fake internet points. 1 Quote
jim78b Posted March 18, 2022 Author Posted March 18, 2022 sorry i edit but don't work give me: Select Blocks Nothing Selected (defun C:BlkEdit (/ Drawing ent blk) (vl-load-com) (setq Drawing (vla-get-activedocument (vlax-get-acad-object))) (if (/= (getvar 'refeditname) "") (progn (setq blk (vla-item (vla-get-blocks Drawing) (getvar 'refeditname))) (vl-cmdf "_.Refclose" "S") (vlax-for x blk (vla-put-Color x 6) ) (vla-Regen Drawing acAllViewports) ) (progn (if (eq (cdr (assoc 0 (setq ent (entget (car (nentsel "\nSelect Blocks")))))) "INSERT") ; (progn (setq blk (vla-item (vla-get-blocks Drawing) (cdr (assoc 2 ent)))) (vlax-for x blk (vla-put-Color x 256) ) (sssetfirst nil (ssadd (cdr (assoc -1 ent)))) (vl-cmdf "-REFEDIT" "O" "A" "N") ) (Prompt "\nNothing Selected") ) ) ) (princ) ) Quote
mhupp Posted March 18, 2022 Posted March 18, 2022 That was a lot more work then I thought. Used some of danallen code. had to add in another "n" to get to the right nested block. this will go 6 nest deep. but im sure you could make that dynamic somehow. Used the repeat command! (defun C:BlkEdit (/ Drawing e ent blk blkname nest) (vl-load-com) (setq Drawing (vla-get-activedocument (vlax-get-acad-object))) (if (/= (getvar 'refeditname) "") (progn (setq blk (vla-item (vla-get-blocks Drawing) (getvar 'refeditname))) (vl-cmdf "_.Refclose" "S") (vlax-for x blk (vla-put-Color x 6) ) (vla-Regen Drawing acAllViewports) ) (progn (if (setq e (nentselp "\nSelect Block: ")) (progn (if (and (> (length e) 2) (setq blkname (cdr (assoc 2 (entget (car (last e))))))) (progn (setq blk (vla-item (vla-get-blocks Drawing) blkname)) (vlax-for x blk (vla-put-Color x 256) ) ) (Prompt "\nNot A Block") ) (setq nest (length (cadddr e))) (setvar 'cmdecho 0) (command "refedit" (cadr e)) (repeat (- nest 1) (command "n") ) (command "ok" "all" "y") (setvar 'cmdecho 1) ) (Prompt "\nNothing Selected") ) ) ) (princ) ) Quote
jim78b Posted March 18, 2022 Author Posted March 18, 2022 (edited) yes i understand, i need that after open block i see all object inside bylayer even nested block. Edited March 18, 2022 by jim78b 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.