Block attribute tag to multileader

Block attribute tag to multileader

ssuoiresos
Contributor Contributor
1,956 Views
8 Replies
Message 1 of 9

Block attribute tag to multileader

ssuoiresos
Contributor
Contributor

Hi all. I have attached a lisp program BNAMELABEL.LSP which at the moment reads the name of a block and place it in a multileader. I would like someone to change this program to do the following.

-to read one of the block attributes, named "ATT", instead of the name of the block, and attach it to the multileader

-the font size of the text for the multileader to be set as  200 instead of 4 that is now

- somehow the "REGEN" command to be used, so that if some of the attributes named "ATT" in the blocks will be changed, using the REGEN command, the block multileaders to update accordingly. 

I tried to modify this lisp routine myself but I got so many errors...

Many thanks.

0 Likes
Accepted solutions (1)
1,957 Views
8 Replies
Replies (8)
Message 2 of 9

Sea-Haven
Mentor
Mentor

You can select a attribute directly no need to get block 1st.

 

 

(defun c:BattLabel (/ ent )
(while (setq ent (car (nentsel "\nSelect block attribute: Enter to exit :")))
(if (eq (cdr (assoc 0 (entget ent))) "ATTRIB")
	(progn
		(setq pt (getpoint "\nSpecify first point: "))
		(vl-cmdf "_.mleader" "_non" pt "\\" (cdr (assoc 1 (entget ent))))
            )
		(alert "You did not pick a ttribute ")
)
)

 (princ)
)

 

0 Likes
Message 3 of 9

pbejse
Mentor
Mentor

@ssuoiresos wrote:

Hi all. I have attached a lisp program BNAMELABEL.LSP...

... -to read one of the block attributes, named "ATT", instead of the name of the block,..

...  using the REGEN command, the block multileaders to update accordingly. 


 

Credit to the author 

 

(defun c:BNameLabel (/ ent entl obj)
;;	CADTutor Alanjit Jun 2013	;;
....

 

I addition to @Sea-Haven contribution

(defun c:BattLabel (/ ent mySourceID  str pt)
(while (setq ent (car (nentsel "\nSelect block attribute: Enter to exit :")))
(if (and (eq (cdr (assoc 0 (entget ent))) "ATTRIB")
	 (eq (cdr (assoc 2 (entget ent))) "ATT"))
	(progn
	  (setq mySourceID (itoa (vla-get-objectid (vlax-ename->vla-object ent))))
	  	(setq str (strcat "%<\\AcObjProp Object(%<\\_ObjId "  mySourceID
		                        		">%).TextString>%"))
		(setq pt (getpoint "\nSpecify first point: "))
		(vl-cmdf "_.mleader" "_non" pt "\\" str)
            )
		(alert "You did not pick a ttribute ")
	)
)
 (princ)
)

 HTH

 

0 Likes
Message 4 of 9

ssuoiresos
Contributor
Contributor

Hi. Thank you for your quick reply. Not sure what do you mean by "You can select a attribute directly no need to get block 1st". This attribute that will be copied in the multileader, is different for every block. So I am not sure how can I do that without selecting the block that I want to label. Anyway, when I run this lisp it just gives me the message "You did not pick a attribute"... 

0 Likes
Message 5 of 9

pbejse
Mentor
Mentor
Accepted solution
(defun c:BNameLabel (/ ent entl obj str mySourceID)
;;	CADTutor Alanjit Jun 2013 | pbe 2021	;;
 (cond ((not (setq ent (car (entsel "\nSelect block: ")))))
       ((not (eq (cdr (assoc 0 (entget ent))) "INSERT")) (princ "\nInvalid object!"))
       ((not (assoc 66 (entget ent))) (princ "\nNo Attributes on this block!"))
       ((setq pt (getpoint "\nSpecify first point: "))
        (setq entl (entlast))
        (vl-cmdf "_.mleader" "_non" pt "\\")
        (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (vl-cmdf ""))
        (if (and
	      (not (equal entl (setq entl (entlast))))
	      (setq mySourceID (Vl-some '(lambda (at)
			(if (eq (vla-get-tagstring at) "ATT")
			  	(itoa (vla-get-objectid at))))
				      (Vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes)))
	      (setq str (strcat "%<\\AcObjProp Object(%<\\_ObjId "  mySourceID
		                        		">%).TextString>%"))
	      )
	  (progn 
          	(vla-put-textstring (vlax-ename->vla-object entl) str )
		  (vl-cmdf "_updatefield" entl "")
		  (vlax-put  (vlax-ename->vla-object entl) 'TextLineSpacingStyle 2)
       		 	)
	  (princ "\nAttribute \"ATT\" not found")
	  
       		)
 	)
     )
 (princ)
)
(vl-load-com)
(princ)

HTH

 

Message 6 of 9

ssuoiresos
Contributor
Contributor

Brilliant. This is what I need. I am sorry to be a pain but what do I need to change in your code for the text to appear without grey mask (I know it won't print like that...). I think now appears like a sort of field. Thank you.

0 Likes
Message 7 of 9

pbejse
Mentor
Mentor

@ssuoiresos wrote:

Brilliant. This is what I need. I am sorry to be a pain but what do I need to change in your code for the text to appear without grey mask (I know it won't print like that...). I think now appears like a sort of field. Thank you.


 

Its because it is a field. so when the user change the value of the attribute, the value onthe mleader wil hcange as well.

You can turn the "grey mask" off with.

Command: FIELDDISPLAY

Enter new value for FIELDDISPLAY <1>: 0

 

Otherwise here's a non-field code

 

(defun c:BNameLabel (/ ent entl obj str)
;;	CADTutor Alanjit Jun 2013 | pbe 2021	;;
 (cond ((not (setq ent (car (entsel "\nSelect block: ")))))
       ((not (eq (cdr (assoc 0 (entget ent))) "INSERT")) (princ "\nInvalid object!"))
       ((not (assoc 66 (entget ent))) (princ "\nNo Attributes on this block!"))
       ((setq pt (getpoint "\nSpecify first point: "))
        (setq entl (entlast))
        (vl-cmdf "_.mleader" "_non" pt "\\")
        (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (vl-cmdf ""))
        (if (and
	      (not (equal entl (setq entl (entlast))))
	      (setq str (Vl-some '(lambda (at)
			(if (eq (vla-get-tagstring at) "ATT")
			  	(vla-get-textstring at)))
				      (Vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes)))
				)
          	(vla-put-textstring (vlax-ename->vla-object entl) str )
	  )
	  (princ "\nAttribute \"ATT\" not found")
	  
       		)
 	)
 (princ)
)
(vl-load-com)
(princ)

 

 

0 Likes
Message 8 of 9

ssuoiresos
Contributor
Contributor

Sorry. I should have done my homework regarding the FIELDDISPLAY command. Didn't really used fields before. I will leave the 200 standard text height for another day. 😁 Thank you so much for changing the code for me. Have a great day.👍👍👍

0 Likes
Message 9 of 9

brk77284027
Explorer
Explorer

Hi can you make one lisp, to callout the attribute values in to Multileader text as shown below image

brk77284027_0-1694173370182.png

 

0 Likes