Jump to content

Recommended Posts

Posted

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

Posted

(setq CLRNUM (getint "\nEnter color number or press \"Enter\" to select: ")) ;Get color number

 

maybe

Posted
(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.

Posted (edited)
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

Edited by fabriciorby
Posted

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

Posted
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

 

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.

Posted

(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.

Posted
(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.

Posted

I posted an example from the command line:

 

 

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.

 

 

 

 

In lisp, simpler:

 

;Move by Color
(defun c:[b]mbc[/b] ()
   (command "_MOVE" (clr) "" pause)
)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...