rossthompson Posted February 5, 2022 Posted February 5, 2022 Hi All, I prefer to use a white background in AutoCAD (I guess because paper is white). So often when I open drawings produced by others anything coloured yellow is hard to see and painful on the eyes. Has anyone come across a LISP routine that will instantly convert anything yellow to another nominated colour? I have found some code that changes the layer colours which is a start. But I would also like to tackle entities with a colour set to yellow as opposed to "by layer", or any yellow embedded in dimension styles, mtext etc. So by the time the routine is finished, there isn't any yellow to be seen anywhere in the DWG file! Any help would be greatly appreciated. Thanks Ross Quote
BIGAL Posted February 5, 2022 Posted February 5, 2022 Something like this change 32 to suit (setq ss (ssget "X" (list (cons 0 "LINE,LWPOLYLINE")(cons 410 "Model")))) (setq x -1) (repeat (sslength ss) (setq obj (vlax-ename->vla-object (ssname ss (setq x (1+ x))))) (vla-put-color obj 32) ) 1 Quote
rossthompson Posted February 6, 2022 Author Posted February 6, 2022 Hi Bigal, Many thanks for the code. I have tested it and it appears to only work on lines and polylines, yellow items embedded in blocks, arrays, dimensions etc. aren't altered. It also changes lines that may not have been yellow to start with. Ideally I only want to change yellow items and leave the rest on the original colour. I'm starting to realise I'm a bit out of my depth here as I haven't worked with LISP code in a while! But I would be happy to pay for an hour or so of someone's time to write this. Ross Quote
tombu Posted February 6, 2022 Posted February 6, 2022 As many still use CTB color based Plot Styles modifying colors in a drawing produced by others can cause serious issues. If you really want it to look like it will on paper why not just check "Display plot styles" in the Page Setup dialog box? I added a toggle to switch the Display of Plot Styles to my Ribbon so I can see exactly what the drawing will look like without plotting it. Slightly modified version of BlackBox's code in thread Lisp to "Display plot styles" on open. Quote
Steven P Posted February 6, 2022 Posted February 6, 2022 1 hour ago, tombu said: As many still use CTB color based Plot Styles modifying colors in a drawing produced by others can cause serious issues. Which might be an issue for some, might not be an issue for the OP. I am fairly firmly in the what-you-see-is-what-you-get side of things, yellow line on the screen plots as yellow on the paper. Often easier that way than explaining to engineers that the colours they see on Zoom shared screens are not what they will be giving out on paper to the installation people. changing this line: (setq ss (ssget "X" (list (cons 0 "LINE,LWPOLYLINE")(cons 410 "Model")))) to (setq ss (ssget "X" (list (cons 62 "Yellow Colour Code")(cons 410 "Model")))) should select all yellow coloured objects, and I say 'Yellow Colour Code' since not everyone will be using one of the basic 8 colours, might be choosing, you might find some drawings have a different 'yellow' Personally I would set everything to ByLayer in my drawings and set the colours by the layer properties (in fact one of our largest clients will reject drawings drawn otherwise). Should be a LISP out there 'set all objects to by layer'. Block entities I set to ByBlock Quote
Tharwat Posted February 6, 2022 Posted February 6, 2022 I have sent you a private message regarding this program. Quote
rossthompson Posted February 6, 2022 Author Posted February 6, 2022 Hi All, Thanks for the responses. The quality of the drawings I receive to clean up varies considerably, often they have been created in other software and exported to AutoCAD. I'm not sure the plot style route will be effective. I don't really get involved with them, as I just use AutoCAD to clean drawings for export into Sketchup to make 3D models. As Steven suggests maybe step 1 is to sort out the drawing and "set all objects to by layer". It turns out there is already a command for this: SETBYLAYER. So I could solve a lot of issues with "SETBYLAYER;all;;Yes;Yes;" which should run as a script/macro. Then I already have this code to substitute the layer colours: Quote (defun c:colorchange (/ c1 c2 ) (vl-load-com) (setq c1 (getint " What is the original color: ") c2 (getint " What is the new color: ")) (vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))(if (= c1 (vla-get-Color layer))(vla-put-Color layer c2))) (prin1) ) I'm looking to modify this, to remove the user input and always use values of: c1 = 2 (yellow), and c2 = 161 (a random blue colour I like to replace yellow with). Any help on this would be appreciated. Thanks Ross Quote
Tharwat Posted February 6, 2022 Posted February 6, 2022 Here you go . (defun c:colorchange nil (vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))(if (= 2 (vla-get-Color layer))(vla-put-Color layer 161))) (prin1) ) (vl-load-com) 3 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.