This script changes a blocks attributed text size and rotation
Can sombody please help me edit this script so I have the ability to change the color as well?
(defun C:ated ( / i ta as hi bl la an e eli) (setq i 0.0) (setvar "CMDECHO" 0) (setq ent (entget (car (entsel "\nSelect Block")))) (setq la (cdr (assoc 8 ent))) (setq bl "*") (setq ta "*") ; end of selection (setq hi nil) (initget 6) (setq hi (getreal "\nSpecify Hight: ")) (setq an nil) ; (initget 1) (setq an (getorient "\nSpecify Angle: ")) (cond ((and (= bl "*") (= la "*")) (setq as (ssget "X" (list (cons 0 "INSERT") (cons 66 1))))) ((and (= bl "*") (/= la "*")) (setq as (ssget "X" (list (cons 0 "INSERT") (cons 8 la) (cons 66 1))))) ((and (/= bl "*") (= la "*")) (setq as (ssget "X" (list (cons 0 "INSERT") (cons 2 bl) (cons 66 1))))) (t (setq as (ssget "X" (list (cons 0 "INSERT") (cons 2 bl) (cons 8 la) (cons 66 1))))) ) (while (< i (sslength as)) (setq e (entnext (ssname as i))) (while (not (= (cdr (assoc 0 (entget e))) "SEQEND")) (if (or (= (cdr (assoc 2 (entget e))) ta) (= ta "*")) (progn (setq eli (entget e)) (if hi (setq eli (subst (cons 40 hi) (assoc 40 eli) eli))) (if an (setq eli (subst (cons 50 an) (assoc 50 eli) eli))) (entmod eli) (entupd e) ) ) (setq e (entnext e)) ) (setq i (1+ i)) ) )
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by lgabriel. Go to Solution.
Attribute color is referenced in the enitty list as number 62. Simply add the following to your code
(setq an (getorient "\nSpecify Angle: ")) - your code
(setq cl (getint "n\Specify Color by number: ")) - add new line of code right after
(if an (setq eli (subst (cons 50 an) (assoc 50 eli) eli))) - your code
(if an (setq eli (subst (cons 62 cl) (assoc 62 eli) eli))) - add new line of code right after
If you want to enter the color by name, you will need to write code to change the color entered (text) to its associated number
i.e. Red 1
Yellow 2
Green 3 etc.
Good Luck
Thanks for the help!
But it doesnt work. It ask me for the color, but doesnt change anything.
(defun C:aed ( / i ta as hi bl la an e eli) (setq i 0.0) (setvar "CMDECHO" 0) (setq ent (entget (car (entsel "\nSelect Block")))) (setq la (cdr (assoc 8 ent))) (setq bl "*") (setq ta "*") ; end of selection (setq hi nil) (initget 6) (setq hi (getreal "\nSpecify Hight: ")) (setq an nil) ; (initget 1) (setq an (getorient "\nSpecify Angle: ")) (setq cl (getint "n\Specify Color by number: ")) (cond ((and (= bl "*") (= la "*")) (setq as (ssget "X" (list (cons 0 "INSERT") (cons 66 1))))) ((and (= bl "*") (/= la "*")) (setq as (ssget "X" (list (cons 0 "INSERT") (cons 8 la) (cons 66 1))))) ((and (/= bl "*") (= la "*")) (setq as (ssget "X" (list (cons 0 "INSERT") (cons 2 bl) (cons 66 1))))) (t (setq as (ssget "X" (list (cons 0 "INSERT") (cons 2 bl) (cons 8 la) (cons 66 1))))) ) (while (< i (sslength as)) (setq e (entnext (ssname as i))) (while (not (= (cdr (assoc 0 (entget e))) "SEQEND")) (if (or (= (cdr (assoc 2 (entget e))) ta) (= ta "*")) (progn (setq eli (entget e)) (if hi (setq eli (subst (cons 40 hi) (assoc 40 eli) eli))) (if an (setq eli (subst (cons 50 an) (assoc 50 eli) eli))) (if an (setq eli (subst (cons 62 cl) (assoc 62 eli) eli))) (entmod eli) (entupd e) ) ) (setq e (entnext e)) ) (setq i (1+ i)) ) )
@dsm_dude wrote:.... it doesnt work. It ask me for the color, but doesnt change anything.
....
(setq cl (getint "n\Specify Color by number: "))
....
(if an (setq eli (subst (cons 62 cl) (assoc 62 eli) eli)))
....
It won't change the color if you don't give it an angle. Should that perhaps be like this?
(if cl (setq eli (subst (cons 62 cl) (assoc 62 eli) eli)))
Thanks Kent. You are correct. I tested the program but cut and paste the solution from the original message and forgot to change the variable name to cl.
FYI, The program still does not work to change the color. The necessary changes have been made and checked and it still does not work. I am using 2004, if that has anything to do with it.
@Anonymous wrote:FYI, The program still does not work to change the color. The necessary changes have been made and checked and it still does not work. I am using 2004, if that has anything to do with it.
I didn't think of this before, but of course....
It would work if there was already a color override to replace. But things without a color override don't have a code-62 entry in their entity data, so substituting something for that does nothing. Try replacing this:
(if cl (setq eli (subst (cons 62 cl) (assoc 62 eli) eli)))
with this:
(if cl (setq eli (append eli (list (cons 62 cl)))))
If there's already a color override, putting the new one at the end like that overrides the earlier one.
May be the wrong lsp syntax but it works. Would be intersted to see other possibilities if there are any, which I am pretty sure there is. HTH.
(defun C:aed ( / i ta as hi bl la an e eli)
(setq i 0) (setvar "CMDECHO" 0)
(setq ent (entget (car (entsel "\nSelect Block"))))
(setq la (cdr (assoc 8 ent)))
(setq bl "*")
(setq ta "*")
; end of selection
(setq hi nil)
(initget 6)
(setq hi (getreal "\nSpecify Height: "))
(setq an nil)
; (initget 1)
(setq an (getorient "\nSpecify Angle: "))
(setq cl (getint "n\Specify Color by number: "))
(setq hrh (list (cons '62 cl)))
(cond ((and (= bl "*") (= la "*"))
(setq as (ssget "X" (list (cons 0 "INSERT") (cons 66 1)))))
((and (= bl "*") (/= la "*"))
(setq as (ssget "X" (list (cons 0 "INSERT") (cons 8 la) (cons 66 1)))))
((and (/= bl "*") (= la "*"))
(setq as (ssget "X" (list (cons 0 "INSERT") (cons 2 bl) (cons 66 1)))))
(t
(setq as (ssget "X" (list (cons 0 "INSERT") (cons 2 bl) (cons 8 la) (cons 66 1)))))
)
(while (< i (sslength as))
(setq e (entnext (ssname as i)))
(while (not (= (cdr (assoc 0 (entget e))) "SEQEND"))
(if (or (= (cdr (assoc 2 (entget e))) ta) (= ta "*"))
(progn
(setq eli (entget e))
(setq eli (append eli hrh))
(if hi (setq eli (subst (cons 40 hi) (assoc 40 eli) eli)))
(if an (setq eli (subst (cons 50 an) (assoc 50 eli) eli)))
(entmod eli)
(entupd e)
)
)
(setq e (entnext e))
)
(setq i (1+ i))
)
)
I should have checked the post before posting. Kent, I knew you come up with something quick. Oh well!!!!
Nice job Kent. The block that I tested my code changes had attributes that were assigned to colors not ByLayer and therefore worked on my machine.
Always learn something new every time I visit this forum