Results 1 to 9 of 9

Thread: LISP to change Attribute values in 1000's of drawings

  1. #1
    Login to Give a bone
    0

    Default LISP to change Attribute values in 1000's of drawings

    Hi friends..
    Anybody having any lisp/script to change attribute values?
    I am facing a problem with 1000’s of drawings
    One of my project titles has changed. Only one attribute value has changed. “Project title”.
    Is there any way change all drawing together or open and run a script/lisp?
    I am attaching the attribute here.
    Thanks in advance
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: LISP to change Attribute values in 1000's of drawings

    Here is my old one, it works good for me in A2005, try it

    Code:
    ;;=============================================================;
    ;; *| DBX-CHANGE-ATT.lsp | Fatty The Old Horse © 2004   All rights removed  |* ;
    ;;=============================================================;
    
    ;; edited 4/20/06 
    ;; edited 5/28/06
    
    
    (defun odbx-test (/ dbx_doc)
    (if (< (atof (getvar "ACADVER")) 15.06)
    (progn (alert "ObjectDBX method not applicable\nin this AutoCAD version")
      (exit)(princ)(gc))
    (progn
    (if (= (atoi (getvar "ACADVER")) 15)
    (progn
      
    (if (not (vl-registry-read
    "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"))
    (startapp "regsvr32.exe"
    (strcat "/s \"" (findfile "axdb15.dll") "\"")))
    
    (setq dbx_doc (vla-getinterfaceobject
    (vlax-get-acad-object)
    "ObjectDBX.AxDbDocument")))
    
    (setq dbx_doc (vla-getinterfaceobject
                (vlax-get-acad-object)
                "ObjectDBX.AxDbDocument.16"))))))
    ;							;
    
    (defun put-new-value (actdoc blk_name cur_tag  new_value / actspace att_obj_list)
      (vlax-for b (vla-get-modelspace actdoc)
        (if	(and
    	  (eq (vla-get-objectname b) "AcDbBlockReference")
    	  (vlax-read-enabled-p b)
    	  (vlax-write-enabled-p b)
    	  (vlax-method-applicable-p b 'Getattributes)
    	  (eq (strcase (vla-get-name b)) (strcase blk_name))
    	)
          (progn
    	(setq att_obj_list (vlax-invoke b 'Getattributes))
    	(foreach at att_obj_list
    	  (if (eq cur_tag (strcase (vlax-get at 'Tagstring )))
    	    (progn
    	    (vlax-put at 'Textstring new_value)
    	    (vla-update at)))))))
      (gc)
      (princ)
      )
    ;;__________________MAIN PART___________________;;
     
    (defun C:chat (/ acapp adoc blk_name cur_tag fn fname
    	      fold full_name_list mdmod new_value
    	      other_doc)
    
    (vl-load-com)
    (or acapp (setq acapp (vlax-get-acad-object)))  
    (or adoc (setq adoc (vla-get-activedocument acapp)))
    (vla-endundomark adoc)
    (vla-startundomark adoc)  
    (setq mdmod (vla-getvariable adoc "SDI"))
    (vla-setvariable adoc "SDI" (vlax-make-variant 1 vlax-vbinteger))
      (setq blk_name "mytitle";(getstring T "\nBlock name (case sensitive):\n")
    	cur_tag "TITLE_1";(getstring "\nAttribute tag to be change:\n")
    	new_value " >>> HAS CHANGED MY FIRST LINE OF THE TITLE BLOCK?");(getstring T "\nNew value of an attribute:\n"))
      (setq	fn	       (getfiled "Select ANY .DWG FILE in a desired folder : "
    				 ""
    				 "dwg"
    				 4
    		       )
    	fold	       (vl-filename-directory fn)
    	full_name_list (vl-directory-files fold "*.dwg" 1)
    	full_name_list (mapcar (function (lambda (x)
    					   (strcat fold "\\" x)
    					 )
    			       )
    			       full_name_list
    		       )
      )
    (foreach other full_name_list   
    (if
    (setq fname (findfile other))
    (progn
    (setq other_doc (odbx-test))
    (vla-open other_doc fname)
    (put-new-value other_doc blk_name cur_tag  new_value)
    (vlax-invoke other_doc 'SaveAs fname) 
    (vl-catch-all-apply (function (lambda ()
    	(vla-release-object other_doc))))
    (setq other_doc nil)
    (vl-catch-all-apply (function (lambda ()
    (vla-update acapp))))
    )
    
    (princ "\File Not Found")
     )
      )
    (vla-setvariable adoc "SDI" mdmod)
      (vla-endundomark adoc)
      (gc)
    (princ)
      )
    (prompt "\n===========================\n")
    (prompt "\n	Type CHAT to execute ...   ")
    (prompt "\n===========================\n")
    (princ)
    f.

  3. #3
    Login to Give a bone
    0

    Default Re: LISP to change Attribute values in 1000's of drawings

    fixo..Thanks for the fastest action.. there is an error,,
    ,what could b wrong..?


    Command: chat
    The SDI variable cannot be reset unless there is only one drawing open.; error:
    Automation Error. Error setting system variable

  4. #4
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: LISP to change Attribute values in 1000's of drawings

    Quote Originally Posted by windowsxp5
    fixo..Thanks for the fastest action.. there is an error,,
    ,what could b wrong..?


    Command: chat
    The SDI variable cannot be reset unless there is only one drawing open.; error:
    Automation Error. Error setting system variable
    Okay, I'll find where is problem
    wait a ...minutes

  5. #5
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: LISP to change Attribute values in 1000's of drawings

    Did you load this lisp from the same folder where
    are you drawings locate?
    You need to load it from other folder
    And maybe cause is on of any system variables,
    but I can't to find which of these is wrong
    Try to set XLOADCTL to 0, FILEDIA to 0

  6. #6
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: LISP to change Attribute values in 1000's of drawings

    Fatty, I hope you don't mind but I modified your code and commented where & what I did. There should be one more (vl-catch-all-apply) added into where the ODBX drawing is being opened. This will allow the rourine to continue to run if an error is raised due to an incompatable drawing version or it already being open.
    Code:
    ;;================================================  =============;
    ;; *| DBX-CHANGE-ATT.lsp | Fatty The Old Horse © 2004   All rights removed  |* ;
    ;;================================================  =============;
    
    ;; edited 4/20/06 
    ;; edited 5/28/06
    ;; edited 5/28/06 by Jeff M
    
    (defun odbx-test (/ dbx_doc)
      ;;modified slightly to work with more versions
      (if (< (setq dbxver (atof (getvar "ACADVER")) 15.06))
        (progn (alert
    	     "ObjectDBX method not applicable\nin this AutoCAD version"
    	   )
    	   (exit)
    	   (princ)
    	   (gc)
        )
        (progn
          (if (= (atoi (getvar "ACADVER")) 15)
    	(progn
    
    	  (if (not (vl-registry-read
    		     "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"
    		   )
    	      )
    	    (startapp "regsvr32.exe"
    		      (strcat "/s \"" (findfile "axdb15.dll") "\"")
    	    )
    	  )
    
    	  (setq	dbx_doc	(vla-getinterfaceobject
    			  (vlax-get-acad-object)
    			  "ObjectDBX.AxDbDocument"
    			)
    	  )
    	)
    
    	(setq dbx_doc (vla-getinterfaceobject
    			(vlax-get-acad-object)
    			(strcat "ObjectDBX.AxDbDocument." (fix dbxver))
    		      )
    	)
          )
        )
      )
    )
    					;							;
    
    (defun put-new-value
           (actdoc blk_name cur_tag new_value / actspace att_obj_list)
      (vlax-for layout (vla-get-layouts actdoc);;added this to go thru ALL layouts
        (vlax-for b	(vla-get-block layout);;;modified this
          (if (and
    	    (eq (vla-get-objectname b) "AcDbBlockReference")
    	    (vlax-read-enabled-p b)
    	    (vlax-write-enabled-p b)
    	    (vlax-method-applicable-p b 'Getattributes)
    	    (eq (strcase (vla-get-name b)) (strcase blk_name))
    	  )
    	(progn
    	  (setq att_obj_list (vlax-invoke b 'Getattributes))
    	  (foreach at att_obj_list
    	    (if	(eq cur_tag (strcase (vlax-get at 'Tagstring)))
    	      (progn
    		(vlax-put at 'Textstring new_value)
    		(vla-update at)
    	      )
    	    )
    	  )
    	)
          )
        )
      )
      (gc)
      (princ)
    )
    ;;__________________MAIN PART___________________;;
    
    (defun C:chat (/	  acapp	     adoc	blk_name   cur_tag
    	       fn	  fname	     fold	full_name_list
    	       mdmod	  new_value  other_doc
    	      )
    
      (vl-load-com)
      (or acapp (setq acapp (vlax-get-acad-object)))
      (or adoc (setq adoc (vla-get-activedocument acapp)))
      ;;next 4 lines not needed for use with ODBX   
    ;;;(vla-endundomark adoc)
    ;;;(vla-startundomark adoc)  
    ;;;(setq mdmod (vla-getvariable adoc "SDI"))
    ;;;(vla-setvariable adoc "SDI" (vlax-make-variant 1 vlax-vbinteger))
      (setq	blk_name  "mytitle"		;(getstring T "\nBlock name (case sensitive):\n")
    	cur_tag	  "TITLE_1"		;(getstring "\nAttribute tag to be change:\n")
    	new_value " >>> HAS CHANGED MY FIRST LINE OF THE TITLE BLOCK?"
      )					;(getstring T "\nNew value of an attribute:\n"))
      (setq	fn	       (getfiled "Select ANY .DWG FILE in a desired folder : "
    				 ""
    				 "dwg"
    				 4
    		       )
    	fold	       (vl-filename-directory fn)
    	full_name_list (vl-directory-files fold "*.dwg" 1)
    	full_name_list (mapcar (function (lambda (x)
    					   (strcat fold "\\" x)
    					 )
    			       )
    			       full_name_list
    		       )
      )
      (if (setq other_doc (odbx-test))
        ;;moved out of foreach
        (progn
          (foreach other full_name_list
    	(if (setq fname (findfile other))
    	  (progn
    	    (vla-open other_doc fname)
    	    (put-new-value other_doc blk_name cur_tag new_value)
    	    (vlax-invoke other_doc 'SaveAs fname)
    					;the next line does nothing for a ODBX doc
    ;;;(vl-catch-all-apply (function (lambda ()
    ;;;(vla-update acapp))))
    	  )
    
    	  (princ "\File Not Found")
    	)
          )
        )
      )
      ;;moved following 2 lines out of foreach
      (vl-catch-all-apply
        (function (lambda ()
    		(vlax-release-object other_doc)
    	      )
        )
      )
      (setq other_doc nil)
    					;no need for these next 2 lines
    					;(vla-setvariable adoc "SDI" mdmod)
    					;  (vla-endundomark adoc)
      (gc)
      (princ)
    )
    (prompt "\n===========================\n")
    (prompt "\n	Type CHAT to execute ...   ")
    (prompt "\n===========================\n")
    (princ)

  7. #7
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Smile Re: LISP to change Attribute values in 1000's of drawings

    Glad to meet you again, thank you for the saving my time
    Your work is nice as always

  8. #8
    Login to Give a bone
    0

    Thumbs up Re: LISP to change Attribute values in 1000's of drawings

    fixo..miff..Thanks ....My headaic over....

  9. #9
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: LISP to change Attribute values in 1000's of drawings

    Quote Originally Posted by windowsxp5
    fixo..miff..Thanks ....My headaic over....
    Cheers

    ~'J'~

Similar Threads

  1. Replies: 3
    Last Post: 2014-01-02, 07:54 PM
  2. How to change dynamic block attribute default values based on block selected?
    By zeirz109180 in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2013-12-13, 02:20 PM
  3. Attribute color change through LISP
    By bradley.palmer407325 in forum AutoCAD Customization
    Replies: 1
    Last Post: 2012-09-27, 11:32 AM
  4. Automatic updating drawings when Excel values change
    By nvh.1989 in forum Inventor - General
    Replies: 2
    Last Post: 2008-09-18, 07:16 AM
  5. Replies: 0
    Last Post: 2008-02-08, 04:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •