Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Calling a LISP function in many drawings

  1. #1
    Login to Give a bone
    0

    Default Calling a LISP function in many drawings

    Hi

    I have a very handy LISP program (thanks to pbejse) but I'm trying to learn how to apply it to many drawings in the one directory. I tried Lee Macs script writer but didnt have much luck.


    I typed this into the script line but it only came up with invalid file name and had me select a drawing file. I'm not sure where I went wrong here.

    _.open *file* (load "C:\\Users\\Daniel\\Documents\\AutoCAD programs\\ReTagDup.lsp") retagdup _.saveas *file* _.close



    I tried installing scriptpro but due to recent IT changes I'm having trouble installing new programs so didn't have any luck there.


    Any ideas?

  2. #2
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    check the file name syntax

    _.open "D:/DrawingFolder/wright.dwg" (load "C:\\Users\\Daniel\\Documents\\AutoCAD programs\\ReTagDup.lsp") retagdup _.saveas "othername" _.close

    "/" <-- forward slash for drawing filename

    and

    _.saveas "othername" <--extra space after _saveas

    Note that the prompts and their order may change from version to version

    You can however pre-load the lisp routine , read this from LM webiste http://www.lee-mac.com/autoloading.html
    Last edited by pbejse; 2012-07-09 at 06:33 AM.

  3. #3
    Member
    Join Date
    2009-10
    Posts
    10
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    If I need to run a lisp or lisps on multiple drawings in a folder, I use a neat little free third party program called Starbatch.
    It runs direct without altering the registry.

    Can be found here: -

    http://sourceforge.net/projects/starbatch/

    I wouldn't be without this very useful application.

  4. #4
    Member
    Join Date
    2011-10
    Posts
    2
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    Probably another way is to have a batch file, a script and your lisp program.
    batch file example (saved as batch.bat):
    Code:
     FOR %%V IN (*.DWG) DO START /W "C" "C:\Program Files\Autocad 2010\acad.exe" %%V /b "script"
    script file example (saved as script.scr):
    Code:
    (load "C:/Your Folder Path/LISP.lsp") Test
    The "Test" is lisp syntax.

  5. #5
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    Hi everyone.

    Thanks for the help but as usual I'm lost.

    pbejse - What I wrote there was what I was trying to write into Lee Mac's script writer. *file* (i thought) was a token in the program replaced with each name of the drawings in the directory. Didn't realise double space after saveas but it didn't seem to help.

    mark.232312 - i downloaded starbatch but couldn't get it to actually open autocad. not sure what was going wrong there

    dong95 - not sure where to start with your method. How do I call the batch file? Will that code save each file? How does it know which drawing files to open? Does it focus on a specific directory?

  6. #6
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    Hi,

    Try this ?
    Start this lisp in a new drawing, and after result, use the srcript command for execute it
    Code:
    (defun c:make_script ( / prefix file_scr)
    	(setq
    		prefix (strcat (vl-filename-directory (getfiled "Select a file drawing for batch your directory" "" "dwg" 16)) "\\")
    		file_scr (open (strcat prefix "batch_dir.scr") "w")
    	)
    	(foreach dwg (vl-directory-files prefix "*.dwg" 1)
    		(write-line "_.open" file_scr)
    		(write-line (strcat "\"" prefix dwg "\"") file_scr)
    ;;Begin of your commands
    		(write-line "(load \"C:\\Users\\Daniel\\Documents\\AutoCAD programs\\ReTagDup.lsp\")" file_scr)
    		(write-line "retagdup" file_scr)
    ;;End of your commands
    		(write-line "_.qsave" file_scr)
    		(write-line "_.close" file_scr)
    	)
    	(close file_scr)
    	(princ (strcat "\nYou can use the SCRIPT :" prefix "batch_dir.scr"))
    	(prin1)
    )
    Last edited by Bruno.Valsecchi; 2012-07-17 at 08:31 AM.

  7. #7
    Member
    Join Date
    2011-10
    Posts
    2
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    Quote Originally Posted by daniel.j.wright112877 View Post
    Hi everyone.

    Thanks for the help but as usual I'm lost.

    pbejse - What I wrote there was what I was trying to write into Lee Mac's script writer. *file* (i thought) was a token in the program replaced with each name of the drawings in the directory. Didn't realise double space after saveas but it didn't seem to help.

    mark.232312 - i downloaded starbatch but couldn't get it to actually open autocad. not sure what was going wrong there

    dong95 - not sure where to start with your method. How do I call the batch file? Will that code save each file? How does it know which drawing files to open? Does it focus on a specific directory?
    The batch file will open the drawing file and will execute the script that calls a lisp routine. Batch process will not open another drawing file unless the script has been executed. The three files (batch, script & lisp) is accompanied on your specific directory.

  8. #8
    Member
    Join Date
    2009-10
    Posts
    10
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    Quote Originally Posted by daniel.j.wright112877 View Post
    mark.232312 - i downloaded starbatch but couldn't get it to actually open autocad. not sure what was going wrong there?
    Hi Daniel,

    To use Starbatch, you need Microsoft .NET Framework 3.5 / 4, loaded onto your computer.

    If you do not have this it could be the problem.

    Can be found here: -

    http://www.microsoft.com/net

  9. #9
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    Cheers guys

    Starbatch still didn't work - I had frame work 4 so i did a repair on it and still no luck.

    Bruno.Valsecchi - beautiful work! Thanks alot. Worked a treat!

  10. #10
    I could stop if I wanted to
    Join Date
    2008-05
    Location
    Yardley, PA
    Posts
    305
    Login to Give a bone
    0

    Default Re: Calling a LISP function in many drawings

    my disclaimer here is that I would say I'm still green at programming. Got some things figured out, but I'm definitely not the cream of the crop type...

    I'm working on the same thing. Still trying to make it work but that is a separate problem I think I will fix in the end...

    Currently I don't get why you have to write a scr file and then tell it to run. Why can't you just say in the lisp program open file, run programs, save, close, open another file, repeat... Instead of writing a lisp program to write a script file to open file, run programs, save, close, open another file, repeat... end writing script, and then tell it to run the script...

    Is it because the lisp program 'lives' in a dwg file and once it is closed it end the lisp program? Can you not keep a default DWG file open to run the lisp program to open other files and such?

    also when you're writing to the script, why do you have to have a file path surrounded by '\'. Ex. \C:\\folder\\folder\\file.dwg\

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 8
    Last Post: 2018-08-18, 02:53 PM
  2. Calling up LISP routine from within another LISP
    By jimmy_goodall in forum AutoLISP
    Replies: 4
    Last Post: 2013-08-21, 05:56 AM
  3. Calling a script from with in a lisp
    By randy.sherwood597724 in forum AutoLISP
    Replies: 4
    Last Post: 2012-06-05, 04:13 PM
  4. Replies: 41
    Last Post: 2007-11-20, 12:32 AM
  5. Help with Sub Function and calling it from main Function
    By avinash00002002 in forum VBA/COM Interop
    Replies: 1
    Last Post: 2006-06-21, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •