Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

running lisp routine inside script

5 REPLIES 5
Reply
Message 1 of 6
jj26
3217 Views, 5 Replies

running lisp routine inside script

Hello,

 

I was wanting to create a script to go through and clean up a bunch of drawings in a given folder. I've written a lisp routine (cleanx) that works fine when you run it on a single drawing, but I'm having some trouble integrating it into a script. As it is currently, I'm experiencing several issues -

 

1) It prompts the user for an 'object' after finding 0 objects. It seems to be caused by the line,

 

(command "-layer" "u"    "*" "t"    "*" "on" "*" "" "")

 

in 'cleanx' based on the text window, but I'm not sure why it does that given that if I run cleanx directly it doesn't prompt me.

 

2) It ends with saying 'Really want to discard all changes to drawing?' which confused me as I use Qsave before I close, and then confused me further when I realised that the text window suggests that this prompt comes up after the 'open' command, and that if I type <Y> (exit without saving) then it asks me to select a file. Why doesn't it save, close and then open the next file automatically?

 

I didn't write this code, but I didn't think I changed enough to break it! Any help is appreciated.

 

;;; Main program, command: batchjob
;;; By Abdul Huck

(defun c:cleanb (/ dwgs file dwgName scrFile folderName)
  (setq folderName
  (browsefolder "Select folder to perform batch job: ")
  )
  (setq dwgs (vl-directory-files folderName "*.dwg"))
  (setq scrFile (open (strcat folderName "\\batchJob.scr") "w"))
  (write-line "SDI 1" scrFile)
  (foreach file dwgs
	(setq dwgName (strcat "\"" folderName "\\" file "\""))
	(write-line ".Open" scrFile)
	(write-line dwgName scrFile)
       	(load "C:/Documents and Settings/jamesr/My Documents/CAD stuff/cleanx.lsp") 
    	(c:cleanx)
    	(write-line ".Qsave" scrFile)
   	(write-line "SDI 0" scrFile)
	(write-line "CLOSE" scrFile)
  )	 
  (close scrFile)  
  (command ".script" (strcat folderName "\\batchJob.scr"))
  (princ)
)	
;;; Function to browse folder
;;; This code was originally posted by kpblc2000 in AUGI AutoLisp Forum
;;;
(defun browsefolder (title / shlobj folder fldobj)
  (vl-load-com)
  (setq
	shlobj (vla-getinterfaceobject
	  (vlax-get-acad-object)
	  "Shell.Application"
	)
	folder (vlax-invoke-method shlobj 'browseforfolder 0 title 0)
  )
  (vlax-release-object shlobj)
  (if folder
	(progn
	  (setq
 fldobj	(vlax-get-property folder 'self)
 folderName (vlax-get-property fldobj 'path)
	  )
	  (vlax-release-object folder)
	  (vlax-release-object fldobj)
	  folderName
	)
  )
)
(princ "\ncleanb is loaded, Type cleanb to run.")
(princ)

 

5 REPLIES 5
Message 2 of 6
Moshe-A
in reply to: jj26

Hi,

 

A script that opens and closes files should be called from out side drawing editor

create a new AutoCAD shortcut on your desktop that have this blue addition

 

"C:\Program Files\Autodesk\AutoCAD 20xx\acad.exe" /b "batchjob"

 

(if batchjob.scr is not on the support path you should add it or prefix the file with a full path name)

revice your code accordingly.

 

why the SDI is needed?

 

Moshe

 

Message 3 of 6
AlessiMarc'Antonio
in reply to: jj26

(command "-layer" "u"    "*" "t"    "*" "on" "*" "" "")

 

Try to remove last ""

Marc'Antonio Alessi

http://alessi.xoom.it//alessi/Programmi.htm
(vl-string-translate "1234567890" "ie@mst.lan" "499825513610716")
2D Parametric for 2000-2013
Message 4 of 6
jj26
in reply to: Moshe-A

SDI was in the original code I received, it doesn't seem to work without it. It seems to be working now, I just had to load my function in using the startup suite and use

 

(write-line "cleanx" scrFile)

in cleanb.lsp. That shortcut thing doesn't seem to work, it says "cannot find the specified drawing file, please check that it exists". Is that because it's cleanb.lsp, not cleanb.scr? Is there a way to run a lisp routine on startup via a shortcut, or do I just have to leave it as is? I guess having to type cleanb isn't a huge problem.

Message 5 of 6
AlessiMarc'Antonio
in reply to: jj26

did you read my reply?

Marc'Antonio Alessi

http://alessi.xoom.it//alessi/Programmi.htm
(vl-string-translate "1234567890" "ie@mst.lan" "499825513610716")
2D Parametric for 2000-2013
Message 6 of 6
jj26
in reply to: AlessiMarc'Antonio

yes Marc'Antonia, thanks : )

 

I removed the extra " " 's when I changed the line I mentioned before. It didn't need the extra space.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost