Author Topic: Process a list of Drawing Files  (Read 3967 times)

0 Members and 1 Guest are viewing this topic.

Vince

  • Newt
  • Posts: 55
Process a list of Drawing Files
« on: August 16, 2012, 10:09:01 AM »
Hi Swamp Members,

I must have brain freeze or something and need a little help.......I used the Get Files Dialog utility from the Lee Mac Programming website and it works great to allow me to select the files I want to process however, I can not figure out how to use the list of drawings to run some AutoCAD commands on. In this case I want to reload any unloaded x-reference files and then bind all of the x-reference files for all of the drawings.

Code: [Select]
;;------------------=={ Get Files Dialog }==------------------;;
;;                                                            ;;
;;  An analog of the 'getfiled' function for multiple files.  ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  title   - String specifying the dialog box label.         ;;
;;  default - Default directory; can be a null string ("")    ;;
;;  ext     - Filename extension filter (e.g. "dwg;lsp")      ;;
;;------------------------------------------------------------;;
;;  Returns:  List of selected files, else nil                ;;
;;------------------------------------------------------------;;
;;  Version 1.1    -    12-01-2012                            ;;
;;------------------------------------------------------------;;
http://lee-mac.com/getfilesdialog.html

Can Anyone provide some assistance in accomplishing this....??   Any help would be appreciated.


Regards,
Vince
« Last Edit: August 16, 2012, 10:39:21 AM by CAB »

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Process a list of Drawing Files
« Reply #1 on: August 16, 2012, 10:26:08 AM »
Vince, I would prefer if you provided a link to the function in question rather than post the code in its entirety on the forum, otherwise version control becomes a nightmare as the code is out of my control.

Please read:

http://www.theswamp.org/index.php?topic=2621.msg33156#msg33156

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Process a list of Drawing Files
« Reply #2 on: August 16, 2012, 10:40:37 AM »
Message edited for header only plus link.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Vince

  • Newt
  • Posts: 55
Re: Process a list of Drawing Files
« Reply #3 on: August 16, 2012, 10:47:08 AM »
My apologies Lee.......It will not happen again, I am now more educated on Swamp policies....!

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Process a list of Drawing Files
« Reply #4 on: August 16, 2012, 11:26:37 AM »
Message edited for header only plus link.

Cheers Alan  :-)

My apologies Lee.......It will not happen again, I am now more educated on Swamp policies....!

No worries  :-)

Now, back to your question: to clarify, my utility simply provides an interface for the user to select a number of drawings from various directories (and will return a list of those selected drawings), it will not operate on the selected drawings in any way.

Given the list of drawings, you could operate on them using either a Script or ObjectDBX. For the ObjectDBX route, I have written an ObjectDBX Wrapper function allowing you to evaluate a function (compatible with ObjectDBX) on a list of drawings.

If you alternatively wanted to use a Script, you could use a LISP function to construct the Script from the list of selected drawings, then run this Script using the 'script' command from the command-line.


Vince

  • Newt
  • Posts: 55
Re: Process a list of Drawing Files
« Reply #5 on: August 16, 2012, 12:11:43 PM »
I tried this approach at the end of your utility and it failed:

Code: [Select]
  (setq File#1   (open "c:/temp/BatchrunX.scr" "w" ) )
  (foreach DwgName result
        (setq FileName result)
        (princ "open\n" File#1 )
        (princ (strcat FileName) File#1 )

        (princ  Do Something Here)

        (princ "_.close\n" File#1 )
        (princ "N\n" File#1 ) ; do save
  )
  (close File#1 )
        (command "._script" "C:/temp/BatchrunX.scr" )
        (princ)
It opened the BatchrunX.scr file then failed..........Obviously I am missing something.....?



Regards
Vince
« Last Edit: August 16, 2012, 12:14:59 PM by CAB »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Process a list of Drawing Files
« Reply #6 on: August 16, 2012, 01:39:45 PM »
I think this might be the issue:
Code - Auto/Visual Lisp: [Select]
  1. (foreach DwgName result
  2.         (setq FileName DwgName) ;Note write the current filename, not the entire list
Although you don't need to do that either. This should be enough:
Code - Auto/Visual Lisp: [Select]
  1. (foreach DwgName result
  2.   (princ "open\n" File#1 )
  3.   (princ DwgName File#1 )
  4.   ;; ... continued
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Process a list of Drawing Files
« Reply #7 on: August 16, 2012, 03:17:48 PM »
I tried this approach at the end of your utility and it failed:

There should be no need to modify my function in any way (that also applies to all of the functions posted in the subfunction library section of my site), instead, you should call the function with the necessary arguments, then use the return of the function in your program.

To explain, think about my function (or any subfunction) as just another in-built LISP function, and imagine that you have no access to the source code for my function.

Without access to the source code, you wouldn't know how the function works, or be in any position to edit the function definition, but you do know that the function requires a number of arguments (or parameters) and will return a known result after performing some operation.

Compare this to how you would use the AutoLISP getfiled function: you obviously don't have access to the source code for the getfiled function (as it is defined in a compiled arx file), yet you know that the function requires four arguments (dialog title, default directory, file extension filter, bit-code), and will return a filename if the user selects a file.

In your code you might call the getfiled function in the following way in order to prompt the user to select a Text File:

Code - Auto/Visual Lisp: [Select]
  1. (setq file (getfiled "Select a Text File" "" "txt" 16))

Notice how the above example sets the return of the getfiled function to the variable 'file' for later use in the program.

Now consider using my LM:GetFiles function.

As noted in the code header, my function requires three arguments (dialog title, default directory & file extension filter - much the same as the getfiled function), and my function will return either a list of filenames or nil if the user pressed cancel or failed to select any files.

With this knowledge, you needn't know how my function works (though of course it would be prudent to study it for learning purposes), but you can confidently call it in your program, knowing that the user will be presented with a file selection interface customised by the parameters you have passed to the function, and also knowing all of the possible return values for the function.

So, just like the getfiled function, you can call my LM:GetFiles function in the following way to prompt the user to select multiple Text files:

Code - Auto/Visual Lisp: [Select]
  1. (setq filelist (LM:GetFiles "Select Text Files" "" "txt"))

However, having extensively described this particular example, consider that you are in fact implementing this logic for every AutoLISP function that you are using in your program.

For every AutoLISP function, you know the parameters required by the function, and you know what the function will return when called in your program.

Consider the somewhat trivial functions, such as the sqrt function: you have no access to know the exact method that the sqrt function is using to calculate the square root of its argument, but you do know that if you supply it will a valid numerical argument, the function will return the square root of that number, which you can then use in your program.
« Last Edit: August 16, 2012, 03:22:12 PM by Lee Mac »

Vince

  • Newt
  • Posts: 55
Re: Process a list of Drawing Files
« Reply #8 on: August 17, 2012, 08:56:42 AM »
Hi Lee,

I have been successful in getting the "script" option working for the list of files obtained from your Get Files Dialog routine......thank you very much for the routine and your expert assistance. I do have a question regarding the Select Files dialog box. The dialog box appears instantly however, it takes a long time for the directories to populate the box and I can browse to my desired folder. Is there a way to speed this up....??  Am I doing something incorrectly....??

Thanks again for your help.


Regards,
Vince