Forum: Poser Python Scripting


Subject: How do I write to a file?

Anthony Appleyard opened this issue on Jul 17, 2021 ยท 9 posts


HartyBart posted Sat, 17 July 2021 at 11:48 AM

(1). This line in a PoserPython script will do the first part of what you want, at least it will on Windows. Here we open my_text_file.txt with My Text Editor:

subprocess.call([r'C:|Program Files|My_Text_Editor.exe',r'C:|my_text_file.txt'])

(The forum refuses to display backslashes, so pipes have been used above - but you get the idea and can repair it). Note that the r's are important.

(2). Not sure how you would have the script actually type something in my_text_file.txt, other than by launching a desktop macro such as JitBit MacroRecorder + pre-recorded macro by the same method. Possible? But you can have the script rename the file as something-something-something.txt, which may be just as useful. To do that you would use the os.rename command from within the script. (Having first called up the OS module in the script header).

(3). Not sure how you'd then kill the subprocess.call software that you had Poser launch. In some circumstances the called software will just exit when the task is done and the script will carry on. If you are passing the called software its own type of script, then you may be able to conclude that script with an explicit kill-switch that will terminate the .exe. An example of a Windows-only kill-switch for a Photoshop javascript would be:

executeAction(app.charIDToTypeID('quit'), undefined, DialogModes.NO);



Learn the Secrets of Poser 11 and Line-art Filters.