@wanda.keightleyUNM49 Unsure where you wanted the files so I just stuck them in a folder under temp files.
(defun ngn ( / blk attrs name dest)
(if (not (vl-catch-all-error-p (setq blk (vl-catch-all-apply '(lambda () (vlax-ename->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)
)
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.
(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")
)
)
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:
(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)
)
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.
(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)
)
You'd then need to call it via an objectDB wrapper. For example, Lee Mac has one: http://www.lee-mac.com/odbxbase.html. You could then call it in a similar fashion as above.
(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)
)
Note: I don't have his wrapper installed so I was unable to test it.
Lastly, I do not recommend Accoreconsole. It is extremely 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.