Visual LISP, AutoLISP and General Customization

Reply
Active Member
jj26
Posts: 7
Registered: ‎02-05-2013
Message 1 of 6 (723 Views)

running lisp routine inside script

723 Views, 5 Replies
02-07-2013 08:20 PM

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)

 

Distinguished Mentor
Moshe-A
Posts: 735
Registered: ‎09-14-2003
Message 2 of 6 (701 Views)

Re: running lisp routine inside script

02-07-2013 11:37 PM 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

 

Active Contributor
AlessiMarc'Antonio
Posts: 49
Registered: ‎12-04-2006
Message 3 of 6 (685 Views)

Re: running lisp routine inside script

02-08-2013 09:45 AM 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
Active Member
jj26
Posts: 7
Registered: ‎02-05-2013
Message 4 of 6 (661 Views)

Re: running lisp routine inside script

02-10-2013 08:29 PM 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.

Active Contributor
AlessiMarc'Antonio
Posts: 49
Registered: ‎12-04-2006
Message 5 of 6 (646 Views)

Re: running lisp routine inside script

02-11-2013 12:55 AM 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
Active Member
jj26
Posts: 7
Registered: ‎02-05-2013
Message 6 of 6 (637 Views)

Re: running lisp routine inside script

02-11-2013 02:13 AM 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community