Fri, Nov 29, 1:57 AM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: os.startfile


Naylin ( ) posted Thu, 01 February 2007 at 3:41 AM · edited Mon, 25 November 2024 at 12:37 PM

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."


adp001 ( ) posted Thu, 01 February 2007 at 1:44 PM

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.




PhilC ( ) posted Sat, 03 February 2007 at 1:54 AM

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.

###########################

Save as :Runtime:Python:poserScripts:test:ExecFileTest.py

pathname = os.path.split(poser.AppLocation())[0]
filePath = os.path.join(pathname, 'Runtime', 'Python', 'poserScripts', 'test', 'execfile_1.py')
poser.ExecFile(filePath)

##########################

Save as :Runtime:Python:poserScripts:test:execfile_1.py

print "execfile_1.py run OK"

#########################

Run ExecFileTest.py to execute execfile_1.py

Works on a PC fails on a Mac


adp001 ( ) posted Sat, 03 February 2007 at 5:08 PM

Hm. No need to assemble a filename for poser.ExecFile().
poser.ExecFile("Runtime:Python:poserScripts:<script.py>") works fine for windows (and should for Macs, too).

If poser.ExecFile() won't work on Macs with P7, try Pythons execfile() insteed.




PhilC ( ) posted Mon, 05 February 2007 at 7:51 AM

Thanks, execfile() works on Poser 7 Mac. I'd forgotten that it was the same word just lower case.

Incidentally am I right that the Mac path delimiter has changed to "/" 

Again thanks.


adp001 ( ) posted Mon, 05 February 2007 at 8:14 AM · edited Mon, 05 February 2007 at 8:16 AM

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.




semidieu ( ) posted Mon, 05 February 2007 at 8:16 AM

Great info !

But does it work for all kind of file, or only Python files ? For example, I wanted to open a text file in the default editor. Will this work with ExecFile (and execfile for Mac) ?


adp001 ( ) posted Mon, 05 February 2007 at 9:33 AM

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.




adp001 ( ) posted Mon, 05 February 2007 at 9:43 AM

@**semidieu:

** Mayby you are interested to know that python has some special Macintosh libs. Search the online docu for Macintosh. :

  • Front Matter
  • Contents
    1. Using Python on a Macintosh - 1.1 Getting and Installing MacPython - 1.1.1 How to run a Python script
  • 1.1.2 Running scripts with a GUI
  • 1.1.3 configuration
  • 1.2 The IDE - 1.2.1 Using the ``Python Interactive'' window
  • 1.2.2 Writing a Python Script
  • 1.2.3 Executing a script from within the IDE
  • 1.2.4 Save as'' versusSave as Applet''
  • 1.3 The Package Manager
    1. MacPython Modules - 2.1 macpath -- MacOS path manipulation functions
  • 2.2 macfs -- Various file system services - 2.2.1 FSSpec Objects
  • 2.2.2 Alias Objects
  • 2.2.3 FInfo Objects
  • 2.3 ic -- Access to Internet Config - 2.3.1 IC Objects
  • 2.4 MacOS -- Access to Mac OS interpreter features
  • 2.5 macostools -- Convenience routines for file manipulation
  • 2.6 findertools -- The finder's Apple Events interface
  • 2.7 EasyDialogs -- Basic Macintosh dialogs - 2.7.1 ProgressBar Objects
  • 2.8 FrameWork -- Interactive application framework - 2.8.1 Application Objects
  • 2.8.2 Window Objects
  • 2.8.3 ControlsWindow Object
  • 2.8.4 ScrolledWindow Object
  • 2.8.5 DialogWindow Objects
  • 2.9 autoGIL -- Global Interpreter Lock handling in event loops
    1. MacPython OSA Modules - 3.1 gensuitemodule -- Generate OSA stub packages
  • 3.2 aetools -- OSA client support
  • 3.3 aepack -- Conversion between Python variables and AppleEvent data containers
  • 3.4 aetypes -- AppleEvent objects
  • 3.5 MiniAEFrame -- Open Scripting Architecture server support - 3.5.1 AEServer Objects
    1. MacOS Toolbox Modules - 4.1 Carbon.AE -- Apple Events
  • 4.2 Carbon.AH -- Apple Help
  • 4.3 Carbon.App -- Appearance Manager
  • 4.4 Carbon.CF -- Core Foundation
  • 4.5 Carbon.CG -- Core Graphics
  • 4.6 Carbon.CarbonEvt -- Carbon Event Manager
  • 4.7 Carbon.Cm -- Component Manager
  • 4.8 Carbon.Ctl -- Control Manager
  • 4.9 Carbon.Dlg -- Dialog Manager
  • 4.10 Carbon.Evt -- Event Manager
  • 4.11 Carbon.Fm -- Font Manager
  • 4.12 Carbon.Folder -- Folder Manager
  • 4.13 Carbon.Help -- Help Manager
  • 4.14 Carbon.List -- List Manager
  • 4.15 Carbon.Menu -- Menu Manager
  • 4.16 Carbon.Mlte -- MultiLingual Text Editor
  • 4.17 Carbon.Qd -- QuickDraw
  • 4.18 Carbon.Qdoffs -- QuickDraw Offscreen
  • 4.19 Carbon.Qt -- QuickTime
  • 4.20 Carbon.Res -- Resource Manager and Handles
  • 4.21 Carbon.Scrap -- Scrap Manager
  • 4.22 Carbon.Snd -- Sound Manager
  • 4.23 Carbon.TE -- TextEdit
  • 4.24 Carbon.Win -- Window Manager
  • 4.25 ColorPicker -- Color selection dialog
    1. Undocumented Modules - 5.1 applesingle -- AppleSingle decoder
  • 5.2 buildtools -- Helper module for BuildApplet and Friends
  • 5.3 cfmfile -- Code Fragment Resource module
  • 5.4 icopen -- Internet Config replacement for open()
  • 5.5 macerrors -- Mac OS Errors
  • 5.6 macresource -- Locate script resources
  • 5.7 Nav -- NavServices calls
  • 5.8 PixMapWrapper -- Wrapper for PixMap objects
  • 5.9 videoreader -- Read QuickTime movies
  • 5.10 W -- Widgets built on FrameWork
  • A. History and License - A.1 History of the software
  • A.2 Terms and conditions for accessing or otherwise using Python
  • A.3 Licenses and Acknowledgements for Incorporated Software - A.3.1 Mersenne Twister
  • A.3.2 Sockets
  • A.3.3 Floating point exception control
  • A.3.4 MD5 message digest algorithm
  • A.3.5 Asynchronous socket services
  • A.3.6 Cookie management
  • A.3.7 Profiling
  • A.3.8 Execution tracing
  • A.3.9 UUencode and UUdecode functions
  • A.3.10 XML Remote Procedure Calls
  • Module Index
  • Index
  • About this document ...




semidieu ( ) posted Tue, 06 February 2007 at 6:42 AM

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...


adp001 ( ) posted Tue, 06 February 2007 at 7:05 AM

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?




semidieu ( ) posted Tue, 06 February 2007 at 8:17 AM

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.


Privacy Notice

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.