printing on console from a script?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
roegel
Posts: 73
Joined: Tue Aug 12, 2014 7:21 pm

printing on console from a script?

Post by roegel »

Hi

in my scripts, I want to print some stuff on the console or on the terminal where I launch freecad.
I have tried the following dummy example

Code: Select all

import sys # first two lines to be able to launch with python alone
sys.path.insert(0,'/usr/lib/freecad/lib/')
from FreeCAD import Base
import Part
from math import *

a, b = 1, 2

print("a={0},b={1}".format(a, b))
but it prints nothing if I call freecad on the script. However, if I call python, then it prints
what I expect. Is there a way to get the printout if I run with the GUI?

Thanks,

Denis
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: printing on console from a script?

Post by shoogen »

Then please disable the redirection of internal python output to the report window using Edit -> Preferences -> General -> Output window -> redirect internal ....
mario52
Veteran
Posts: 4670
Joined: Wed May 16, 2012 2:13 pm

Re: printing on console from a script?

Post by mario52 »

hi
since version 0.14 using "print" no longer works (Report view) !??
try with the function

Code: Select all

a = 5
App.Console.PrintMessage("Value  : " + str(a) + "\n")
there also PrintWarning and PrintError

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
wmayer
Founder
Posts: 20113
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: printing on console from a script?

Post by wmayer »

since version 0.14 using "print" no longer works (Report view) !??
For me it still works. You have to enable the option to redirect internal Python messages and errors to the report view.
roegel
Posts: 73
Joined: Tue Aug 12, 2014 7:21 pm

Re: printing on console from a script?

Post by roegel »

Fo me too. shoogen's solution is fine.

Denis
mario52
Veteran
Posts: 4670
Joined: Wed May 16, 2012 2:13 pm

Re: printing on console from a script?

Post by mario52 »

hi
Ok does it work thanks
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Tom1
Posts: 16
Joined: Fri Jul 28, 2017 9:47 pm

Re: printing on console from a script?

Post by Tom1 »

Is there a way to keep all the variables after I run a python script, which means I can still load the python variables on console?
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: printing on console from a script?

Post by triplus »

Tom1 wrote: Thu Aug 31, 2017 1:34 am Is there a way to keep all the variables after I run a python script, which means I can still load the python variables on console?
If you run the script directly in Python console then yes.

P.S. That is you need to define/assign the variable in Python console first.
Post Reply