Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
This is Windows only (see the Python documentation at http://www.python.org).
Other systems may not allow something like this (for security reasons).
If you know whitch program should handle your datafile, perhaps you can use a system call to exec the application.
If you want to show something that a webbrowser can handle, look into the Python docu. There is a "webbrowser" module that runs on any OS where Python is available.
poser.ExecFile('filepath') works on PC and Mac for Poser 5 & 6 and PC Poser 7
Could someone please test with Poser 7 on a Mac. My tests appear to show that it does not.
###########################
pathname = os.path.split(poser.AppLocation())[0]
filePath = os.path.join(pathname, 'Runtime', 'Python', 'poserScripts', 'test', 'execfile_1.py')
poser.ExecFile(filePath)
##########################
print "execfile_1.py run OK"
#########################
Run ExecFileTest.py to execute execfile_1.py
Works on a PC fails on a Mac
As you may know you can find out the seperator actually used by the OS with
os.sep
os.pathsep
sep The character used by the operating system to separate pathname components, for example, "/" for POSIX or ":" for Mac OS 9. Note that knowing this is not sufficient to be able to parse or concatenate pathnames -- use os.path.split() and os.path.join() -- but it is occasionally useful. Also available via os.path.
pathsep The character conventionally used by the operating system to separate search path components (as in PATH), such as ":" for POSIX or ";" for Windows. Also available via os.path.
poser.ExecFile() and execfile() both are to start Python scripts only.
If you need to start any other executable from within Python, you probably may want to use os.popen(). But better read the docu :)
popen( command[, mode[, bufsize]]) Open a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r'
(default) or 'w'
. The bufsize argument has the same meaning as the corresponding argument to the built-in open() function. The exit status of the command (encoded in the format specified for wait()) is available as the return value of the close() method of the file object, except that when the exit status is zero (termination without errors), None
is returned. Availability: Macintosh, Unix, Windows.
Changed in version 2.0: This function worked unreliably under Windows in earlier versions of Python. This was due to the use of the _popen() function from the libraries provided with Windows. Newer versions of Python do not use the broken implementation from the Windows libraries.
@**semidieu:
** Mayby you are interested to know that python has some special Macintosh libs. Search the online docu for Macintosh. :
Save as'' versus
Save as Applet''Thanks... I was hoping it could be easier...
I already tried "popen", but it seems to not work exactly the same on PC or Mac. For example:
os.popen('notepad.exe text.txt')
work for PC. But for Mac, someone told me to use:
os.popen('open text.txt').
This doesn't work on PC... and I can't test on a Mac to check if it's working...
import sys
if sys.platform.startswith("win") :
ex = "notepad.exe"
else:
ex = "open"
os.popen("%s text.txt" % ex)
But, sorry, why would you do that? Any user should be able to start his prefered texteditor without any help.
What about getting the text you need with a dialog and store it where it belongs to?
I'm working on a GUI interface to apply the Art Materials shader by Olivier. I want to "disable" the AO feature when the material correspond to a list of name in a text file. This text file must be editable, so everyone can make their own "list" (add, remove, edit).
And... yes, you could simply browse the folder and double-click the file to open... But I would like it to be accessible directly from my GUI.
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
Using Windows, I can use: os.startfile(PathToFile) to open a file in it's default application. Does anyone know or can anyone test if this also works on a Mac???
If it doesn't work, does anyone know how I can accomplish the same on a Mac?
Thanks in advance,
--Naylin
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
My Store My Gallery
____
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
"You have the right to remain silent. Anything you say can and will be misquoted and then used against you."