Copy value of one attribute to another

Copy value of one attribute to another

aksha
Enthusiast Enthusiast
696 Views
9 Replies
Message 1 of 10

Copy value of one attribute to another

aksha
Enthusiast
Enthusiast

I am trying to develop a block which has two attributes but user is to provide input for only one attribute. The second attribute will inherit the value of the first attribute. Is this possible? I can use an MText (or Text) instead of the second attribute if the same result can be achieved.

0 Likes
697 Views
9 Replies
Replies (9)
Message 2 of 10

paullimapa
Mentor
Mentor

both can be attributes 

but you can use atvlnk.lsp function to link the value of one attribute (source) to the other (target) as a field

then when the source changes the target will change with a regen:

; atvlnk selects Texts value or Attribute inside Block and link to another as a field
(defun c:atvlnk (/ Get-ObjectIDx64 en en1 txt)
 (vl-load-com)
 (defun Get-ObjectIDx64 (obj / util)
   (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))))
   (if (= (type obj) 'ENAME)(setq obj (vlax-ename->vla-object obj)))
   (if (= (type obj) 'VLA-OBJECT)
     (if (> (vl-string-search "x64" (getvar "platform")) 0)
       (vlax-invoke-method util "GetObjectIdString" obj :vlax-False)
       (rtos (vla-get-objectid obj) 2 0)
     )
   )
 ) ;  defun Get-ObjectIDx64
; nested selection function
(defun get_nen (msg / nen)
 (while(not nen)
  (princ msg)(princ)
  (setq nen(car(nentsel))) ; select 1st block's attributes you want to create a field from
  (if (not
       (or
         (eq (vla-get-ObjectName (vlax-ename->vla-object nen)) "AcDbAttribute")
         (eq (vla-get-ObjectName (vlax-ename->vla-object nen)) "AcDbText")
;        (eq (cdr(assoc 0 (entget nen)))"ATTRIB")
;        (eq (cdr(assoc 0 (entget nen)))"TEXT")
       )
      )
     (progn
      (setq nen nil)
      (princ"\n...Supported Objects are Attribute / Text...")(princ)
     )
     (redraw nen 3) ; highlight it
  ) ; if
 ) ; while
 nen
) ; defun
  (if(setq en(get_nen "\nPick Source Attribute / Text to Link...")) ; if picked 1st attibute/text
  (progn
   (setq txt(vla-get-TextString (vlax-ename->vla-object en))) ; get text string
;   (setq txt(cdr(assoc 1 (entget en)))) ; get the text string
   (setq txt(strcat "%<\\AcObjProp.16.2 Object (%<\\_ObjId " (Get-ObjectIDx64 en) ">%).TextString>%")) ; create new text string as field
   (if(setq en1(get_nen "\nPick Target Attribute / Text...")) ; if picked another attibute/text
    (progn
     (vla-put-TextString(vlax-ename->vla-object en1) txt) ; replace with new text string as field
     (command"_.UpdateField" en1 "") ; update the block attribute
;     (redraw en1 4) ; unhighlight it 
     (redraw en 4) ; unhighlight it
    )
   ) ; if
  ) ; progn
  (alert"No Attributes / Text Selected.")
 ) ; if
 (princ)
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 10

aksha
Enthusiast
Enthusiast

Hi @paullimapa 

 

Thank you for your reply. I am still not sure how would I use the lisp with the block.

0 Likes
Message 4 of 10

paullimapa
Mentor
Mentor

You’ll have to insert the block and fill out one attribute. Then run the lisp routine to select the attribute thats filled out as the source and then the other you left blank as the target. Then the target will automatically match the value of the source. Anytime you change the source the target will change automatically after a regen


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 10

aksha
Enthusiast
Enthusiast

@paullimapa 
Sorry, but this solution does not work for me. It will be easier to manually change the value of both attributes in the block after insertion. 

0 Likes
Message 6 of 10

Automohan
Advocate
Advocate

Can you post an example dwg . . .

 

I hope this link will work for you !

https://www.lee-mac.com/copytext.html 

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 7 of 10

aksha
Enthusiast
Enthusiast

@Automohan 
My block dwg file is attached. It is a gridline block with grid bubbles at each end. The grid line ID must remain same at both ends, hence my request. I have made it work somehow, but I would like to know if the functionality of the block is fine.

0 Likes
Message 8 of 10

Sea-Haven
Mentor
Mentor

The dwg is blank nothing in it !

 

Just a comment I would look at the task again of making a grid, most samples out there label as they are created so your adding a step that is not required. Post a image of what your grid looks like and I am sure some one will have what you want.

 

 

0 Likes
Message 9 of 10

aksha
Enthusiast
Enthusiast

@Sea-Haven 
I downloaded the drawing file from my post and opened it. It opens in 'Block Editor' (as it should) and shows all the components as created. Inserting it into another drawing as a block also works as intended. 

0 Likes
Message 10 of 10

Moshe-A
Mentor
Mentor

@aksha hi,

 

Your block is good if you make the right connection from G2 -> G1

after you do remember 2 things:

 

1. on each grid line you insert, you have to make this connection\relation G2 -> G1

2. use updatefield after setting G1 

 

Moshe

 

0 Likes