Pick attribute from block and polyline handle and paste in other block

Pick attribute from block and polyline handle and paste in other block

RBernaz
Advocate Advocate
991 Views
10 Replies
Message 1 of 11

Pick attribute from block and polyline handle and paste in other block

RBernaz
Advocate
Advocate

Hi, 

As I don't understand a word of lisp programming, I would like to ask someone who understand to please help me. I thank you in advance.

 

I would like same lisp routine to pick  a attribute "A" from a block "X" to paste to an attribute "A" in a block "Y" and in a second step pick a polyline handle and past it in attribute "H" in the same block "Y".

 

Hope I'm explaining well, is that possible or easy to make?

 

Many thanks 

Accepted solutions (1)
992 Views
10 Replies
Replies (10)
Message 2 of 11

dlanorh
Advisor
Advisor

Are "A" &  "H" the Attribute Tags or do you want to select attribute (get value) select attribute (put value) Select polyline (get handle) select attribute (put handle) as the value?

I am not one of the robots you're looking for

0 Likes
Message 3 of 11

RBernaz
Advocate
Advocate

Hi dlanorh ,

 

Thank you very much for your reply,

I think in either cases I want to copy paste the values found within same Tag names and the handle the same

I hope I'm being clear enough

 

Regards

0 Likes
Message 4 of 11

dlanorh
Advisor
Advisor

What is the tag name of the attribute to contain the handle?

I am not one of the robots you're looking for

0 Likes
Message 5 of 11

RBernaz
Advocate
Advocate

HANDLE_LANCO

0 Likes
Message 6 of 11

dlanorh
Advisor
Advisor
Accepted solution

Try this. Select attribute to copy, select Pline and select block. Not tested as currently on a LT version.

 

 

(vl-load-com)

(defun c:a2a ( / *error* c_doc sv_lst sv_vals aobj tn tv ph bobj)

  (defun *error* ( msg )
    (mapcar 'setvar sv_lst sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred")))
    (princ)
  );end_defun

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        sv_lst (list 'cmdecho 'osmode)
        sv_vals (mapcar 'getvar sv_lst)
  );end_setq

  (mapcar 'setvar sv_lst '(0 0))

  (setq aobj (vlax-ename->vla-object (car (nentsel "\nPick Block Attribute to copy  : ")))
        tn (vlax-get aobj 'tagstring)
        tv (vlax-get aobj 'textstring)
        ph (cdr (assoc 5 (entget (car (entsel "|nSelect Polyline for Handle : ")))))
        bobj (vlax-ename->vla-object (car (entsel "\nSelect Destination Block : ")))
  );end_setq

  (foreach att (vlax-invoke bobj 'getattributes)
    (cond ( (= (strcase tn) (strcase (vlax-get att 'tagstring))) (vlax-put att 'textstring tv))
          ( (= "HANDLE_LANCO" (strcase (vlax-get att 'tagstring))) (vlax-put att 'textstring ph))
    );end_cond
  );end_foreach

  (vla-regen c_doc acallviewports)
  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

 

 

I am not one of the robots you're looking for

Message 7 of 11

RBernaz
Advocate
Advocate

FANTASTIC, many many thanks

it works very well, is exactly what I was looking for

 

thank you 

 

best regards

0 Likes
Message 8 of 11

dlanorh
Advisor
Advisor

@RBernaz

Glad it was useful.

 

I have updated the code above as I had missed the regen, which is always a good idea when working with attributes

 

If you need it to loop let me know.

I am not one of the robots you're looking for

0 Likes
Message 9 of 11

Sea-Haven
Mentor
Mentor

Hi Dlanorh I use nentsel to get attribute tag makes the routines more global, it also returns the attribute value. You can also use pick point to get block name if required. So many times the request is changed regarding tag names.

0 Likes
Message 10 of 11

RBernaz
Advocate
Advocate

Hi, sorry for asking another request....

 

Could you please make a simple lisp, just to pick a polyline handle and paste it to a block with attribute "HANDLE_LANCO", just a simple copy paste like.

 

Thanks, I would much appreciate your attention

0 Likes
Message 11 of 11

ВeekeeCZ
Consultant
Consultant

More generic function. You can pick an attribute or polyline as a source.

Also, destination att is identified by a pick, not by name.

 

(defun c:HTA (/ e d h)
  (and (setq e (car (nentsel "\nGet handle from: ")))
       (setq d (entget e))
       (setq h (cdr (assoc (if (= "ATTRIB" (cdr (assoc 0 d))) 1 5) d)))
       (setq e (car (nentsel "\nPut handle to: ")))
       (setq d (entget e))
       (setpropertyvalue (cdr (assoc 330 d)) (cdr (assoc 2 d)) h)
       )
  (princ)
  )

 

0 Likes