Waited soooooooolong. 🙂
Here's what I came up with. You just load the program and it will run. No 'Function C:xx. calls.
Once loaded, it prompts to select a folder with the .dxf files.
Foreach of the .dxf, it adds the text (you may want to adjust the textsize variable), then it
saves it into a "Finished" folder, just one level down from the Folder you selected in the beginning.
e.g. IF your .dxf files are in a folder 'C:\Project12345\', then it will save the finished
into a folder C:\Project12345\Finished\' - AND that folder (may not be visible, depending on how
your windows is set up.) If it's not visible, right click on the main folder, do 'Properties', and set
the folders below that to (NOT) read-only. Or, go to the original folder in Explorer, and it will be
shown on the Right Pane, click on that. Here's the code.
;; Add_dxf_name.lsp
;; New: 08-24-2024 ECCAD for the AutoLisp Forum
;;
(vl-load-com)
;;
;; Old Version of 'BrowseForFolder' by: Tony Tanzillo (AutoLisp Forum)
;;
(defun BrowseForFolder ( Message / sh folder parentfolder folderobject result)
(vl-load-com)
(setq sh
(vla-getInterfaceObject
(vlax-get-acad-object)
"Shell.Application"
)
)
(setq folder
(vlax-invoke-method
sh
'BrowseForFolder
0
Message
0
)
)
(vlax-release-object sh)
(if folder
(progn
(setq parentfolder
(vlax-get-property folder 'ParentFolder)
)
(setq FolderObject
(vlax-invoke-method
ParentFolder
'ParseName
(vlax-get-property Folder 'Title)
)
)
(setq result
(vlax-get-property FolderObject 'Path)
)
(mapcar 'vlax-release-object
(list folder parentfolder folderobject)
)
(if (/= (substr result (strlen result)) "\\")
(setq result (strcat result "\\"))
result
)
)
)
); defun BrowseForFolder
(defun get_dxf_file_lst ()
(if (setq DXF_Path_Name (BrowseForFolder "Select Folder of DXF Files."))
(progn
(setq fil_lst (vl-directory-files DXF_Path_Name "*.dxf" 1))
(if (/= fil_lst nil)
(setq fil_lst (acad_strlsort fil_lst))
(setq fil_lst (list ""))
); end if
); progn
); if
(princ)
); end function get_dxf_file_list
;;
;; Local Functions to process each DXF, add text, save in Finished folder
;;
(defun save_the_dxf ( fname )
(setq FOLDER (strcat DXF_Path_Name "Finished"))
(vl-mkdir FOLDER); Nil if folder exists
(setq OUTPATH (strcat FOLDER "\\"))
(setq dxfname (strcat OUTPATH out_fil))
(command "_DXFOUT" dxfname 16)
); end function save_the_dxf
(defun get_project_string ( fname )
(setq str ""); blanked string
(if fname
(progn
(setq N 1)
(repeat (strlen fname)
(setq chk (substr fname N 1))
(if (= chk "_")
(setq str (substr fname 1 (- N 1)))
); if
(setq N (+ N 1))
);repeat
); progn
); if
str
); end function get_project_string
(defun add_text_to_dxf ( DXFList )
(setq L 0)
(repeat (length DXFList)
(setq dx_fil (nth L DXFList)); get a file at a time
(setq out_fil dx_fil); Save existing File Name
(setq dx_fil (strcat DXF_Path_Name dx_fil))
(command "_erase" "all" "")
(command "_purge" "ALL" "" "N")
(command "_DXFIN" dx_fil); load the DXF
(command "_zoom" "E"); zoom
(setq txt (get_project_string out_fil))
(if (/= txt "")
(progn
(setvar "TEXTSIZE" 10.0); or whatever textheight you need.
(command "_Text" (list 0.0 0.0 0.0) (getvar "textsize") "0" txt)
); progn
); if
(save_the_dxf dx_fil)
(setq L (+ L 1))
); repeat
(princ "\n")
(alert (strcat "DXF Files Updated in " OUTPATH))
(princ)
); end function add_text_to_dxf
;;
;; Begin
;;
(setq fil_lst nil)
(get_dxf_file_lst)
(if fil_lst
(add_text_to_dxf fil_lst)
); if
(if (= fil_lst nil)
(alert "Did Not Find any .dxf Files in that Folder ?")
); if
(princ)
ECCAD