Hi,
Please find very simple way to run lisp function on many drawing files present in selected folder.
Step 1: Below Function CreateScript is to be run to create script file for all the drawing files present in selected folder.
Script file will be created in respected selection folder having name of the folder .scr.
(defun c:CreateScript()
(if (setq WORKINGDWGPATHVal (browseForFolder "Select Folder to create Script file" 1 "d:\\"))
(progn
(setq myfilenamelist (VL-DIRECTORY-FILES WORKINGDWGPATHVal "*.dwg"))
(setq scrname (last (sparser WORKINGDWGPATHVal "\\")))
(setq openfile (open (strcat WORKINGDWGPATHVal "\\"scrname ".scr") "w"))
(write-line "FILEDIA" openfile)
(write-line "0" openfile)
(setq myloopcnt 0)
(repeat (length myfilenamelist)
(write-line "OPEN" openfile)
(write-line (strcat "\"" WORKINGDWGPATHVal "\\" (nth myloopcnt myfilenamelist) "\"" ) openfile)
(write-line "QSAVE" openfile)
(write-line "CLOSE" openfile)
(setq myloopcnt (1+ myloopcnt))
);repeat
(write-line "FILEDIA" openfile)
(write-line "1" openfile)
(close openfile)
);progn
);if
(princ)
);defun
(defun sparser (str delim / ptr lst)
(while (setq ptr (vl-string-search delim str))
(setq lst (cons (substr str 1 ptr) lst))
(setq str (substr str (+ ptr 2)))
)
(reverse (cons str lst))
)
(defun browseForFolder (title options rootFolder / sh folder folderobject result)
(vl-load-com)
(setq
sh
(vla-getInterfaceObject
(vlax-get-acad-object)
"Shell.Application"
)
)
(setq
folder
(vlax-invoke-method
sh
'BrowseForFolder
(vla-get-hwnd (vlax-get-acad-object))
title
options
rootFolder
)
)
(vlax-release-object sh)
(if folder
(progn
(setq
folderobject
(vlax-get-property folder 'Self)
)
(setq
result
(vlax-get-property FolderObject 'Path)
)
(vlax-release-object folder)
(vlax-release-object FolderObject)
result
)
)
)
Step 2: Create AutoLISP fuction which you want run on DWG File, and Save it as RunFunction.lsp
(defun RunFunction()
......
);defun
(RunFunction)
Step 3: Open AutoCAD and use Appload and add RunFunction.lsp in Startup Suite (Contents) hence lisp file will be automatically loaded.
Step 4: Run the Script file
Regards,
Rajesh