Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing the color of an attribute

15 REPLIES 15
Reply
Message 1 of 16
rodb
1108 Views, 15 Replies

Changing the color of an attribute

Can you change the color of a block attribute with lisp like you can with the built in Enhanced Attribute Editor function eg

I can change the value of the attribute LAMP but can I also change its color from the color of the layer its created on?

 

(while (not (equal ck "SEQEND"))
(setq e1 (entnext e1)
e2 (entget e1)
ck (cdr (assoc 0 e2)))
(if (= (cdr (assoc 2 e2)) "LAMP")
(progn
(setq e2 (subst (cons 1 lamp)(assoc 1 e2)e2))
(entmod e2)
(entupd e1)
(setq ctr (+ ctr 1))
)
)
)

15 REPLIES 15
Message 2 of 16
hmsilva
in reply to: rodb

rodb,
perhaps something like

 

  (setq e2 (subst (cons 1 lamp) (assoc 1 e2) e2))
  (if (assoc 62 e2)
    (setq e2 (subst (cons 62 2) (assoc 62 e2) e2));; color 2
    (setq e2 (append e2 (list (cons 62 2))));; color 2
  )
  (entmod e2)

 

hope that helps

Henrique

EESignature

Message 3 of 16
rodb
in reply to: hmsilva

Hi Henrique, thank you for that I will give it a go today I hope I can get it to work!

 

Rod.

 

Message 4 of 16
rodb
in reply to: hmsilva

It is working! Now I just have to polish the routine to ask for a color as well as a lamp type with a drop down menu which I have done before some time ago. Thanks!

Message 5 of 16
pbejse
in reply to: rodb


@RodB wrote:

Can you change the color of a block attribute with lisp like you can with the built in Enhanced Attribute Editor function eg

I can change the value of the attribute LAMP but can I also change its color from the color of the layer its created on?




Not sure what you mean by "created on" , is that block layer or the ATTDEF layer? 

 

if its the former

 

(defun demo  (str tag / ss y)
  (vl-load-com)
  (if (setq ss (ssget ":L" '((0 . "INSERT") (66 . 1))))
    (repeat (sslength ss)
      (if (setq y (vl-some '(lambda (x)
                              (if (eq (vla-get-tagstring x) tag)
                                x))
                           (vlax-invoke (vlax-ename->vla-object (ssname ss 0)) 'Getattributes)))
        (mapcar '(lambda (j k) (vlax-put y J k))
                '("Textstring" "Color")
                (list str (cdr (assoc 62 (tblsearch "Layer" (vla-get-layer y)))))))
      (ssdel (ssname ss 0) ss)))
  (princ)
  )

 

(demo  "New String" "LAMP")

 

HTH

 

EDIT: to add a color option

 

(defun demo2  (str tag col / ss y)
  (vl-load-com)
  (if (setq ss (ssget ":L" '((0 . "INSERT") (66 . 1))))
    (repeat (sslength ss)
      (if (setq y (vl-some '(lambda (x)
                              (if (eq (vla-get-tagstring x) tag)
                                x))
                           (vlax-invoke (vlax-ename->vla-object (ssname ss 0)) 'Getattributes)))
        (mapcar '(lambda (j k) (vlax-put y J k))
                '("Textstring" "Color")
                (list str col)))
      (ssdel (ssname ss 0) ss)))
  (princ)
  )

 

(demo2  "New String" "LAMP" 2)

 

Message 6 of 16
pbejse
in reply to: pbejse

or even

 

(Defun c:demo3 ( / str tag col ss y)
   	(if (and
              (setq str (getstring  T "\nEnter New String:"))
              (not (eq "" str))
              (setq tag (strcase (getstring "\nEnter Tag to search:")))
              (not (eq "" tag))
              (setq col (setq lst (acad_colordlg 7 nil)))
              (setq ss (ssget ":L" '((0 . "INSERT") (66 . 1))))
              )
		(repeat (sslength ss)
		(if (setq y (vl-some '(lambda (x)
		              (if (eq (vla-get-tagstring x) tag)
		                x))
		           (vlax-invoke (vlax-ename->vla-object (ssname ss 0)) 'Getattributes)))
		(mapcar '(lambda (j k) (vlax-put y J k))
		'("Textstring" "Color")
		(list str col)))
		(ssdel (ssname ss 0) ss))
          	)
   (princ)
          )

 command: Demo3

Enter New String:hahaha

Enter Tag to search:LAMP

<Color dialog>

Select objects:

 

HTH

 

Message 7 of 16
hmsilva
in reply to: rodb

You're welcome, Rod

 

Henrique

EESignature

Message 8 of 16
rodb
in reply to: hmsilva

Thank you everyone. The program is working perfectly now. I was wanting to change the color of the attribute tag which is on a cyan layer by default not the color of the block layer. Using Henrique's option it works well. This is the program snippet now. I'm sure there are better ways of writing it but my Lisp is not that good.

 

(setvar "DYNMODE" 3)
(if (equal kelvin nil)
(setq kelvin 4))
(initget 7 "2800k 3000k 32000k 34000k 4000k 5000k")
(setq ctemp (getkword "\n Choose Colour Temperature [2800k/3000k/32000k/34000k/4000k/5000k] :"))
(setq kelvin (cond((= ctemp "2800k") 6)
((= ctemp "3000k") 1)
((= ctemp "32000k") 26)
((= ctemp "34000k") 3)
((= ctemp "4000k") 4)
((= ctemp "5000k") 5)

)
)
(prompt "\nPick your Blocks..")
(setq ss (ssget '((0 . "insert")))
sl (sslength ss)
ct 0
ctr 0)
(repeat sl
(setq e1 (ssname ss ct))
(setq ck 2)
(while (not (equal ck "SEQEND"))
(setq e1 (entnext e1)
e2 (entget e1)
ck (cdr (assoc 0 e2)))
(if (= (cdr (assoc 2 e2)) "LAMP")
(progn
(setq e2 (subst (cons 1 lmp)(assoc 1 e2)e2))
(if (assoc 62 e2)
(setq e2 (subst (cons 62 kelvin) (assoc 62 e2) e2))
(setq e2 (append e2 (list (cons 62 kelvin))))
)
(entmod e2)
(entupd e1)

 

Message 9 of 16
brianchapmandesign
in reply to: rodb

Hate to burst your bubble but "Battman" command works well for this.


"Very funny, Scotty. Now beam down my clothes.
Message 10 of 16
rodb
in reply to: brianchapmandesign

But it does not allow you to select multiple blocks and the danger is it will assign a particular lamp to all those blocks, also the lisp is faster and much easier to use, it remembers your lamp and colour allowing you to pick and choose which blocks to edit. I have tried many times to get people in the office to use the built in AutoCAD commands like attedit but they simply forget how to use them and find them too long winded when they do remember them. Much better a Lisp with a clear menu pick option that you can find easily and asks direct questions then completes the task efficiently and remembers your choices.   

Message 11 of 16
hmsilva
in reply to: rodb

rodb,
for setting the color temperature of the lamps, you ask the user to write the complete definition of the lamp
eg 32000k, six digits, facilitating the error by forcing the user to provide as high a number of digits,
might be more user friendly allow the user to provide only a few digits,perhaps something like

 

(initget 7 "2800k,28 3000k,30 32000k,32 34000k,34 4000k,40 5000k,50")
(setq ctemp (getkword "\n Choose Colour Temperature [(28)2800k/(30)3000k/(32)32000k/(34)34000k/(40)4000k/(50)5000k] :"))

 

this way allows the user, if choose the lamp of 32000k, just enter 32, making it easier to choose the lamp...

 

hope that helps

Henrique

EESignature

Message 12 of 16
rodb
in reply to: hmsilva

Thank you Henrique, thats a good idea, at the moment though the program allows the user to click on an on screen menu so all he has to do is fill in the lamp type using the keyboard and then click on the required color temperature, no typing required for the color temp selection. But sometimes people have set their computer to disable the on screen menu or they keep their mouse off the graphic screen area and don't see the menu so they would then have to type it in so I will make a short cut type in option like you suggest as well.   

Message 13 of 16
rodb
in reply to: rodb

And I have just seen some extra zero's in my menu! Oh no!

Message 14 of 16
hmsilva
in reply to: rodb

You're welcome,rodb

the menu is a good solution, to prevent that someone disable the on screen menu, You may also consider using a DCL ...

 

Henrique

EESignature

Message 15 of 16
rodb
in reply to: hmsilva

Hmmm I have never used DCL but it could be very useful for me so I will definately look into it - thanks again!

Message 16 of 16
brianchapmandesign
in reply to: rodb

Sorry rob, my battman comment was in response to your original question: Can you change the color of a block attribute with lisp...

 

I see now there was more to it.


"Very funny, Scotty. Now beam down my clothes.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost