Author Topic: Open Multiple Drawing from the command line  (Read 2341 times)

0 Members and 1 Guest are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Open Multiple Drawing from the command line
« on: December 12, 2011, 10:00:26 AM »
Is it possible to open multiple drawing from the command line with filedia set to 0?

Let say I want to run a lisp to open 10 different drawings, I would use something like

(command "open" .....

Can I supply multiple drawings using a separator.  It would be like selecting multiple drawing in the file open dialog?

Thanks
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Open Multiple Drawing from the command line
« Reply #1 on: December 12, 2011, 10:16:07 AM »
I though you couldn't access the OPEN command with LISP? You *could* try something like this...

Code: [Select]
(defun _OpenFiles (filelist / shell file)
  (setq shell (vlax-create-object "Shell.Application"))
  (foreach file filelist
    (if (setq file (findfile file))
      (vl-catch-all-apply (function vlax-invoke) (list shell 'Open file))
    )
  )
  (vlax-release-object shell)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Open Multiple Drawing from the command line
« Reply #2 on: December 12, 2011, 10:44:58 AM »
Or doing it through ActiveX:
Code: [Select]
(vl-load-com)

(defun OpenDrawings (filelist / doc-collection)
  (setq doc-collection (vla-get-Documents (vlax-get-acad-object)))
  (foreach file filelist
    (if (and (setq file (findfile file))
             (vl-catch-all-error-p (vl-catch-all-apply 'vla-Item (list doc-collection file)))
        )
      (vla-Open doc-collection file :vlax-false)
    )
  )
)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Open Multiple Drawing from the command line
« Reply #3 on: December 12, 2011, 10:52:42 AM »
Or doing it through ActiveX:
Code: [Select]
(vl-load-com)

(defun OpenDrawings (filelist / doc-collection)
  (setq doc-collection (vla-get-Documents (vlax-get-acad-object)))
  (foreach file filelist
    (if (and (setq file (findfile file))
             (vl-catch-all-error-p (vl-catch-all-apply 'vla-Item (list doc-collection file)))
        )
      (vla-Open doc-collection file :vlax-false)
    )
  )
)
Oh yeah, duh!
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Open Multiple Drawing from the command line
« Reply #4 on: December 12, 2011, 10:54:36 AM »
Thanks Alan/irneb,

That is exactly what I was looking for.  I believe Open can be done is lisp but it will exit the lisp once that dwg becomes active?

This is part of a Batch process program I am building for my company, that will use a line in the acad.lsp to look for a .batch file (a lisp) that is stored in a certain location.  The program gets the batch process that the user wants to run (it copies it (.batch) to a local directory) then opens the drawings the user wants to process. (the .batch will close each drawing).  A line in the acad.lsp looks for the .batch, if it exists it runs it, if not it opens normally. It will also check for the dwgname.  Once the list of drawings are selected by the user it will add BatchEnd.dwg to the end of the list.  Once it opens this dwg, the .batch will get deleted and the BatchEnd.dwg will get closed. (this will "reset" the batch).

There is a bit more to it than this obviously but it gives you an idea.  We currently select a pull down which overwrites the acad.lsp to a lisp that is used to batch process.  However if the user forgets to restore the acad.lsp every time they open a dwg it starts the batch.  It works great but is cumbersome to the end user.

This has been an long process (they hate change here) so I need to have something solid to demo before they will even give it a chance.


ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Open Multiple Drawing from the command line
« Reply #5 on: December 12, 2011, 11:11:00 AM »
You mean similar to Kean's attempt here: http://through-the-interface.typepad.com/through_the_interface/2009/06/index.html

BTW, my code has a bug. I'm effectively testing if the file is already opened. But I'm using its full name as the vla-Item - which is wrong. It should be more like this:
Code: [Select]
(defun OpenDrawings (filelist / doc-collection)
  (setq doc-collection (vla-get-Documents (vlax-get-acad-object)))
  (foreach file filelist
    (if (and (setq file (findfile file))
             (vl-catch-all-error-p
               (vl-catch-all-apply
                 'vla-Item
                 (list doc-collection (strcat (vl-filename-base file) (vl-filename-extension file)))
               )
             )
        )
      (vla-Open doc-collection file :vlax-false)
    )
  )
)

Or even a more correct way:
Code: [Select]
(defun OpenDrawings2 (filelist / doc-collection testopen)
  (defun testopen (file / n opened)
    (setq n 0)
    (while (and (not opened) (< n (vla-get-Count doc-collection)))
      (setq opened (eq file (vla-get-FullName (vla-Item doc-collection n)))
            n (1+ n)
      )
    )
  )
  (setq doc-collection (vla-get-Documents (vlax-get-acad-object)))
  (foreach file filelist
    (if (and (setq file (findfile file))
             (not (testopen file))
        )
      (vla-Open doc-collection file :vlax-false)
    )
  )
)

But for your case you'd actually want the file closed before opening. I.e. if the file is already open, then close it so a new open fires your acaddoc.lsp file to continue the code from there.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Open Multiple Drawing from the command line
« Reply #6 on: December 12, 2011, 11:14:49 AM »
BTW, that code of Kean's shows a simpler method of doing this. You basically save a list of DWGs to open into a file then open the 1st. The AcadDoc.LSP then performs your batch script, removed the 1st DWg from the list, resaves to the same file and opens the next. Until the file doesn't contain any more DWGs.

I'd modify his code slightly by using a vl-bb-set & -ref instead of the file though. Makes it ever so slightly simpler as well.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Open Multiple Drawing from the command line
« Reply #7 on: December 12, 2011, 11:54:19 AM »
You mean similar to Kean's attempt here: http://through-the-interface.typepad.com/through_the_interface/2009/06/index.html


Yeah, Similar.  I tried his method but I got mixed results from it.  I used it as a study guide, and in keeping with what this company already had, just kinda joining the 2 together.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016