itacad Posted January 22, 2018 Share Posted January 22, 2018 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 Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 22, 2018 Share Posted January 22, 2018 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 ) Quote Link to comment Share on other sites More sharing options...
itacad Posted January 23, 2018 Author Share Posted January 23, 2018 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 Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 23, 2018 Share Posted January 23, 2018 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. Quote Link to comment Share on other sites More sharing options...
rlx Posted January 23, 2018 Share Posted January 23, 2018 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")) ) ) Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 23, 2018 Share Posted January 23, 2018 Thanks Rlx, perhaps that will expand your creativity! Quote Link to comment Share on other sites More sharing options...
itacad Posted January 24, 2018 Author Share Posted January 24, 2018 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! Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 24, 2018 Share Posted January 24, 2018 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 25, 2018 Share Posted January 25, 2018 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.