Steven P Posted December 27, 2021 Posted December 27, 2021 On 12/24/2021 at 12:32 AM, vuxvix said: Hi! @ Lee Mac @ dlanorh i am looking for a solution for changing the color of the objects in the block. I have tried both lisp (CTA, Blockprops). Both lisp do not change color : By layer to by block. I put up an example of the blocks I'm working on. Looking forward to help, Thanks Blocknotworking.dwg 73.68 kB · 0 downloads This will change attribute colours http://www.lee-mac.com/attributecolour.html - My CAD is off for the holidays so not sure if this will help you? Quote
vuxvix Posted December 27, 2021 Posted December 27, 2021 Hi @Steven P Thanks for the reply. Unfortunately, it doesn't work for . as you look, it works for ATT in block. Hp new year! Quote
Steven P Posted December 28, 2021 Posted December 28, 2021 (edited) You could try this: "attred" and will set the block objects to colour "10" (red), however it won't change any nested blocks definitions, just change their colour (so if that nested block is drawn using Green lines it will show as green, if it is drawn using "ByBlock" coloured lines it will show as red (or whatever colour you set this to be) Please note that I copied and pasted a lot of this but I didn't note where I took the original parts from, if the originator reads this, thanks I use this all the time, but let me know so I can credit you accordingly. (defun c:attred (/ myblocklayer myblockcolour myblocklineweight myblocklinetype) (setq myblocklayer "0") (setq myblockcolour 10) (setq myblocklineweight aclnwtbyblock) (setq myblocklinetype "byblock") (mynorm myblocklayer myblockcolour myblocklineweight myblocklinetype) (princ) ) (defun mynorm (myblocklayer myblockcolour myblocklineweight myblocklinetype / *error* adoc lst_layer func_restore-layers) (defun *error* (msg) (func_restore-layers) (vla-endundomark adoc) (princ msg) (princ) ) ;_ end of defun (defun func_restore-layers () (foreach item lst_layer (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))) (vl-catch-all-apply '(lambda () (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))) ) ;_ end of vla-put-freeze ) ;_ end of lambda ) ;_ end of vl-catch-all-apply ) ;_ end of foreach ) ;_ end of defun (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ) ;_ end of vla-startundomark (if (and (not (vl-catch-all-error-p (setq selset (vl-catch-all-apply (function (lambda () (ssget '((0 . "INSERT"))) ) ;_ end of lambda ) ;_ end of function ) ;_ end of vl-catch-all-apply ) ;_ end of setq ) ;_ end of vl-catch-all-error-p ) ;_ end of not selset ) ;_ end of and (progn (vlax-for item (vla-get-layers adoc) (setq lst_layer (cons (list item (cons "lock" (vla-get-lock item)) (cons "freeze" (vla-get-freeze item)) ) ;_ end of list lst_layer ) ;_ end of cons ) ;_ end of setq (vla-put-lock item :vlax-false) (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)) ) ;_ end of vl-catch-all-apply ) ;_ end of vlax-for (foreach blk_def (mapcar (function (lambda (x) (vla-item (vla-get-blocks adoc) x) ) ;_ end of lambda ) ;_ end of function ((lambda (/ res) (foreach item (mapcar (function (lambda (x) (vla-get-name (vlax-ename->vla-object x) ) ;_ end of vla-get-name ) ;_ end of lambda ) ;_ end of function ((lambda (/ tab item) (repeat (setq tab nil item (sslength selset) ) ;_ end setq (setq tab (cons (ssname selset (setq item (1- item)) ) ;_ end of ssname tab ) ;_ end of cons ) ;_ end of setq ) ;_ end of repeat tab ) ;_ end of lambda ) ) ;_ end of mapcar (if (not (member item res)) (setq res (cons item res)) ) ;_ end of if ) ;_ end of foreach (reverse res) ) ;_ end of lambda ) ) ;_ end of mapcar (vlax-for ent blk_def ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Sets the block attributes ;;add in here other attributes to change (vla-put-layer ent myblocklayer) (vla-put-color ent myblockcolour) (vla-put-lineweight ent myblocklineweight) ;; (vla-put-linetype ent myblocklinetype) ;;end of setting up block attributes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ) ;_ end of vlax-for ) ;_ end of foreach (func_restore-layers) (vla-regen adoc acallviewports) ) ;_ end of progn ) ;_ end of if (vla-endundomark adoc) (princ) ) ;_ end of defun Edited December 28, 2021 by Steven P 2 Quote
vuxvix Posted January 3, 2022 Posted January 3, 2022 Hi! Steven P Thank you for this lisp. I tried using it and it works as expected. I have 2 problems with this lisp: -Because the desired color is not 10. I tried fixing: (setq myblockcolour 10) to (setq myblockcolour "ByBlock"). but it doesn't work. I think setting it to by block is easier to customize. Is that possible!? -The block I sent in the example does not contain nested blocks. So why can't it change the color using McLee and Dlanorh's lisp? Thanks, have a good new year Quote
vuxvix Posted January 4, 2022 Posted January 4, 2022 CAN YOU BE MORE SPECIAL INSTRUCTIONS, I HAVE NO EXPERIENCE WITH LISP Quote
mhupp Posted January 4, 2022 Posted January 4, 2022 (edited) 3 hours ago, vuxvix said: CAN YOU BE MORE SPECIAL INSTRUCTIONS, I HAVE NO EXPERIENCE WITH LISP You understand that (setq myblockcolour 10) is red and want to change it to Byblock? lisp typically only use numbers for colors. You can see all the different colors #'s use this. (acad_colordlg 1) Their are also 7 colors you can call by their name like red, yellow, green, cyan, blue, magenta, white @BIGAL is giving you the answer. (setq myblockcolour 0) ;= Byblock (setq myblockcolour 256) ;= Bylayer (setq myblockcolour (acad_colordlg 1)) ;user can pick the color each time the lisp is ran Edited January 4, 2022 by mhupp 2 1 Quote
vuxvix Posted January 4, 2022 Posted January 4, 2022 Hi! I added your function snippet and it worked as expected. Thank you very much! Ps: I understand it's a suggestion by Bigal. But it is only valid for those who understand about lisp. Quote
Steven P Posted January 4, 2022 Posted January 4, 2022 1 hour ago, vuxvix said: Hi! I added your function snippet and it worked as expected. Thank you very much! Ps: I understand it's a suggestion by Bigal. But it is only valid for those who understand about lisp. But here is a great place to learn a bit more about it 1 2 Quote
Ahmed_Hisham Posted February 22 Posted February 22 Hi @Tharwat @Lee Mac @dlanorh @mhupp Lets say I have a normal Block containing a dimension inside it then I modified the dimstyle but the changes don't apply to the dimensions inside this block till i open the block editor the dimensions get updated. My Question here is there any lisp to apply dimstyle update to dimensions inside ablock without entering the block itself or selecting the dimensions even if they are inside the block and apply the dimstyle update myself ? Thanks for you support Ahmed Hisham 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.