Jump to content

AutoCAD lisp routine for changing selectable objects to color red 1


Guest

Recommended Posts

What's the need in moving objects from position to the same position ? although if objects on locked layer then that won't work.

Also when you set a new system variable then you need to set it back as it was.

Link to comment
Share on other sites

cmdecho.... it is nice to reset system variables like cmdecho back to the starting point after you have done all you need to do, that way the user can continue with the same setting as before

 

for example:

 

(setq Cmdecho_Old (getvar 'cmdecho)) ;; get variable setting
(setvar 'cmdecho 0) ;; new variable setting


.... all your code here......

(setvar 'cmdecho Cmdecho_Old) ;; reset variable to starting point

 

 

This works well for a single variable change, MHUPP had a good example maybe 6 weeks if you want to change several using mapcar and lists

 

(noting that you will want to put a similar reset in any error functions)

Link to comment
Share on other sites

A similar approach to set or reset Vars

 

(setq vars (list '("insunits" 6) '("Insunitsdefsource" 6) '("INSUNITSDEFTARGET" 6)'("lunits" 2)'("luprec" 3)'("aunits" 1) ))
(foreach var vars
(setvar (car var)(cadr var))
)

 You can add the existing setting in the list 

(setq vars (list '("insunits" 6 (getvar 'insunits)) '("Insunitsdefsource" 6 (getvar Insunitsdefsource)) '("INSUNITSDEFTARGET" 6 (getvar 'INSUNITSDEFTARGET)) '("lunits" 2 (getvar 'lunits))'("luprec" 3 (getvar 'luprec))'("aunits" 1 (getvar 'aunits)) ))

So at end rest back to original.

(setvar (car var)(caddr var))

 

  • Like 1
Link to comment
Share on other sites

This might do what you want.

;Posted by rkmcswain 06FEB2006
;cadtutor.net/forum/showthread.php?5713-Change-Object-Color
;Post 2

; "This defines a function for each color (1-255). So command 1 will change
;  color to red, command 2 will change color to yellow, and so on."

(defun CHANGECOLOR (color / ss1) 
  (setq ss1 (ssget))
  (command "._chprop" ss1 "" "p" "c" color "")
)
(setq i 1)
(while (<= i 254) 
  (eval 
    (read 
      (strcat "(defun c:" (itoa i) (chr 40) (chr 41) "(CHANGECOLOR " (itoa i) "))")
    )
  )
  (setq i (1+ i))
)

 

Steve

Edited by StevJ
Spellin errers
Link to comment
Share on other sites

You cant just change the colors of selected blocks. if they are anywhere else in the drawing they will be changed also. best to have the entity's in the block set to bylayer. then change it to a layer that is red. or you could use this on the selected blocks giving them unique names.

https://www.cadtutor.net/forum/topic/76007-make-block-reference-names-unqiue/?do=findComment&comment=600502

store those name and then change all those entity's to red.

Edited by mhupp
Link to comment
Share on other sites

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