Select by Color - TIP 1046
I tried to get the following LISP routine to run. However, I was trying to locate the error but without success and I would like that someone can help me please:;TIP1046.LSP: CLR.LSP Select by Color (C)1994, Grant Kiba;Collection function;--------------------------------------------------------------------(defun collect (E1) ;Define the collection funtion(if (= c nil) ;Set if no selection set(setq C(ssadd E1)) ;THEN ;Then create the set(setq C(ssadd E1 C)) ;ELSE ;or add this object to the current set);end if);end defun;Color selection function;-------------------------------------------------------------------(defun clr (/ A B C COUNT NUM CLRLAY) ;Define function(setq COUNT 0) ;Set counter to 0(initget 6) ;Don't negative values(princ "\nRed=1,Yellow-2,Green=3,Cyan=4,Blue=5,Magenta=6,White=7,Byblock=0")(setq CLRNUM (getint"\nEnter color number or press \"Enter\" to select: ")) ;Get color number(if(= CLRNUM nil)(progn(initget 1)(setq SAMPLE (entget(car(entsel "\nSelect object /w color to filter: "))))(if (null (assoc 62 SAMPLE))(progn ;THEN(setq LAY(cdr(assoc 8 SAMPLE)))(setq CLRNUM(cdr(assoc 62 (tblsearch "layer" LAY)))));end progn(setq CLRNUM (cdr (assoc 62 SAMPLE))) ;ELSE);end if);end progn);end if(setq MSG (strcat "\nFiltering color #" (itoa CLRNUM)))(princ MSG)(princ "\nWindow or select objects to filter then press \"Enter\"")(while (null A)(setq A (ssget)) ;Get initial selection(if (null A) (princ "No objects to filter! Select again or ^C to abort.")));end while(setq NUM (sslength A)) ;Get number of objects selected(while (< COUNT NUM)(setq B (entget (ssname A COUNT))) ;Get entity list(if (/= (assoc 62 B) nil) ;If the object has a color;THEN(if (equal (assoc 62 B) (cons 62 CLRNUM)) ;If the color matches(collect (ssname A COUNT)) ;Then Collect object);end if;ELSE ;Else get object's layer(progn(setq LAY(cdr(assoc 8 B)))(setq CLRLAY(cdr(assoc 62 (tblsearch "layer" LAY))))(if (= CLRNUM CLRLAY) ;If the layer matches color(collect (ssname A COUNT)) ;Collect the object);end if);end progn);end if(setq COUNT (+ 1 COUNT)) ;Check next object in set);end while(if (null C)(progn(command "")(princ "No objects match filter color!")(princ));end progn(setq X C) ;Sends the selection set to the current commad);end if);end clr.lsp (setq CLRNUM (getint "\nEnter color number or press \"Enter\" to select: ")) ;Get color number
maybe
I think it has to do with the parentheses but where I don't know.
No, haha
In your code it is (getint"\nEnter...
Maybe you just need to get a space there like (getint "\nEnter...
edit: nvm, it works even without space First off, that is a horribly written routine.
So don't blame yourself for having difficulties in debugging it.
Basic question:
Do you to make a selection based on the group 62 number value a user enters?
or
Do you want to make selection of entities that match the color of a user picked entity?
-David
I'm sorry I didn't looked at that space in your reply.
However, I don't get it work and still don't know why. (defun c:clr (/ A B C COUNT............
.............
.............
.............
(setq X C) ;Sends the selection set to the current commad
.............
.............
(i.e.)
Command: MOVE
Select object: 'clr
Red=1,Yellow-2,Green=3,Cyan=4,Blue=5,Magenta=6,White=7,Byblock=0
Enter color number or press "Enter" to select: 3
Filtering color #3
Window or select objects to filter then press "Enter"
etc.
etc.
Thank you very much for your effort! However, now it's getting complicated for me and I get lost.
I put that c: after defun but where exactly the rest goes I don't know. I posted an example from the command line:
In lisp, simpler:
;Move by Color(defun c:mbc () (command "_MOVE" (clr) "" pause))
页:
[1]