ktbjx Posted September 27, 2018 Posted September 27, 2018 I have a stupid question, is there a way for me to change a certain hatch RGB color into another RGB color by using a lisp?? because im not changing only 1 or 2 colors, i need to change a lot RGB's. but lucky for me, the are all the same, so what im doing now is just filtering the collor i need to change, and changing them... problem is, its taking a lot of my time, thats why i am asking for a lisp, say i need to change all the REDs (255,0,0) hatch into GRAY (192,192,192), and so on.. could someone help? Quote
dlanorh Posted September 27, 2018 Posted September 27, 2018 Yes it's pretty easy using lisp, but you need to be more specific. Do you always need to change from "red" to "grey", or do you need the option to select the two colours? Do you need to change all the "red" hatches or just a selection? Quote
ktbjx Posted September 27, 2018 Author Posted September 27, 2018 19 minutes ago, dlanorh said: Yes it's pretty easy using lisp, but you need to be more specific. Do you always need to change from "red" to "grey", or do you need the option to select the two colours? Do you need to change all the "red" hatches or just a selection? yes i always need to change from red to gray and i only need to change from selections only, for me to control what needs to change, because some are already changed, and i don't want it to change again wow i didnt know its that easy. i thought its a long shot! but thank you for helping me! Quote
JuniorNogueira Posted September 27, 2018 Posted September 27, 2018 Try this: (defun c:Test (/ ss) (setq ss (ssget '((62 . 1)))) (command "_.Chprop" ss"" "_Color" "_Truecolor" "192,192,192" "") (princ) ) Not tested. Quote
dlanorh Posted September 27, 2018 Posted September 27, 2018 OK. Here is the code. This will continually ask for a "Red" Hatch to change. To exit make a null selection (click on a blank area of the screen. The code includes a local error function and adds the ability to undo all changes made in one undo. It will only change the color of "Red" hatches to "Gray". If the hatch isn't red it will ignore it. (vl-load-com) (defun c:r2g ( / *error* c_doc obj) (defun *error* ( msg ) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error occurred : " msg))) (princ) );end_defun *error* (setq c_doc (vla-get-activedocument (vlax-get-acad-object))) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (vla-startundomark c_doc) (while (setq obj (vlax-ename->vla-object (car (entsel "\nSelect Red Hatch : ")))) (if (and (wcmatch (vlax-get-property obj 'objectname) "*Hatch") (= (vlax-get-property obj 'color) 1) );end_and (vlax-put-property obj 'color 9) );end_if );end_while (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (princ) );end_defun (princ) This has been minimally tested Quote
dlanorh Posted September 27, 2018 Posted September 27, 2018 15 minutes ago, dlanorh said: OK. Here is the code. This will continually ask for a "Red" Hatch to change. To exit make a null selection (click on a blank area of the screen. The code includes a local error function and adds the ability to undo all changes made in one undo. It will only change the color of "Red" hatches to "Gray". If the hatch isn't red it will ignore it. (vl-load-com) (defun c:r2g ( / *error* c_doc obj) (defun *error* ( msg ) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error occurred : " msg))) (princ) );end_defun *error* (setq c_doc (vla-get-activedocument (vlax-get-acad-object))) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (vla-startundomark c_doc) (while (setq obj (vlax-ename->vla-object (car (entsel "\nSelect Red Hatch : ")))) (if (and (wcmatch (vlax-get-property obj 'objectname) "*Hatch") (= (vlax-get-property obj 'color) 1) );end_and (vlax-put-property obj 'color 9) );end_if );end_while (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (princ) );end_defun (princ) This has been minimally tested Ignore the above code, this is a bit neater : (vl-load-com) (defun c:r2g ( / *error* c_doc ent obj) (defun *error* ( msg ) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error occurred : " msg))) (princ) );end_defun *error* (setq c_doc (vla-get-activedocument (vlax-get-acad-object))) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (vla-startundomark c_doc) (while (setq ent (car (entsel "\nSelect Red Hatch : "))) (cond (ent (setq obj (vlax-ename->vla-object ent)) (if (and (wcmatch (vlax-get-property obj 'objectname) "*Hatch") (= (vlax-get-property obj 'color) 1) );end_and (vlax-put-property obj 'color 9) );end_if ) );end_cond );end_while (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (princ) );end_defun (princ) Quote
ktbjx Posted September 27, 2018 Author Posted September 27, 2018 (edited) 14 minutes ago, dlanorh said: Ignore the above code, this is a bit neater : (vl-load-com) (defun c:r2g ( / *error* c_doc ent obj) (defun *error* ( msg ) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error occurred : " msg))) (princ) );end_defun *error* (setq c_doc (vla-get-activedocument (vlax-get-acad-object))) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (vla-startundomark c_doc) (while (setq ent (car (entsel "\nSelect Red Hatch : "))) (cond (ent (setq obj (vlax-ename->vla-object ent)) (if (and (wcmatch (vlax-get-property obj 'objectname) "*Hatch") (= (vlax-get-property obj 'color) 1) );end_and (vlax-put-property obj 'color 9) );end_if ) );end_cond );end_while (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (princ) );end_defun (princ) yes! this is the one!!!! owh sir, what if i want to change any hatch to, say green, its RGB like 0,147,0 this Autolisp you made is so usefull! but i realized what if i wanna change the selected hatch(regardless of the color) into RGB(not the index color) like the green i was talking about? or orange? i mean, the index would be 30 right? but what i need is 255,128,0 hey! i put ; on the ;(= (vlax-get-property obj 'color) 1) and now I can change all hatch! yey! i learned a new thing today! now, how can i use RGB intead of index colors? Edited September 27, 2018 by ktbjx i added some info Quote
dlanorh Posted September 27, 2018 Posted September 27, 2018 (edited) 2 hours ago, ktbjx said: yes! this is the one!!!! owh sir, what if i want to change any hatch to, say green, its RGB like 0,147,0 this Autolisp you made is so usefull! but i realized what if i wanna change the selected hatch(regardless of the color) into RGB(not the index color) like the green i was talking about? or orange? i mean, the index would be 30 right? but what i need is 255,128,0 hey! i put ; on the ;(= (vlax-get-property obj 'color) 1) and now I can change all hatch! yey! i learned a new thing today! now, how can i use RGB intead of index colors? Index 30 is 255,127,0 . The difference between 255,127,0 and 255,128,0 are indistinguishable (see attached drawing) which is why indexes are used. Basic indexes are from 1 to 255. If this isn't good enough then you need to move to truecolor, and convert your RGB to a true color index. Autocad (my version at least) works with color indexes, truecolor indexes or color book indexes, not RGB values. Take the following code : (setq a (acad_truecolordlg 0));this calls the true color dialog with 0 as the start color Now select a color from any dialog tag and it returns a list something like this ==> ((62 . 212)) ; 62 is the color index when color selected from the colour index tab ==> ((62 . 212) (420 . 13578447)) ;420 group is the true color index when color selected from the true colour tab ==> ((62 . 191) (420 . 12557278) (430 . "PANTONE+ Solid Coated$PANTONE Violet 0631 C")); 430 is the color book and color Perhaps calling the "truecolordlg" would help in selecting the colour? colours.dwg Edited September 27, 2018 by dlanorh forgot attachment 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.