WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   starting Vizard from a Python script (https://forum.worldviz.com/showthread.php?t=13)

hotspur1 03-26-2003 09:11 AM

starting Vizard from a Python script
 
I would like to run a Vizard script from another Python script by something like

os.execv("winviz.exe",['runthisVizardscript.py'])

but when I try this, I get a dialog box that says Vizard must be running first. Also, when I click the 'ok' button, it seems to hang up the Pythonwin program.... Normally, I would not be using Pythonwin but the calling script would be executed from the Command prompt or equivalent.

Any thoughts on how I can do this?

Thanks in advance.

farshizzo 03-26-2003 09:32 AM

Hi,

To run a Vizard script from the command line you need to execute
'Vizard.exe' and pass the file name and "-r" as the arguments. This will basically open up the main Vizard program and immediatley run the specified script. Here's an example:

C:\Program Files\Vizard\bin\Vizard C:\myscript.py -r

One thing to note, if there are spaces in the name of your script path you need to inclose it within quotes:

C:\Program Files\Vizard\bin\Vizard "C:\my script.py" -r

Good Luck!

-- farshid

hotspur1 03-26-2003 10:04 AM

:)

Thanks. That works like a charm! I think you put the quotes around the wrong part of the command in your example....

As a follow-up, is there a clean way to exit Vizard as well? I can exit the graphics portion with viz.quit() but is there a way to also exit Vizard.exe without using the menu option?

farshizzo 03-26-2003 11:27 AM

Hi,

Currently there is no way to exit the main vizard program with a command, but I can easily add this feature for the next release.

For now you can do the following, which basically finds the handle to the vizard window and sends a close message to it:

import win32ui

VizardWindow = win32ui.FindWindow("WorldvizVizardClass",None)

VizardWindow.SendMessage(16,0,0)

Hope that helps!

-- farshid

hotspur1 03-26-2003 02:08 PM

Thanks for the workaround - although I discovered that I had to make sure that the Pythonwin package was installed to have access to the win32ui module. I was not running the python script via Vizard although, I suspect that I will do this eventually.

Thanks also for putting this feature into the list for the next release.

hotspur1 03-26-2003 02:18 PM

Oops - one more comment to my previous post. My Vizard script protests when I try to include the win32ui methods, or at least, I cannot use them after a call to vrut.quit() (It's in part of a keyboard event handler routine). If I don't use vrut.quit() then it seems to run ok. Will the future command allow me to shut down all windows?

farshizzo 03-26-2003 03:09 PM

Hi,

Once vrut.quit() is called the program stops execution, that's why the win32ui commands aren't being called. Try running the win32ui commands before vrut.quit(). This should work fine since the main vizard program is a separate process than the winviz program. So your keyboard handler should look something like this:

def mykeyboard(key):

if key == 'q':
import win32ui
window = win32ui.FindWindow('WorldvizVizardClass',None)
window.SendMessage(16,0,0)
vrut.quit()

Hope that works!

-- farshid

hotspur1 03-27-2003 06:23 AM

OK, that did the trick - thanks!

Andy

hotspur1 05-01-2003 07:11 AM

v1.09 include this type of quit
 
Just wondering if this functionality made it into v1.09? I can still use the workaround, but curious if there is a new method like

viz.quitall()

that handles it nicely?

Thanks
Andy

farshizzo 05-01-2003 09:06 AM

Hi Andy,

There is no built in way of closing the main Vizard application, but you can pass it the '-e' flag through the command line to make it exit. This is probably nicer than the previous way, however I'll just go ahead and implement a "quitall()" method while I'm at it. =)

-- farshid

JRichizzle 03-14-2005 03:01 PM

Is this "quitall()" functionality now included in Vizard 2.50 or 2.51? I would like to be able to close Vizard.exe from within a Vizard script.

farshizzo 03-15-2005 11:16 AM

The command will not work. It was created before the ability to launch a script from outside the GUI. Here is the code for it if you still need it:
Code:

def quitall():
        #Send '-e' flag to vizard to make it exit
        path = _WIN_VIZ_PATH
        #Make sure vizard_path exists
        if len(path) > 0:
                if path[-1] != '\\':
                        path += '\\'
                path += 'bin\\Vizard.exe" -e'
                path = '"' + path
                os.system(path)
        #Now quit winviz
        quit()


zumbay 06-12-2019 12:03 PM

hey,

is there a build-in function for closing the application by now?

thanks!


All times are GMT -7. The time now is 07:19 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC