jim78b Posted January 18 Posted January 18 (edited) hello please i need change this lisp because i want after execute it change only blocks and not dimensions (defun c:AllToByBlock (/ doc) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-IsLayout b) (vla-get-IsXref b)) (vlax-for o b (vla-put-Color o 0) ) ) ) (vla-regen doc acAllViewports) (princ) ) Edited January 18 by jim78b Quote
pkenewell Posted January 18 Posted January 18 (edited) @jim78b Try this: (defun c:AllToByBlock (/ doc) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for b (vla-get-Blocks doc) (if (= :vlax-false (vla-get-IsLayout b) (vla-get-IsXref b)) (vlax-for o b (if (not (wcmatch (vla-get-objectname o) "*Dimension")) (vla-put-Color o 0) ) ) ) ) (vla-regen doc acAllViewports) (princ) ) Edited January 19 by pkenewell 1 Quote
jim78b Posted January 18 Author Posted January 18 Ok thanks tomorrow i will try and tell you. Best regards Quote
Tharwat Posted January 19 Posted January 19 @pkenewell you called the vla-get-activedocument two times. Quote
jim78b Posted January 19 Author Posted January 19 SORRY don't work because change again the dimension line and text color Quote
jim78b Posted January 19 Author Posted January 19 (defun c:Atbk (/ doc b o SS blk) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (if (/= (vl-string-elt (vla-get-name b) 0) 42) (vlax-for o b (vla-put-Color o 0) ;change all elements inside block to byblock ) ) ) (if (setq SS (ssget "_X" '((0 . "INSERT")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq blk (vlax-ename->vla-object blk)) (vla-put-Color blk 200) ) ) (vla-regen doc acAllViewports) (princ) ) this work with dimension lines but not work for dynamic blocks! Quote
jim78b Posted January 19 Author Posted January 19 (edited) (defun c:AB (/ blk doc obj SS) (vl-load-com) (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (vlax-for blk (vla-get-Blocks doc) (if (and (= (vla-get-isxref blk) :VLAX-FALSE) ;ignores xrefs (not (wcmatch (vla-get-name blk) "*`**,*|*")) ;ignores anonymous and xref blocks ) (vlax-for obj blk (vla-put-Color obj 0) ;change all elements inside block to byblock ) ) ) (if (setq SS (ssget "_X" '((0 . "INSERT")))) (foreach blk (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (vla-put-Color blk 200) ;added another mapcar to line above to convert at the list level from ename to vla-object ) ) (vla-regen doc acAllViewports) (vla-EndUndoMark doc) (princ) ) tHIS ROUTINE WAS PERFECT but not work with dynamic bloks and anonymous! can you resolve it? please Edited January 19 by jim78b Quote
pkenewell Posted January 19 Posted January 19 (edited) 6 hours ago, Tharwat said: @pkenewell you called the vla-get-activedocument two times. @Tharwat Oops - your right. I just altered the original routine and didn't check. I updated my post. @jim78b Be more specific on your post. My alteration to your routine just excludes dimensions from the changing of the color that you had in your original. Now I don't really understand exactly what you want. Post a sample drawing with the before and after. Edited January 19 by pkenewell 1 Quote
pkenewell Posted January 19 Posted January 19 @jim78b I mean an actual DWG file, not screenshots. Quote
pkenewell Posted January 19 Posted January 19 (edited) @jim78b OK - I see. you have nested blocks within nested dynamic blocks. You need some kind of recursive function to drill all the way down. Not sure if I can help, but I'll give it a try as soon as I have some time. For now, you can open up one of each of the dynamic clocks in refedit and run your command again and they will be done. Open the main block first with double click, then open the dynamic blocks with double-click and run AB on each of them. Edited January 19 by pkenewell 1 Quote
jim78b Posted January 19 Author Posted January 19 I appreciate your help but I would like it to be done automatically the first time... is it difficult? Quote
pkenewell Posted January 19 Posted January 19 (edited) @jim78b I don't know. I just don't deal with dynamic blocks so I am not sure why its not already working. I'm just missing something that maybe someone else here knows better? Edited January 19 by pkenewell 1 Quote
pkenewell Posted January 19 Posted January 19 I can see this isn't the first time you have been asking about this: Quote
pkenewell Posted January 19 Posted January 19 (edited) OK - found something. I did some searching on earlier solutions to the problem. Try this code - it's working for me. It could be made shorter I think, but it works (use the code below, not the link). Credit to Roy_043 from this post: (defun c:AB (/ blk doc i obj SS) (vl-load-com) (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (vlax-for blk (vla-get-Blocks doc) (if (and (= (vla-get-isxref blk) :VLAX-FALSE) ;ignores xrefs (not (wcmatch (vla-get-name blk) "*`**,*|*")) ;ignores anonymous and xref blocks ) (vlax-for obj blk (vla-put-Color obj 0) ;change all elements inside block to byblock ) ) ) (if (setq SS (ssget "_X" '((0 . "INSERT")))) (repeat (setq i (sslength ss)) (ChangeDynBlockColor (vla-get-name (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))) 0) (vla-put-color obj 200) ) ) (vla-regen doc acAllViewports) (vla-EndUndoMark doc) (princ) ) ; Blk can be a block name or the ename of a "BLOCK" entity. (defun KGA_BlockClassic_EffectiveName (blk / elst blkRecHnd) (setq elst (entget (if (= 'ename (type blk)) blk (tblobjname "block" blk)))) (if (and (= "*" (substr (cdr (assoc 2 elst)) 1 1)) (setq blkRecHnd (cdr (assoc 1005 (cdadr (assoc -3 (entget (cdr (assoc 330 elst)) '("AcDbBlockRepBTag"))))))) ) (cdr (assoc 2 (entget (handent blkRecHnd)))) (cdr (assoc 2 elst)) ) ) ; (ChangeDynBlockColor (vla-get-name (vlax-ename->vla-object (car (entsel)))) (acad_colordlg 2)) (defun ChangeDynBlockColor (nme col / N_Mod blks i nmeLst) (defun N_Mod (blk) (vlax-for obj blk (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (not (vl-position (strcase (vla-get-effectivename obj)) nmeLst)) ) (setq nmeLst (append nmeLst (list (strcase (vla-get-effectivename obj))))) ; Append required. (vla-put-color obj col) ) ) ) (setq blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (setq nmeLst (list (strcase (KGA_BlockClassic_EffectiveName nme)))) (setq i 0) (while (< i (length nmeLst)) (setq nme (nth i nmeLst)) (vlax-for blk blks (if (= nme (strcase (KGA_BlockClassic_EffectiveName (vla-get-name blk)))) (N_Mod blk) ) ) (setq i (1+ i)) ) ) Edited January 19 by pkenewell 1 Quote
pkenewell Posted January 19 Posted January 19 8 minutes ago, jim78b said: wonderful you are the best!!! thanks a lot! @jim78b OOPS - I made a slight change to the routine above. Re-copy it from the post. I realized it changes everything to color 200, rather than changing everything inside blocks to ByBlock. corrected. 1 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.