Jump to content

Copy text to attribute tag value


rajapower

Recommended Posts

Hi,

 

i have the text in model space and i have attribute block.

i want the model space text to copy the attribute value tag of "ID"

 

Ex. model text is "L00-314-00-EPC-6ELI-01" this is text copy to attribute tag of "ID"

 

Please help me

 

raja

Link to comment
Share on other sites

You want to copy single text value to one attributed block and to replace the value in the ID tag name ?

 

This seems to be a completion of your last thread but copy a single text's value instead of writing it from the user , right ?

Link to comment
Share on other sites

thks for reply

 

please find the attached for reference in that i have the text in model space i want to copy the text and paste to the attribute tag "ID" (tag "Id" remain same) to paste the text (value area)

copy to attibute block.dwg

Link to comment
Share on other sites

This ?

 

(defun c:Test  (/ st e ss)
 ;; Tharwat 07.06.2015	;;
 (if (and (setq st (car (entsel "\nSelect Single text :")))
          (eq (cdr (assoc 0 (setq e (entget st)))) "TEXT")
          (princ "\nSelect Attributed blocks :")
          (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
          )
   ((lambda (i / sn)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (mapcar
          '(lambda (x)
             (if (eq (strcase (vla-get-tagstring x)) "ID")
               (vla-put-textstring x (cdr (assoc 1 e)))))
          (vlax-invoke
            (vlax-ename->vla-object sn)
            'getattributes))
        ))
     -1)
   )
 (princ)
 )(vl-load-com)

Link to comment
Share on other sites

This idea can be expanded fairly significantly we have a drainage schedule in a layout and pick text values from all over the place different layouts, model space and updates the correct line of the schedule, only trick is schedule must exist once only. We just use a simple pick id so it knows which line to update.

Link to comment
Share on other sites

Good, you're welcome.

 

If incase I need to copy the text some there tag in attributes that means same block attributes instead of to mention tag where to copy the text to be very use to me

Link to comment
Share on other sites

  • 6 years later...
  • 1 year later...
On 6/7/2015 at 12:34 PM, Tharwat said:

This ?

 

 

(defun c:Test  (/ st e ss)
 ;; Tharwat 07.06.2015	;;
 (if (and (setq st (car (entsel "\nSelect Single text :")))
          (eq (cdr (assoc 0 (setq e (entget st)))) "TEXT")
          (princ "\nSelect Attributed blocks :")
          (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
          )
   ((lambda (i / sn)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (mapcar
          '(lambda (x)
             (if (eq (strcase (vla-get-tagstring x)) "ID")
               (vla-put-textstring x (cdr (assoc 1 e)))))
          (vlax-invoke
            (vlax-ename->vla-object sn)
            'getattributes))
        ))
     -1)
   )
 (princ)
 )(vl-load-com)
 

 

Hi,
Thank you ery much for this LSP.
Is it possible to change code to:
- select 1 text
- select 2 text

- select 3 text

- select 4 text
- select block
done

I add that I can select 2,3, and 4 text to change 4 attributes but I have select block after each selected text.
And is it possible to select text from xref?
All best
Once again, thank You  

Link to comment
Share on other sites

To select xref text, you will want to use nentselp instead of entsel to select the text objects - I am not sure of your ability and if this makes sense ?

 

Try this in a LISP or paste into the command line as an example:

 

(princ (cdr (assoc 1 (entget (car (nentselp "Select text: ")))))) )

 

Then all you need to do is make a loop to select the texts one after another, and paste them into the block....

 

To paste to a block how is the LISP to know which text to paste to which attribute? I tend to select each text in a block one after another to update, but to do it with one click you'll maybe need to specify the attribute tag names

 

 

The rest of what you want should all be copy and paste from somewhere, just need to know how to do pasting to attributes

 

EDIT

and a bit long winded way to do it, copy and paste, will select texts (up to something like 255 characters long) until you hit enter or space. Just need to know about the blocks

 

EDIT 2: Added dotted pair list for output, just as an idea for copying / pasting many many texts (either use a foreach loop or an assoc search... not decided yet). Commented that part out for now

(defun c:txtmg ( / MyTexts EndLoop MyText acount)
  (setq MyTexts (list))
  (setq EndLoop "No")
;;(setq acount 0)
  (while (= EndLoop "No")
    (setq MyText (gettext))
    (if (= (type MyText) 'ENAME) 
      (progn
;;(setq acount (+ acount 1))
        (setq MyTexts (append MyTexts
           (list (cdr (assoc 1 (entget Mytext)) ) )
;;(list (cons acount (cdr (assoc 1 (entget Mytext))) ))
        )) ; end append, end setq
        (princ (last MyTexts))
      ) ; end progn
      (progn
        (setq EndLoop "Yes")
      )
    ) ; end if
  ) ; end while
  (princ MyTexts)
)
(defun gettext ( / endloop enta entb pt result LP)
  (setvar "errno" 0)
  (setq endloop "No")
  (while (and (= endloop "No")(/= 52 (getvar "errno")) )
    (setq LP (getvar "lastpoint"))
    (setq result (nentselp "\nSelect Text: "))

    (cond
      ((= 'list (type result)) ;;do stuff with ENT
        (if (not (wcmatch (cdr (assoc 0 (entget (car result)))) "TEXT,MTEXT,ATTRIB") )
          (progn
            (princ "\nThats not Text...\n")
          ) ; end progn
          (progn
            (princ "I thank you, that is selected OK: ")
            (setq enta (car result))
            (setq pt (cdr (assoc 10 (entget enta))) )
;;;;fix for nenset or entsel requirements
            (setq entb (last (last (nentselp pt))))
            (if (and (/= entb nil) (/= (type entb) 'real) )
              (if (wcmatch (cdr (assoc 0 (entget entb))) "ACAD_TABLE,*DIMENSION,*LEADER")(setq enta entb))
            )
            (setq endloop "Yes")
          ) ; end progn
        ) ; end if
      )
      ( (or (= "Exit" result)(= "E" result))
        (princ "\n-Cancel or Exit- ")
      )
      ( (= nil result) ;; Missed
        (if (= LP (getvar "lastpoint"))(princ)(princ (strcat "\nMissed: Select text, do try again. ")));
      )
      (t
        (setq enta "Ended")
        (setvar "errno" 52)
      )
    ) ; end conds
  ) ; end while
  enta ;;Entity name
)

 

Edited by Steven P
  • Like 1
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...