Author Topic: Running External Programs  (Read 2778 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Running External Programs
« on: October 21, 2020, 07:31:10 PM »
I am currently using StartApp to launch an external program; however, I need to wait for that external program to finish its job before my LISP routine continues. I know it would be possible to use DOSLib to do this; however, I would like to avoid dependence on a third party if I can, does anyone have some ideas?

I could potentially loop until a file is created; however, there is the very real possibility that the file won't get created all of the time and would end up in an endless loop, so I would like something with a bit more of a failsafe.

framednlv

  • Newt
  • Posts: 64
Re: Running External Programs
« Reply #1 on: October 21, 2020, 07:43:16 PM »
What happens if you use Start?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Running External Programs
« Reply #2 on: October 21, 2020, 08:07:17 PM »
Use an instance of shell with the wait flag set to true (-1).
Bonus, set the visibility flag to 0 if you to hide execution.
The external program may override the latter.

e.g.

(progn
    (setq shell (vlax-create-object "WScript.Shell"))
    (vl-catch-all-apply 'vlax-invoke (list shell 'run "cmd.exe" 8 -1)))
    (alert "lol, there you are.")
    (vl-catch-all-apply 'vlax-release-object (list shell))
    (princ)
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Running External Programs
« Reply #3 on: October 22, 2020, 02:25:05 PM »
What happens if you use Start?
I tried that and it kept launching another session of AutoCAD, no idea why.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Running External Programs
« Reply #4 on: October 22, 2020, 05:09:04 PM »
Use an instance of shell with the wait flag set to true (-1).
Bonus, set the visibility flag to 0 if you to hide execution.
The external program may override the latter.

e.g.

(progn
    (setq shell (vlax-create-object "WScript.Shell"))
    (vl-catch-all-apply 'vlax-invoke (list shell 'run "cmd.exe" 8 -1)))
    (alert "lol, there you are.")
    (vl-catch-all-apply 'vlax-release-object (list shell))
    (princ)
)


Thank you, that did the trick, I am actively getting there on my routine, I am quite surprised at how well this is working. I will eventually share the whole package, but there are a lot of pieces to it.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Running External Programs
« Reply #5 on: October 22, 2020, 05:40:14 PM »
Thank you, that did the trick

you're most welcome 👍

I am quite surprised at how well this is working

oh ye of little faith 🙃
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Running External Programs
« Reply #6 on: October 22, 2020, 07:45:11 PM »
I am quite surprised at how well this is working

oh ye of little faith 🙃
Considering everywhere says what I am doing is literally impossible, I definitely will admit to having little faith on this one.

When it fully works, I will have an amazing way to make sheet indexes and keep them up to date, including revision numbers inside of blocks in a table.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Running External Programs
« Reply #7 on: October 22, 2020, 11:01:56 PM »
everyone says what I am doing is literally impossible

summary of my career right there, lol :-D

When it fully works, I will have an amazing way to make sheet indexes and keep them up to date, including revision numbers inside of blocks in a table.

That's pretty awesome. I'm honoured I could contribute a little here, a little there.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Running External Programs
« Reply #8 on: October 23, 2020, 11:43:41 AM »
everyone says what I am doing is literally impossible

summary of my career right there, lol :-D

When it fully works, I will have an amazing way to make sheet indexes and keep them up to date, including revision numbers inside of blocks in a table.

That's pretty awesome. I'm honoured I could contribute a little here, a little there.
It will be once all is said and done, there are a lot of moving pieces and unfortunately, using the actual Revision Number field in the sheet set manager doesn't seem to work well, there is something funky with that field. I will keep at it, as eventually I want to use that, but in the meanwhile I have a work around.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Running External Programs
« Reply #9 on: October 26, 2020, 07:32:46 PM »
everyone says what I am doing is literally impossible

summary of my career right there, lol :-D

When it fully works, I will have an amazing way to make sheet indexes and keep them up to date, including revision numbers inside of blocks in a table.

That's pretty awesome. I'm honoured I could contribute a little here, a little there.
As promised, I have uploaded my routine, but it is slower than I would like when creating the sheet index using larger DST files. Smaller ones are ok, but larger are problematic, it has been posted to: https://www.theswamp.org/index.php?topic=56345.new#new

I am hoping to figure out why reading the resulting file and creating a table is so slow.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Running External Programs
« Reply #10 on: October 27, 2020, 05:09:55 PM »
I am hoping to figure out why reading the resulting file and creating a table is so slow.

I think that you have forgot something.

 :whistling:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Running External Programs
« Reply #11 on: October 27, 2020, 05:14:13 PM »
I am hoping to figure out why reading the resulting file and creating a table is so slow.

I think that you have forgot something.

 :whistling:
Actually, I added that in as well and it still is slow.

I made some more changes and realized it wasn't working before, but now I get automation error when I use it.
« Last Edit: October 27, 2020, 05:29:13 PM by cmwade77 »

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Running External Programs
« Reply #12 on: October 27, 2020, 06:54:37 PM »
It seems the slowness is in the reading of the text file, I have attached an updated version of the .LSP file and a sample copy of the fields file it needs to read in.