lisp on all dwg directory

lisp on all dwg directory

dvir860
Enthusiast Enthusiast
5,104 Views
9 Replies
Message 1 of 10

lisp on all dwg directory

dvir860
Enthusiast
Enthusiast

hi,

I have to run Lisp on folder with 50 DWG files.

I like to know if I can run Lisp go into the current dwg.'s Directory, get all the dwg. files, open them one by one and run the program in each one then close that .dwg and move on to the next one.

 

Dvir

0 Likes
Accepted solutions (2)
5,105 Views
9 Replies
Replies (9)
Message 2 of 10

hmsilva
Mentor
Mentor

@dvir860 wrote:

hi,

I have to run Lisp on folder with 50 DWG files.

I like to know if I can run Lisp go into the current dwg.'s Directory, get all the dwg. files, open them one by one and run the program in each one then close that .dwg and move on to the next one.

 

Dvir


Hi Dvir,

one way, is using a script file and Autodesk's ScriptPro

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 10

Lee_Mac
Advisor
Advisor
Accepted solution

You may also wish to try my old Script Writer program.

 

For your task, simply enter the Script Line as:

 

_.open *file* (load "YourProgram.lsp" nil) (c:YourLISPCommand) _.qsave _.close
0 Likes
Message 4 of 10

MehtaRajesh
Advocate
Advocate
Accepted solution

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



 

 

 

 

0 Likes
Message 5 of 10

Anonymous
Not applicable
Lee wrote:
You may also wish to try my old Script Writer program.

 

 

One little suggestion Lee, if you ever revisit your Scriptwriter lisp, please can we have a box to paste in the folder address (from Windows Explorer) that the script will run on rather than having to browse for it?

0 Likes
Message 6 of 10

Lee_Mac
Advisor
Advisor
sbanister wrote:
Lee wrote:
You may also wish to try my old Script Writer program.

 

One little suggestion Lee, if you ever revisit your Scriptwriter lisp, please can we have a box to paste in the folder address (from Windows Explorer) that the script will run on rather than having to browse for it?

 

Thank you for your suggestion sbanister, there are actually many enhancements that I hope to incorporate into my Script Writer program as and when I find the time to develop the program again. The entire program really needs a complete overhaul and I will likely opt to rewrite the entire code.

 

Nevertheless, I'm pleased to hear that you like the program! 

0 Likes
Message 7 of 10

hmsilva
Mentor
Mentor

@Lee_Mac wrote:

You may also wish to try my old Script Writer program.

 

For your task, simply enter the Script Line as:

 

_.open *file* (load "YourProgram.lsp" nil) (c:YourLISPCommand) _.qsave _.close

Old, but very useful...

 

Cheers

Henrique

EESignature

0 Likes
Message 8 of 10

Lee_Mac
Advisor
Advisor
@hmsilva wrote:

@Lee_Mac wrote:

You may also wish to try my old Script Writer program.

 

For your task, simply enter the Script Line as:

 

_.open *file* (load "YourProgram.lsp" nil) (c:YourLISPCommand) _.qsave _.close

Old, but very useful...

 

Cheers

Henrique

 

Thank you Henrique!

 

Good to see you still active & posting here, I wish I could participate & contribute here more often, but there simply isn't enough time in the day!

0 Likes
Message 9 of 10

hmsilva
Mentor
Mentor

Good to see you here!

 

Henrique

EESignature

0 Likes
Message 10 of 10

dvir860
Enthusiast
Enthusiast

Thank you very much for help

0 Likes