Jump to content

Select a definited block, capture determinated attributes and save them in clipboard


itacad

Recommended Posts

hello! I'm a new member of this fantastic forum that I met through google searches...I'am Italian and this is the first time I write to a foreign forum...sorry for my english!

I write to ask how to solve a problem using LISP (but I'm not a programmer)

There is an operation that I perform continuously: select attributes values and copy them out of autocad! and for this operation I always use the same block "CA5"...in my files there are a lot of "CA5", but I always use one only at a time...so:

1) I want to select a single block "CA5" by mouse click

2) I want to "read" the value of 2 definited attributes (es. DESCRIPT1 and DESCRIPT2)

3) I want to combine the 2 values in a single value (es. DESCRIPT1value+space+DESCRIPT2value)

4) I want to save this new value in the windows clipboard

someone can help me write this lisp?

Thank you in advance

Link to comment
Share on other sites

Hi,

How about this:

 

(defun C:test ( / a e enx s )
 (and 
   (or _SetClipBoardText (prompt "\nNo function definition \"_SetClipBoardText\"."))
   (setq a (car (entsel "\nSelect attributed block: ")))
   (setq a (entget a))
   (or (vl-every '(lambda (x) (member x a)) '((0 . "INSERT")(66 . 1))) (prompt "\nInvalid object."))
   (setq e (cdr (assoc -1 a)))
   (setq s "")
   (progn
     (while (member '(0 . "ATTRIB") (setq enx (entget (setq e (entnext e)))))
       (setq s (strcat s " " (cdr (assoc 1 enx))))
     )
     (_SetClipBoardText (substr s 2))
   )
 ); and 
 (princ)
); defun
(vl-load-com)(princ)

;;  MP
;;  http://www.theswamp.org/index.php?topic=21764.msg263322#msg263322
(defun _SetClipBoardText ( text / htmlfile result )
 
 ;;  Caller's sole responsibility is to pass a
 ;;  text string. Anything else? Pie in face.
 
 (setq result
   (vlax-invoke
     (vlax-get
       (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow)
       'ClipBoardData
     )
   'SetData  "Text"  text)
 )
 (vlax-release-object htmlfile)
 text
)

Link to comment
Share on other sites

First of all thanks for the help! Well, I tried your LISP and it could be useful but I need to be faster using a dedicated solution...but I do not have the knowledge to correct myself, to my needs your lisp ...

In only one click on the block "ca5" i want to obtain the string

denom+denom2+sigute

could you explain to me how write the code that combines only the attributes I need in a previously chosen block?

 

For see an example of what I want to do...

https://drive.google.com/open?id=1ZX6Fz9lgbdmcom9LEajEFK4gq73vtpKj

 

P.S. why you post your LISP with the name "TEXT"? I had to rename it

Link to comment
Share on other sites

Try this:

(defun C:test ( / a e enx L )
 (and 
   (or _SetClipBoardText (prompt "\nNo function definition \"_SetClipBoardText\"."))
   (setq a (car (entsel "\nSelect attributed block: ")))
   (setq a (entget a))
   (or (vl-every '(lambda (x) (member x a)) '((0 . "INSERT")(66 . 1))) (prompt "\nInvalid object."))
   (setq e (cdr (assoc -1 a)))
   
   (progn
     (while (member '(0 . "ATTRIB") (setq enx (entget (setq e (entnext e)))))
       (setq L (cons (mapcar '(lambda (x) (cdr (assoc x enx))) '(2 1)) L))
     )
     (_SetClipBoardText
       (apply '(lambda (a b c) (strcat a " " b " " c))
         (mapcar '(lambda (x) (cond ( (cadr (assoc x L)) ) (""))) '("DENOM" "DENOM2" "SIGUTE"))
       )
     )
   )
 ); and 
 (princ)  
); defun
(vl-load-com)(princ)

 

P.S. why you post your LISP with the name "TEXT"? I had to rename it

 

Do you mean test ? - its generally accepted default name for a routine, so you have to rename it by yourself later.

Link to comment
Share on other sites

nice!

(while (member '(0 . "ATTRIB") (setq enx (entget (setq e (entnext e)))))         (setq L (cons (mapcar '(lambda (x) (cdr (assoc x enx))) '(2 1)) L))       )       (_SetClipBoardText         (apply '(lambda (a b c) (strcat a " " b " " c))           (mapcar '(lambda (x) (cond ( (cadr (assoc x L)) ) (""))) '("DENOM" "DENOM2" "SIGUTE"))         )       )

Link to comment
Share on other sites

THANK YOU!

Now I think Grrr it is the diminutive for Grrreat!

Now I can make a series of copies of the lisp so each copy will have a particular combination!

I think I will have to modify this part

(apply '(lambda (a b c) (strcat a " " b " " c))

(mapcar '(lambda (x) (cond ( (cadr (assoc x L)) ) (""))) '("DENOM" "DENOM2" "SIGUTE"))

...a b c are variables where the lisp saves the text right? If I want to save four attributes I have to add one more variable and combine the necessary attributes...

I will write to you in the next days...Thanks again!

Link to comment
Share on other sites

Thanks for the complimens, itacad!

I just liked that you listed the steps in your first post, for what you wanted the routine to do, so I decided to help.

Indeed the a b c are the variables where the attribute values are stored from the tags '("DENOM" "DENOM2" "SIGUTE").

So for further modifications I think you know what to change.

Link to comment
Share on other sites

It can be done also directly just adding the attributes as you pick them using nentsel, this would be ok if you only had to do a few.

As many attributes as you like.

(defun c:add-att ( /  ans obj )
(while (/= (setq ent (nentsel)) nil)
(setq obj (vlax-ename->vla-object (car ent)))
(if (= ans nil)
(setq ans (vla-get-textstring obj))
(setq ans (strcat ans "-" (vla-get-textstring obj)))
)
)
)
(c:add-att)

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...