manddarran Posted April 20, 2010 Share Posted April 20, 2010 I found this lisp and it really works great except for the fact that some of our attributes have quote marks in them. Here is the code and I have attached the dwg and a jpg of what I am talking about along with the error. ;;;DCLATT.LSP ;This program is for demonstration and tutorial purposes only. ;This program, using Visual Lisp will extract attributes from ;a block and display them in a dialog box. ;The dialog box will be created "on the fly" with the relevant ;number of edit boxes ;to suit the number of attributes within ;the block. ;The new attribute data will then be retrieved from the dialog ;and the block updated. ;Written by Kenny Ramage - May 2002 ;afralisp@mweb.com.na ;http://www.afralisp.com ;Usage : ;Load by typing (load "DCLATT") at the command prompt. ;Type DCLATT at the command prompt to run. ;Select any block containing attributes. ;Replace any of the values in the text boxes to updated ;the attributes. ;Dependencies : None that I know of. ;Not much in the way of error checking I'm afraid. ;Limitations : Will only edit a certain number of attributes. ;System dependent. ;I don't recommend more than 10. ;I've had up to 14 on my display. (prompt "\nType DCLATT to run.....") (defun c:dclatt ( / theblock thelist n taglist txtlist lg fname fn nu dcl_id l relist) ;load the visual lisp extensions (vl-load-com) ;get the entity and entity name (setq theblock (car (entsel))) ;convert to vl object (setq theblock (vlax-ename->vla-object theblock)) ;check if it's a block (if (= (vlax-get-property theblock 'ObjectName) "AcDbBlockReference") ;if it is, do the following (progn ;check if it has attributes (if (= (vlax-get-property theblock 'HasAttributes) :vlax-true) ;if it has attributes, do the following (progn ;get the attributes (getatt theblock) ;create the dialog (create_dialog) ;run the dialog (run_the_dialog) ;update the attributes (upatt) );progn ;No attributes, inform the user (alert "This Block has No Attributes!! - Please try again.") );if );progn ;it's not a block, inform the user (alert "This is not a Block!! - Please try again.") );if (princ) );defun (defun getatt (enam) ;retrieve the attributes (setq thelist (vlax-safearray->list (variant-value (vla-getattributes enam)))) ;process each attribute (foreach n thelist ;get the tag attribute data (setq taglist (cons (vla-get-tagString n) taglist) ;get the text attribute data txtlist (cons (vla-get-textString n) txtlist) ;how many attributes? lg (length taglist) );setq );foreach ;reverse the lists (setq taglist (reverse taglist) txtlist (reverse txtlist)) );defun (defun create_dialog () ;create a temp DCL file (setq fname (vl-filename-mktemp "dcl.dcl")) ;open it to write (setq fn (open fname "w")) ;write the dialog header coding (write-line "temp : dialog { label = \"Edit Attributes\";" fn) ;reset the incremental control number (setq nu 0) ;start the loop to create the edit boxes (repeat lg ;create the edit boxes (write-line ": edit_box {" fn) (setq l (strcat "\"" "eb" (itoa nu) "\"" ";")) (write-line (strcat "key = " l) fn) (setq l (nth nu taglist)) (write-line (strcat "label = " "\"" l "\"" ";") fn) (setq l (nth nu txtlist)) (write-line (strcat "value = " "\"" l "\"" ";") fn) (write-line "alignment = centered; edit_width = 20; }" fn) ;increment the counter (setq nu (1+ nu)) );repeat ;ok and cancel button (write-line "ok_only; }" fn) ;close the temp DCL file (close fn) );defun (defun run_the_dialog () ;load the dialog file and definition (setq dcl_id (load_dialog fname)) (if (not (new_dialog "temp" dcl_id)) (exit ) );if (mode_tile "eb0" 2) ;if the OK button is selected (action_tile "accept" "(retatt)") ;start the dialog (start_dialog) ;unload the dialog (unload_dialog dcl_id) ;delete the temp DCL file (vl-file-delete fname) );defun (defun retatt () ;reset the increment counter (setq nu 0) start the loop (repeat lg ;retrieve the tile value (setq l (get_tile (strcat "eb" (itoa nu)))) ;add it to the list (setq relist (cons l relist)) ;increment the counter (setq nu (1+ nu)) );repeat (setq relist (reverse relist)) ;close the dialog (done_dialog) );defun (defun upatt () ;reset the increment counter (setq nu 0) ;start the loop (repeat lg ;update the attribute (vla-put-textstring (nth nu thelist) (nth nu relist)) ;increment the counter (setq nu (1+ nu)) );repeat ;update the block (vla-update theblock) );defun ;clean loading (princ) ;End of ATTDCL.LSP TTL2.DWG dclatt.lsp Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2010 Share Posted April 20, 2010 Why not just double click on the attributed block? Or is this LISP doing something more? Also, I wrote this a while back if it helps: ddatte2.lsp Quote Link to comment Share on other sites More sharing options...
manddarran Posted April 20, 2010 Author Share Posted April 20, 2010 Yeah that works but this makes it some much easier and cleaner. Will give yours a whirl. Quote Link to comment Share on other sites More sharing options...
manddarran Posted April 20, 2010 Author Share Posted April 20, 2010 Perfect. Thx. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2010 Share Posted April 20, 2010 You're welcome. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 20, 2010 Share Posted April 20, 2010 What about regular old AttEdit (or ATE)? Also, if you hold the control key down and double-click on an attribute (in newer versions) it will open a single line, in place attribute editor. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2010 Share Posted April 20, 2010 Something a little more concise: ;; QuickEdit ~ Lee Mac ~ 20.04.10 (defun c:qe (/ e dc el c v ) (while (and (setq e (car (nentsel))) (<= 0 (setq dc (load_dialog "ACAD")))) (if (and (wcmatch (cdr (assoc 0 (setq el (entget e)))) "TEXT,ATTRIB") (setq v (cdr (assoc 1 el)) c v) (new_dialog "acad_txtedit" dc)) (progn (set_tile "text_edit" v) (action_tile "text_edit" "(setq v $value)") (action_tile "cancel" "(setq v c)") (start_dialog) (entupd (cdr (assoc -1 (entmod (subst (cons 1 v) (assoc 1 el) el))))))) (unload_dialog dc)) (princ)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2010 Share Posted April 20, 2010 To be honest though Matt, I'm with Alan on this one - I'm not sure how much cleaner you want the edit to be Quote Link to comment Share on other sites More sharing options...
manddarran Posted April 20, 2010 Author Share Posted April 20, 2010 What about regular old AttEdit(or ATE)? Also, if you hold the control key down and double-click on an attribute (in newer versions) it will open a single line, in place attribute editor. Man, where is this crap hidden? I have been trying to get the ate command to open on double click but I have to double click then select the attribute again. I like that control double click though. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2010 Share Posted April 20, 2010 I have been trying to get the ate command to open on double click but I have to double click then select the attribute again. Assuming your double-click action is set correctly, try setting QAFLAGS to 0 (if it isn't already) (record what it was set to before changing it of course). Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 20, 2010 Share Posted April 20, 2010 Man, where is this crap hidden? I have been trying to get the ate command to open on double click but I have to double click then select the attribute again. I like that control double click though. A double-click will open a different (newer) former of AttEdit. I found the Control double-click one by accident. Quote Link to comment Share on other sites More sharing options...
manddarran Posted April 20, 2010 Author Share Posted April 20, 2010 well it is set to zero and here is what I have in the double click action. Still have to double click then select the block. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2010 Share Posted April 20, 2010 Try using this as the Macro: ^C^C_attedit Quote Link to comment Share on other sites More sharing options...
manddarran Posted April 20, 2010 Author Share Posted April 20, 2010 Good grief. What the #$%#@%#$% was the difference, same command..... Thx Lee that worked. I have been fiddling on and off with that for months. I had tried ^c^c_atte, and ^c^c_ddatte as well. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 20, 2010 Share Posted April 20, 2010 When adding options to Pulldowns, Double-click actions, etc., to avoid any possible issues, always use the command name instead of a command alias. Quote Link to comment Share on other sites More sharing options...
manddarran Posted April 20, 2010 Author Share Posted April 20, 2010 Yup. Just got to make sure which one is the alias. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2010 Share Posted April 20, 2010 Glad you got it working Matt, I'll sure we've provided enough options in this thread to have you satisfied for a long time Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 20, 2010 Share Posted April 20, 2010 Yup. Just got to make sure which one is the alias. With core commands, if you execute a command with an alias, the full name is displayed. eg. Command: ate ATTEDIT Select block reference: *Cancel* Command: l LINE Specify first point: *Cancel* Command: p PLINE Specify start point: *Cancel* 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.