I've just started learning about Gimp scripting using Python, and was wondering, how do I output text to the console? I am using version 2.7.5 on Windows 7.
I tried the print function, but it does not write anything to the python-fu console or the dev console that launches with Gimp. Is there a function I should use to do this? or is this a problem with the 2.7.5 release? I found a few mentions of "gimp-message" but that seems to be a function used with Scheme (Script-fu)
Thanks!
(also posted as a thread here)
The simplest way to write to the console or visual display is python's print function. When the print statement in the script was executed, the string 'Hello, world!' appeared on the visual display in front of us. In technical terms the string was written to standard output, usually the console.
The console appears as a tool window every time you choose the corresponding command on the Tools menu. You can assign a shortcut to open Python console: press Ctrl+Alt+S , navigate to Keymap, specify a shortcut for Main menu | Tools | Python or Debug Console.
Running the Automation Tools on a WorkflowThe tools will open up, work on, save, and close the images one by one. In an earlier tutorial “Automated Jpg to Xcf” we outlined how to import a directory containing jpeg images into a directory with gimp xcf images.
Where To Put Zip Files & Python Scripts. You will need to copy the files for these plugins to the GIMP plugins directory. Extract the zip files first and copy the contents, not the zip file. Go to Edit > Preferences > Folders > Plugins to get to the plugins directory.
We can redirect stdout and stderr.
#!/usr/bin/env python
# coding: iso-8859-1
from gimpfu import *
import sys
sys.stderr = open( 'c:\\temp\\gimpstderr.txt', 'w')
sys.stdout = open( 'c:\\temp\\gimpstdout.txt', 'w')
def MyUsefulFilter(img, drw):
# these print redirected to gimpstdout.txt
print 'hello world'
print img
print drw
# this error redirected to gimpstderr.txt
x = 0
y = 1/x
pdb.gimp_image_undo_group_start(img)
# useful code here
pdb.gimp_image_undo_group_end(img)
register(
"useful_filter",
"very useful indeed",
"",
"MF",
"GPL",
"2013",
"<Image>/Filters/Photo/Useful Filter",
"RGB*",
[],
[],
MyUsefulFilter)
main()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With