<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255595#M23883</link>
    <description>&lt;P&gt;And what’s the name of the Block this Attribute Definition is found under? Would there be only one of these blocks found in each dwg?&lt;/P&gt;</description>
    <pubDate>Thu, 21 Sep 2023 07:29:33 GMT</pubDate>
    <dc:creator>paullimapa</dc:creator>
    <dc:date>2023-09-21T07:29:33Z</dc:date>
    <item>
      <title>Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255297#M23880</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;Our lovely client is known for changing the rules on drawings, and they've done it again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This time they want hundreds of drawings, which they've previously specified needed to have their number in the file name, changed to their client's number prior to the current submission.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been playing with scripts to automate tasks, due to the client constantly changing their minds, and I figure there HAS to be a way to do this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The number each file needs to be saved to is located in an Attribute, field name DRAWING NUMBER, so I'm thinking a script that will copy that number &amp;amp; saveas to that number is what's required. But I have no idea of how to begin writing the script (*.scr). Does anyone here have the capability please? &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 03:56:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255297#M23880</guid>
      <dc:creator>wanda.keightleyUNM49</dc:creator>
      <dc:date>2023-09-21T03:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255565#M23881</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;what is exactly that 'Drawing Number Attribute Field'?&lt;/P&gt;&lt;P&gt;this one?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="komondormrex_0-1695280139374.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1269423i7611B4D919EF062E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="komondormrex_0-1695280139374.png" alt="komondormrex_0-1695280139374.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 07:12:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255565#M23881</guid>
      <dc:creator>komondormrex</dc:creator>
      <dc:date>2023-09-21T07:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255576#M23882</link>
      <description>&lt;P&gt;It's DRAWING_NUMBER&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wandakeightleyUNM49_1-1695280575670.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1269427i5F933F45AC63871B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wandakeightleyUNM49_1-1695280575670.png" alt="wandakeightleyUNM49_1-1695280575670.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 07:16:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255576#M23882</guid>
      <dc:creator>wanda.keightleyUNM49</dc:creator>
      <dc:date>2023-09-21T07:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255595#M23883</link>
      <description>&lt;P&gt;And what’s the name of the Block this Attribute Definition is found under? Would there be only one of these blocks found in each dwg?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 07:29:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255595#M23883</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2023-09-21T07:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255641#M23884</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is only one in each file. The block name is PTA_A1&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 07:49:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12255641#M23884</guid>
      <dc:creator>wanda.keightleyUNM49</dc:creator>
      <dc:date>2023-09-21T07:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12256186#M23885</link>
      <description>&lt;P&gt;Since the client # for example is:&amp;nbsp;&lt;STRONG&gt;12345&lt;/STRONG&gt; is always the same stored under Block:&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;PTA_A1&lt;/STRONG&gt; under Attribute Tag:&amp;nbsp;&lt;STRONG&gt;DRAWING_NUMBER&lt;/STRONG&gt;, when &lt;STRONG&gt;12345&lt;/STRONG&gt; is retrieved, how do you want to save each drawing as to a unique name ? Do you want to place &lt;STRONG&gt;123435&lt;/STRONG&gt; as a prefix before the currrent drawing file name?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 12:24:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12256186#M23885</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2023-09-21T12:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12256215#M23886</link>
      <description>&lt;P&gt;sorry off topic... UNM as in Albuquerque?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 12:36:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12256215#M23886</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2023-09-21T12:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12258011#M23887</link>
      <description>&lt;P&gt;Whilst others are looking into the block for you it may be worthwhile to use Accoreconsole to modify the dwg's as it very fast, as it does not open the dwg, rather amends the dwg database. Not sure if Getproperty is supported in Accoreconsole as would make getting info much easier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The obvious though is before you start back everything up or do small number of dwg's at a time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you post 1 sample dwg with the block and where it would normally be found. Makes testing easier.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 03:34:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12258011#M23887</guid>
      <dc:creator>Sea-Haven</dc:creator>
      <dc:date>2023-09-22T03:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Needed! Script To Batch SAVEAS DWG Files To Text Located In Drawing Number Attribute Field</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12258961#M23888</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12126568"&gt;@wanda.keightleyUNM49&lt;/a&gt;&amp;nbsp;Unsure where you wanted the files so I just stuck them in a folder under temp files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun ngn ( / blk attrs name dest)
	(if (not (vl-catch-all-error-p (setq blk (vl-catch-all-apply '(lambda () (vlax-ename-&amp;gt;vla-object (ssname (ssget "_A" '((2 . "PTA_A1"))) 0))) nil))))
		(progn
			(setq attrs (mapcar '(lambda (x) (cons (vla-get-tagstring x) (vla-get-textstring x))) (vlax-invoke blk 'getattributes))
				name (cdr (assoc "DRAWING_NUMBER" attrs))
				dest (strcat (getvar "TempPrefix") "Output Dwgs\\")
			)
			(if (not (vl-file-directory-p dest))
					(vl-mkdir dest)
			)
			(setq dest (strcat dest name ".dwg"))
			(if (findfile dest)
				(vl-file-delete dest)
			)
			(vl-file-copy (vla-get-fullName (vla-get-ActiveDocument (vlax-get-acad-object))) dest)
			(print (strcat "New file has been saved too: " dest))
		)
		(print "Block PTA_A1 not found")
	)	
	(princ)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The easiest way to call the script would be through a script writer. Not sure if you have one, but here is a really simplified version of a basic one that will work as an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun SimpleScriptWriter (dwgFiles funcsToLoad lispToRun save / body scrName sn)
	(setq body "")
	(if (= 'LIST (type dwgFiles))
		(progn
			(foreach dwgFilePath dwgFiles
				(setq body ;Normal operation
					(strcat 
						body
						"_.open "
						"\"" dwgFilePath "\" "
						"(setvar \"filedia\" 1) "
					)
				)
				(if (= 'LIST (type funcsToLoad))
					(foreach it funcsToLoad 
						(setq body 
							(strcat
								body
								"(lispLoad \"\" \"" it "\") "
							)	
						)
					)
				)
				(setq body ;Normal operation
					(strcat 
						body
						lispToRun 
						" (setvar \"filedia\" 0) "
					)
				)
				(if save
					(setq body (strcat body "(command \"qsave\")\n"))
					(setq body (strcat body "\n"))
				)
			)
			(setq body (vl-string-right-trim "\n" body))
			(setq body (vl-string-right-trim "\n" body))
			(setq body (vl-string-right-trim " " body))
			(setq scrName (strcat (getvar "TempPrefix") "SimpeScript.scr"))
			(setq sn (open scrName "w"))
			(write-line body sn)
			(close sn)
			; (openAnything scrName) ;for debug purposes
			(setvar "filedia" 0)
			(vl-cmdf "_.script" scrName)
		)
		(notifyExit "No list of files found for SimpleScriptWriter")
	)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I don't know where these files are located, I am going to once again assume you stick them all in temp files under "Input Dwgs". In this case, you would call the script like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun c:copyDWGsWithNewNames ( / dwgsLocation dwgFiles )
	(setq dwgsLocation (strcat (getvar "TempPrefix") "Input Dwgs\\"))
	(setq dwgFiles (mapcar '(lambda (x) (strcat dwgsLocation x)) (vl-directory-files dwgsLocation "*.dwg" 1)))
	(SimpleScriptWriter dwgFiles nil "(ngn)" nil)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The script writer is so basic that it doesn't close previous files. If you run it on too many drawings, CAD may crash at some point. A better method would be to use the objectDB method. This would require a small modification to the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun ngn ( doc / blk attrs name dest)
	(vlax-for layout (vla-get-layouts doc)
		(vlax-for blk (vla-get-block layout)
			(if
				(and
					(= "AcDbBlockReference" (vla-get-objectname blk))
					(= :vlax-true (vla-get-hasattributes blk))
					(= (vla-get-name blk) "PTA_A1")
				)
				(progn
					(setq attrs (mapcar '(lambda (x) (cons (vla-get-tagstring x) (vla-get-textstring x))) (vlax-invoke blk 'getattributes))
						name (cdr (assoc "DRAWING_NUMBER" attrs))
						dest (strcat (getvar "TempPrefix") "Output Dwgs\\")
					)
					(if (not (vl-file-directory-p dest))
							(vl-mkdir dest)
					)
					(setq dest (strcat dest name ".dwg"))
					(if (findfile dest)
						(vl-file-delete dest)
					)
					(vl-file-copy (vla-get-Name doc) dest)
					(print (strcat "New file has been saved too: " dest))
				)
			)
		)
	)
	(if (not dest) (print "Block PTA_A1 not found"))		
	(princ)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'd then need to call it via an objectDB wrapper. For example, Lee Mac has one:&amp;nbsp;&lt;A href="http://www.lee-mac.com/odbxbase.html" target="_blank" rel="noopener"&gt;http://www.lee-mac.com/odbxbase.html&lt;/A&gt;. You could then call it in a similar fashion as above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun c:copyDWGsWithNewNames ( / dwgsLocation dwgFiles )
	(setq dwgsLocation (strcat (getvar "TempPrefix") "Input Dwgs\\"))
	(setq dwgFiles (mapcar '(lambda (x) (strcat dwgsLocation x)) (vl-directory-files dwgsLocation "*.dwg" 1)))
	(LM:ODBX 'ngn dwgFiles nil)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Note: I don't have his wrapper installed so I was unable to test it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lastly, I do not recommend&amp;nbsp;&lt;SPAN&gt;Accoreconsole. It is extremely&amp;nbsp;hard to use. I also disagree with the idea that it "amends" the database. It opens CAD without a GUI. This allows you to use CAD commands which can be useful. However, it doesn't let you load LISPs nor use any VLA type functions. Plus it is slower than ObjectDB method which is actually "amending" the database. ObjectDB basically opens up the drawing as a text file with the limitations being you are unable to use any CAD commands, ssget function, getvars, etc. Everything has to be in VLA or pure LISP.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 12:38:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/needed-script-to-batch-saveas-dwg-files-to-text-located-in/m-p/12258961#M23888</guid>
      <dc:creator>MrJSmith</dc:creator>
      <dc:date>2023-09-22T12:38:20Z</dc:date>
    </item>
  </channel>
</rss>

