gazzalp Posted January 21, 2009 Share Posted January 21, 2009 Guys, i quite often have to draw lines on a certain layer, but then have to change the colour of half of them as i go, so rather then select the line, go up to the colour drop down and select the colour, i want a lisp where i can select the line, type in the number that represents the colour (ie: 1 = red, 2 = yellow) and it will change the line. I dont want it to change the colour of the layer so that everything i draw from then on will be that colour, but just change the colour of any entities i currently have selected. Im sure it would be a pretty easy lisp. one thing im not sure about is if i could have all the colours in one lisp, or if id need a new lisp for each colour. Thanks for your help Quote Link to comment Share on other sites More sharing options...
Attila The Gel Posted January 21, 2009 Share Posted January 21, 2009 Don't know anythin about lisps but if you wan't you can just change one lines color and use matchprop to do the other ones in the same color. The problem is if you want an other color you have to do it over again, but its still faster! If you do this thing allot like you say then maybe a lisp be better! Quote Link to comment Share on other sites More sharing options...
gazzalp Posted January 21, 2009 Author Share Posted January 21, 2009 I know about the match properties command, but it still takes longer then i want - id have to go up to the toolbar, select the button, select the entity i want the line matched to, then select the line. And as you said if nothing is already that colour then that wont work. A lisp however will only require me to touch one button on the keyboard. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted January 21, 2009 Share Posted January 21, 2009 Here is simple 1. Change the term layer_name to layer that you want to change. It will allow to select LINEs on that LAyer only. As many as you want: [b][color=BLACK]([/color][/b]defun c:clc [b][color=FUCHSIA]([/color][/b]/ ss clr[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"LINE"[/color][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 8 layer_name[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]if [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"CTAB"[/color][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cons 410 [b][color=PURPLE]([/color][/b]getvar [color=#2f4f4f]"CTAB"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cons 67 [b][color=PURPLE]([/color][/b]- 1 [b][color=TEAL]([/color][/b]getvar [color=#2f4f4f]"TILEMODE"[/color][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]not clr[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq clr [b][color=GREEN]([/color][/b]acad_colordlg 1[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]command [color=#2f4f4f]"_.CHPROP"[/color] ss [color=#2f4f4f]""[/color] [color=#2f4f4f]"_C"[/color] clr [color=#2f4f4f]""[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 21, 2009 Share Posted January 21, 2009 One courtesy of CAB: (defun c:cc (/ usercol ss) (while (not (setq usercol (acad_colordlg 256)))) (prompt "Select all object to change to one color.") (if (setq ss (ssget)) (command "_.ChProp" ss "" "_C" usercol "")) (princ)) Quote Link to comment Share on other sites More sharing options...
gazzalp Posted January 21, 2009 Author Share Posted January 21, 2009 Thanks Lee, not exactly what i wanted. rather than the autocad window coming up and asking what colour i wanted id like to be able to select a line, type "1" and have autocad change the line colour to 1 (red). Same for colour 2 up to about 8. Is this possible? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 21, 2009 Share Posted January 21, 2009 Yes, very possible: (defun c:cc (/ usercol ss) (while (or (not (setq usercol (getint "\nSpecify Colour Code > "))) (not (<= 0 usercol 256)))) (prompt "Select all object to change to one color.") (if (setq ss (ssget)) (command "_.ChProp" ss "" "_C" usercol "")) (princ)) Quote Link to comment Share on other sites More sharing options...
CarlB Posted January 21, 2009 Share Posted January 21, 2009 I think what the OP would like to do is highlight an object, then type the number of the color to change to. No prompts. So you would need to have lisps loaded "c:1.lsp c:2.lsp etc" that would run on the pre-selected (highlighted) objects. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 21, 2009 Share Posted January 21, 2009 I think what the OP would like to do is highlight an object, then type the number of the color to change to. No prompts. So you would need to have lisps loaded "c:1.lsp c:2.lsp etc" that would run on the pre-selected (highlighted) objects. Hmm.. possibly. I was under the impression he/she was satisfied to run the LISP then type the colour? You may be right Carl. Quote Link to comment Share on other sites More sharing options...
jammie Posted January 21, 2009 Share Posted January 21, 2009 Maybe something like this Type LC to load the command ;;Description ;; Define multiple commands to change an objects color ;; EG C:1 Changes the object color to 1 ;; C:2 Changes the object color to 2... (defun c:lc () ;;Add or remove color integers from the li_clr ;;Every valid color found in li_clt will be define as a command (setq li_clr (list 1 2 3 4 5 6 7 );This assigns colors 1 - 8 as a command (foreach n li_clr (if ;;If the the color is a valid acad color (<= 0 n 256) (progn ;convert the color to a string (setq int (itoa n)) ;Step 3 - Evaluate the expression & define the command (eval ;Step 2 - Convert the command string to an expression (read ;Step 1 - Define the command (strcat "(defun c:" int " () (command \"chprop\" (ssget) \"\" \"c\"" int " \"\"))")) ) ) ) ) ) ( Thats very useful Lee, couldn't quiet figure out a clean way of coding the test Regards, Jammie Quote Link to comment Share on other sites More sharing options...
CarlB Posted January 21, 2009 Share Posted January 21, 2009 Here's my contribution, example lisp to change selected items to color 1 (red): (defun c:1 () (if (setq p1 (cadr (ssgetfirst))) (progn (sssetfirst) (command "chprop" p1 "" "C" 1 "")) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 21, 2009 Share Posted January 21, 2009 Nice idea Carl - not actually including the selection process in the LISP - I like it. Quote Link to comment Share on other sites More sharing options...
gazzalp Posted January 21, 2009 Author Share Posted January 21, 2009 Thanks carl and lee, that last code from carl works well, exactly what i wanted, thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 21, 2009 Share Posted January 21, 2009 No Probs - nice one Carl. Quote Link to comment Share on other sites More sharing options...
totzky Posted January 25, 2009 Share Posted January 25, 2009 Dear Friends, Please take a look at what I've done. It certainly needs improvement. (defun c:cc (/ testOBJ surface 3dsolid oldUCS colchoice ss ) (defun *error* (msg) (if (= (getvar "cmdecho") 0) (setvar "cmdecho" 1)) (princ) ); end error function ;Select target color loop. (while (not (setq colchoice (acad_colordlg 256)))) ;Select Entity for color change loop. (while (not (setq ss (entsel (strcat"\nCustom command change color; target color number " "<" (rtos colchoice) ">" ":")) );end setq );end not );end while ;Test Object selected is surface or 3dsolid. (setq testOBJ (entget (car ss))) (if (= (cdr (assoc 0 testOBJ)) "POLYLINE") (setq surface ss));if object is surface (if (= (cdr (assoc 0 testOBJ)) "3DSOLID") (progn (setq 3dsolid ss);if object is solid (princ "\nHow will I do this?") ;;;<<<---------How? (quit) );end progn );end if (setvar "cmdecho" 0) ;If Object selected is surface and color choice is ByBlock. (if (and (/= surface nil) (or (= colchoice 0) (= colchoice "ByBlock")) );end and (progn (vl-cmdf "_change" surface "" "_p" "_c" "ByBlock" "") (quit) );end progn );end if ;If Object selected is surface and color choice is ByLayer. (if (and (/= surface nil) (or (= colchoice 256) (= colchoice "ByLayer")) );end and (progn (vl-cmdf "_change" surface "" "_p" "_c" "ByLayer" "") (quit) );end progn );end if ;;If Object selected is surface and color choice is in the range 1-255. (if (and (/= surface nil) (< colchoice 256) );end and (progn (vl-cmdf "_change" surface "" "_p" "_c" colchoice "") (quit) );end progn );end if ;Mark Current UCS. (if (not (tblsearch "UCS" "oldUCS")) (setq oldUCS (command "_.ucs" "_s" "oldUCS" )); do this (setq oldUCS (command "_.ucs" "_s" "oldUCS" "_yes")); else do this );end if ;If Colchoice is ByBlock. (if (or (= colchoice 0) (= colchoice "ByBlock")) (progn (command "_.ucs" "_ob" ss) (vl-cmdf "_change" ss "" "_p" "_c" "ByBlock" "") (command "_.ucs" "_p" ) (command "_.ucs" "_Del" "oldUCS") (setvar "cmdecho" 1) (quit) );end progn );end if ;If colchoice is ByLayer. (if (or (= colchoice 256) (= colchoice "ByLayer")) (progn (command "_.ucs" "_ob" ss) (vl-cmdf "_change" ss "" "_p" "_c" "ByLayer" "") (command "_.ucs" "_P") );end progn );end if ;If colchoice is in the range 1 to 255. (if (< colchoice 256) (progn (command "_.ucs" "_ob" ss) (vl-cmdf "_change" ss "" "_p" "_c" colchoice "") (command "_.ucs" "_P") );end progn );end if (command "_.ucs" "_Del" "oldUCS") (setvar "cmdecho" 1) (princ) );end function cc Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 25, 2009 Share Posted January 25, 2009 Do you really need that much coding just to change the colour... Quote Link to comment Share on other sites More sharing options...
totzky Posted January 26, 2009 Share Posted January 26, 2009 Do you really need that much coding just to change the colour... Not really, its just my way of saying that Carl's code does not seem to work with objects belonging to different ucs. Also, with 3d solid. Anybody have any ideas on how to do these? Quote Link to comment Share on other sites More sharing options...
totzky Posted January 26, 2009 Share Posted January 26, 2009 Please bear with an absolute beginner! For practice purposes only. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 26, 2009 Share Posted January 26, 2009 I'll have a look Quote Link to comment Share on other sites More sharing options...
StevJ Posted January 27, 2009 Share Posted January 27, 2009 Here's one I found on this forum some time ago, and seems to be what you're looking for. The author and source location is in the code box. I changed the name to CC (red text), but otherwise it's as posted. Steve ;by rkmcswain/6th Feb 2006 ;http://www.cadtutor.net/forum/showpost.php?p=34278&postcount=2 ; ;Color number can be considered a command. ;Enter color number, pick your items; Enter. ;If you have Right-click set to repeat last command, it works that way as well. ;Does not do BYLAYER or BYBLOCK (defun [color=red][b]CC[/b][/color] (color / ss1) (setq ss1 (ssget)) (command "._change" ss1 "" "p" "c" color "" ) ) (setq i 1) (while (<= i 254) (eval (read (strcat "(defun c:" (itoa i) (chr 40)(chr 41) "([color=red][b]CC[/b][/color] " (itoa i) "))"))) (setq i (1+ i)) ) Quote Link to comment Share on other sites More sharing options...
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.