Write two attibute values into a text object

Write two attibute values into a text object

Anonymous
Not applicable
1,033 Views
4 Replies
Message 1 of 5

Write two attibute values into a text object

Anonymous
Not applicable

Hi Everyone,

 

I am a beginner with lisp and this is way beyond my understanding.

 

In our drawings we have four blocks which have different names, but all have the same attribute tag of BAL_NO. The values are all numbers.

 

If we could to pick any two blocks and pass the two attribute values to text that can be inserted into the drawing it would save quite a bit of time as we have up to 300 of these to enter in some drawings. So the two values would be formatted as nnn-nnn, text height of 200.

 

I have been searching as I am sure this has been done before, and I can see that it may not be that difficult, but I don't really have the time at the moment to spend on the problem.  As you probably all are, we are flat out at the moment trying to get drawings out before the Christmas break.

 

~Dave~

 

 

0 Likes
Accepted solutions (2)
1,034 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try the code.

- select the first text (or att),

- the second...

- point for the new text (0 rotation, or change zero to PAUSE for user input)

- or <enter> for put the combined text into clipboard.

 

Spoiler
(defun c:T-T ( / en tx html)
  (if (and (setq en (car (nentsel "\nSelect the first text: ")))
           (wcmatch (cdr (assoc 0 (entget en))) "MTEXT,TEXT,ATTDEF,ATTRIB")
           (setq tx (cdr (assoc 1 (entget en))))
           (setq en (car (nentsel "\nSelect the second text: ")))
           (wcmatch (cdr (assoc 0 (entget en))) "MTEXT,TEXT,ATTDEF,ATTRIB")
           (setq tx (strcat tx "-" (cdr (assoc 1 (entget en)))))
           )
    (cond ((setq pt (getpoint "\nInsertion point <to clipboard>: "))
           (command "_.TEXT" "_none" pt 20 0 tx ""))
          (T
           (vlax-invoke (vlax-get (vlax-get (setq html (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'setData "Text" tx)
           (vlax-release-object html))))
  (princ)
)
Message 3 of 5

Anonymous
Not applicable

Thanks!

 

That works for me. 

 

Just one thing... Could it change the numbers to three digits?  So at the moment they start from 1 (sometimes they are 01) and go up to 300+. We need to make the new  string to be for example 001-002, or 034-044

 

I have mucked around with your code but I can't get it.

 

cheers

 

~Dave~

0 Likes
Message 4 of 5

patrick_35
Collaborator
Collaborator
Accepted solution

Hi

 

By going on the lisp given by @ВeekeeCZ

(defun c:T-T ( / en tx html 3str)
  (defun 3str(txt)
    (while (< (strlen txt) 3)
      (setq txt (strcat "0" txt))
    )
    txt
  )

  (and	(setq en (car (nentsel "\nSelect the first text: ")))
	(setq en (vlax-ename->vla-object en))
	(vlax-property-available-p en 'textstring)
	(setq tx (3str (vla-get-textstring en)))
	(setq en (car (nentsel "\nSelect the second text: ")))
	(setq en (vlax-ename->vla-object en))
	(vlax-property-available-p en 'textstring)
	(setq tx (strcat tx "-" (3str (vla-get-textstring en))))
    (cond
      ((setq pt (getpoint "\nInsertion point <to clipboard>: "))
	(command "_.TEXT" "_none" pt 20 0 tx "")
      )
      (T
	(vlax-invoke (vlax-get (vlax-get (setq html (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'setData "Text" tx)
	(vlax-release-object html)
      )
    )
  )
  (princ)
)

@+

Message 5 of 5

Anonymous
Not applicable

That's great!

 

Thanks to both of you, it will save so much time and effort.

 

Smiley Very Happy

 

 

 

0 Likes