Jump to content

Recommended Posts

Posted

Hi all,

 

I have looked around, but I am struggling to find what I need.

I am comfortable with recording, writing, running scripts however I can't find how to use quick select with scripts?

 

Do I have to use a lisp routine to achieve what I want, then run the lisp from my script?

 

All I really want to do in one batch is;

Select all Blue items on the "Items" layer and move them to the "Blue Items" Layer

Select all Red items on the "Items" layer and move them to the "Red Items" Layer

Select all Green items on the "Items" layer and move them to the "Green Items" Layer

 

If someone could point me in the right direction (or to a lisp that I can modify for instance), I would truly appreciate it.

 

Thanks in advance.

Posted

AutoLISP is AutoCAD's programming language. You can search on how to use and run it.

 

Once you've got that, load the code below and run "COLLAYER" from the command line:

 

(defun c:collayer ( / all col ent layer len pair)
  (setq layer "Items"	; <--- your layer, or nil to select all layers. For multiple layers, use commas
	pair (list
	       (cons acBlue "Blue Items")
	       (cons acRed "Red Items")
	       (cons acGreen "Green Items")	; <--- Add more below line if there are more colors
	       )
	all (ssget "_X" (if layer (list (cons 8 layer))))
	)
  (if all
    (repeat (setq len (sslength all))
      (if (assoc
	    (setq col
		   (cdr
		     (assoc 62
			    (setq ent
				   (entget
				     (ssname all
					     (setq len (1- len))
					     )
				     )
				  )
			    )
		     )
		  )
	    pair
	    )
	(entmod
	  (subst
	    (cons 8 (cdr (assoc col pair)))
	    (assoc 8 ent)
	    ent
	    )
	  )
	)
      )
    )
  )

 

Posted
5 hours ago, Jonathan Handojo said:

AutoLISP is AutoCAD's programming language. You can search on how to use and run it.

 

Once you've got that, load the code below and run "COLLAYER" from the command line:

 


(defun c:collayer ( / all col ent layer len pair)
  (setq layer "Items"	; <--- your layer, or nil to select all layers. For multiple layers, use commas
	pair (list
	       (cons acBlue "Blue Items")
	       (cons acRed "Red Items")
	       (cons acGreen "Green Items")	; <--- Add more below line if there are more colors
	       )
	all (ssget "_X" (if layer (list (cons 8 layer))))
	)
  (if all
    (repeat (setq len (sslength all))
      (if (assoc
	    (setq col
		   (cdr
		     (assoc 62
			    (setq ent
				   (entget
				     (ssname all
					     (setq len (1- len))
					     )
				     )
				  )
			    )
		     )
		  )
	    pair
	    )
	(entmod
	  (subst
	    (cons 8 (cdr (assoc col pair)))
	    (assoc 8 ent)
	    ent
	    )
	  )
	)
      )
    )
  )

 

 

i have a question sir, how about the colors with different code? like 252... i mean, it is gray but 252 and 253 is different from each other.

Posted
3 hours ago, Tickles! said:

 

i have a question sir, how about the colors with different code? like 252... i mean, it is gray but 252 and 253 is different from each other.

 

9 hours ago, Jonathan Handojo said:

AutoLISP is AutoCAD's programming language. You can search on how to use and run it.

 

Once you've got that, load the code below and run "COLLAYER" from the command line:

 


(defun c:collayer ( / all col ent layer len pair)
  (setq layer "Items"	; <--- your layer, or nil to select all layers. For multiple layers, use commas
	pair (list
	       (cons acBlue "Blue Items")
	       (cons acRed "Red Items")
	       (cons acGreen "Green Items")	; <--- Add more below line if there are more colors
	       )
	all (ssget "_X" (if layer (list (cons 8 layer))))
	)
  (if all
    (repeat (setq len (sslength all))
      (if (assoc
	    (setq col
		   (cdr
		     (assoc 62
			    (setq ent
				   (entget
				     (ssname all
					     (setq len (1- len))
					     )
				     )
				  )
			    )
		     )
		  )
	    pair
	    )
	(entmod
	  (subst
	    (cons 8 (cdr (assoc col pair)))
	    (assoc 8 ent)
	    ent
	    )
	  )
	)
      )
    )
  )

 

 

 

Jonathan - Thank you so much, that is very helpful.

I too am curious with Tickles Question, how do we bring in the colours by number, for instance I swapped Blue for 20, but didn't work.

Posted (edited)

Add (cons 20 layer_name) to the pair list.

 

See, if you inspect acRed, acBlue, acGreen, etc... It returns you an integer. The color index of red is 1, hence acRed returns 1. acBlue returns 5, so it's really no different if you write (cons 1 "Red Items") instead of (cons acRed "Red Items). Similarly to blue, you can write (cons 5 "Blue Items) or '(5 . "Blue Items") instead of (cons acBlue "Blue Items")

Edited by Jonathan Handojo
Posted
7 hours ago, Tickles! said:

 

i have a question sir, how about the colors with different code? like 252... i mean, it is gray but 252 and 253 is different from each other.

 

13 hours ago, Jonathan Handojo said:

AutoLISP is AutoCAD's programming language. You can search on how to use and run it.

 

Once you've got that, load the code below and run "COLLAYER" from the command line:

 


(defun c:collayer ( / all col ent layer len pair)
  (setq layer "Items"	; <--- your layer, or nil to select all layers. For multiple layers, use commas
	pair (list
	       (cons acBlue "Blue Items")
	       (cons acRed "Red Items")
	       (cons acGreen "Green Items")	; <--- Add more below line if there are more colors
	       )
	all (ssget "_X" (if layer (list (cons 8 layer))))
	)
  (if all
    (repeat (setq len (sslength all))
      (if (assoc
	    (setq col
		   (cdr
		     (assoc 62
			    (setq ent
				   (entget
				     (ssname all
					     (setq len (1- len))
					     )
				     )
				  )
			    )
		     )
		  )
	    pair
	    )
	(entmod
	  (subst
	    (cons 8 (cdr (assoc col pair)))
	    (assoc 8 ent)
	    ent
	    )
	  )
	)
      )
    )
  )

 

 

That is perfect, thank you!

Posted (edited)

For me use (While  (entsel pick object for layer,  (acad_colordlg 1) to pick color (entsel destination layer no hard coding. A ssget and all done.

Edited by BIGAL

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