Author Topic: Import text into an existing attribute [Resolved]  (Read 2217 times)

0 Members and 1 Guest are viewing this topic.

nini007

  • Newt
  • Posts: 58
Import text into an existing attribute [Resolved]
« on: October 15, 2018, 03:44:20 PM »
Hello forum,

I have a little problem... in fact I made a ball :-(, I need your help :-).
I have an existing attribute (Local_Info) with three fields (in white in the autocad file), Designation, Number and Area.
And of course to go fast, and it had to be only for one example, I created its three fields in a normal text (in red), using the "text" command.
I would like to retrieve the simple texts (in red) in the attribute (in white).
Is it possible ?
Is there a command or a lisp?

I searched on the internet and forums one I did not find anything, does anyone have a solution?

Best regards
« Last Edit: October 21, 2018, 06:54:06 AM by nini007 »

kpblc

  • Bull Frog
  • Posts: 396
Re: Import text into an existing attribute
« Reply #1 on: October 15, 2018, 03:55:54 PM »
Perhaps, attout / attin will help you?
Sorry for my English.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Import text into an existing attribute
« Reply #2 on: October 16, 2018, 04:19:34 AM »
Try this, it does need more as you may want to pick less text than the block has attributes.

Code: [Select]
; This will record text picked and push it into a block with attributes
; By Alan H oct 2018

(defun pushtext ( / lst ent txt blk x att)
(setq blk (vlax-ename->vla-object (car (entsel "Pick block object"))))
(foreach att (vlax-invoke blk 'getattributes)
(setq txt (vla-get-textstring (vlax-ename->vla-object (car (entsel "Pick text object")))))
(vla-put-textstring att txt)
(princ "\n")
)
)
(pushtext)

« Last Edit: October 17, 2018, 03:46:26 AM by BIGAL »
A man who never made a mistake never made anything

nini007

  • Newt
  • Posts: 58
Re: Import text into an existing attribute
« Reply #3 on: October 16, 2018, 08:02:47 AM »
Hello,
I thank you for your message :-D.

I copy/paste your code it works fine thank you.
Two little thing
1. In fact the command is "(pushtext)" I expected "defun c: pushtext:-)
2. During the order and until the end, everything is glued, is it possible to separate the "Pick text object" by a space, a comma or anything else?
   
Code: [Select]
Command: (pushtext)
Pick block objectPick text objectPick text objectPick text objectnil

Thank you in advance for your assistance  :wink:
Best regards
« Last Edit: October 16, 2018, 03:13:46 PM by nini007 »

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Import text into an existing attribute
« Reply #4 on: October 17, 2018, 03:47:54 AM »
Added a (princ "\n") should work
A man who never made a mistake never made anything

nini007

  • Newt
  • Posts: 58
Re: Import text into an existing attribute
« Reply #5 on: October 17, 2018, 06:17:48 AM »
Hello,

Thank you for your correction it works  :wink:
But it is not possible to add "defun c: pushtext"?
As I have several manipulations to do it would be easier to launch a command "^C^Cpushtext" because currently I copy/paste code for each attribute.

Or how do you load it automatically to create a button with a macro ?


Best regards  :-)

nini007

  • Newt
  • Posts: 58
Re: Import text into an existing attribute
« Reply #6 on: October 19, 2018, 09:04:00 AM »
Hello,

Continuing to search the net I found this lisp. :-D
It is limited to three Attibuts but easily modifiable at will.
If other people have other info or changes I takers.  ;-)

Thank you so much for your help  :smitten:

Best regards  :-)


Code: [Select]
;; Par Vincent -> zebulon_

(vl-load-com)

(defun modif_attrib (E ETIQ VALEUR / LATT ATT)
  (if (= (type E) 'ENAME)
    (setq E (vlax-ename->vla-object E))
  )
  (setq LATT (vlax-invoke E 'getAttributes))
  (foreach ATT LATT
    (if (= (strcase (vla-get-TagString ATT)) (strcase ETIQ))
      (vla-put-TextString ATT VALEUR)
    )
  )
)

(defun indtxt (enam)
  (vla-get-TextString (vlax-ename->vla-object enam))
)

(defun c:txt2att ()

  (setq Des (car (entsel "\nTexte Désignation : ")))
  (setq Num (car (entsel "\nTexte Numéro : ")))
  (setq Sur (car (entsel "\nTexte Surface : ")))
 
  (setq Blo (car (entsel "\nBloc de destination : ")))
 
  (modif_attrib Blo "DÉSIGNATION" (indtxt Des))
  (modif_attrib Blo "NUMERO" (indtxt Num))
  (modif_attrib Blo "SURFACE" (indtxt Sur))

  (princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Import text into an existing attribute
« Reply #7 on: October 19, 2018, 12:52:37 PM »
Try this modification.
Code: [Select]
; This will record text picked and push it into a block with attributes
; By Alan H oct 2018

(defun c:pushtext ( / lst ent txt blk x att)
(setq blk (vlax-ename->vla-object (car (entsel "Pick block object"))))
(foreach att (vlax-invoke blk 'getattributes)
(setq txt (vla-get-textstring (vlax-ename->vla-object (car (entsel "\nPick text object")))))
(vla-put-textstring att txt)
(princ "\n")
)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

nini007

  • Newt
  • Posts: 58
Re: Import text into an existing attribute
« Reply #8 on: October 21, 2018, 06:52:23 AM »
Hello,
I thank you for your help  :-)
Below is a modification brought by Vincent "Zebulon_"
Addition of the foreach loop, the vla-get which goes well to recover the name of the current attribute and to display it, so that the user knows where it is before doing the "Pick text object"

That's exactly what I wanted  :wink:

Thank you all for your help  :-D
Best regards


Code: [Select]
; This will record text picked and push it into a block with attributes
; By Alan H oct 2018
; Modification1 by CAB
; Modification2 by Vincent -> zebulon_


(defun c:pushtext ( / txt blk att)
  (setq blk (vlax-ename->vla-object (car (entsel "Pick block object"))))
  (foreach att (vlax-invoke blk 'getattributes)
    (setq txt
      (vla-get-textstring
        (vlax-ename->vla-object
          (car
            (entsel
              (strcat "\nChoose a text object for the attribute "
                (vla-get-TagString att)
              )
            )
          )
        )
      )
    )
    (vla-put-textstring att txt)
  )
 (princ)
)