View Issue Details

IDProjectCategoryView StatusLast Update
0004000FreeCADFeaturepublic2020-10-14 21:10
Reporterardenpm Assigned Towmayer  
Status closedResolutionfixed 
Summary0004000: Ability to suppress console output when running under python
DescriptionAs discussed in this forum thread it would be useful to be able to suppress FreeCAD messages:

Forum thread

Currently FreeCAD outputs a lot of messages to stdout during its operation. Typically this is very helpful, however in cases where it is desirable to using piping of output to another program it is desirable to control explicitly what is being output.

Since the messages appear to often come from the C/C++ part of FreeCAD the simple work-arounds in Python do not easily suppress the messages and the more involve method described in the forum post is required.

It also appears the
FreeCAD.Console.SetStatus("Console", "Log", False)
method does not impact these messages (regardless of whether Log, Wrn, Err, Msg are used) when running a script directly in Python.

Perhaps it is just a matter of making the SetStatus method affect more types of output. It would seem to make sense for this to be under FreeCAD.Console however I am not clear if the messages coming from FreeCAD are coming from there or not.
Steps To ReproduceCreate a simple python script which does something in FreeCAD such as:

import FreeCAD
import Part

document_name = "combined"
doc = FreeCAD.newDocument(document_name)

shape_obj = doc.addObject("Part::Feature", "myshape")
shape = Part.Shape()
shape_obj.Shape = shape
Part.export([shape_obj], "output.step")

This will result in the following output or similar when run with python:

FreeCAD 0.18, Libs: 0.18R16110 (Git)
Writing STEP file......

******        Statistics on Transfer (Write)                 ******

******        Transfer Mode = 0  I.E.  As Is       ******
******        Transferring Shape, ShapeType = 0                      ******
** WorkSession : Sending all data
 Step File Name : output.step(20 ents)  Write  Done

Switching stdout in Pythonland has now affect, the full redirection that includes the underlying native C/C++ functionality mentioned in the forum post is needed.
Additional InformationNote that the FreeCAD version stamp is possibly a special case.

FreeCAD 0.18, Libs: 0.18R16110 (Git)

It is displayed immediately on import of the FreeCAD Python module. Given the module isn't yet loaded when this is displayed I don't have a good suggestion for how to suppress it by setting a FreeCAD option or calling a FreeCAD method. Perhaps a built in which can be checked by FreeCAD:

import __builtin__
__builtin__.FreeCAD_display_banner = False
import FreeCAD

Obviously with the default being True if not present to preserve the current behaviour. Note this is not proposed as a solution, just one way it could work, those more familiar with the codebase likely have a better idea.

Alternatively if there is some persistent configuration that can be written to which is read on startup this would obviously work as well. Clearly FreeCAD has a lot of these but I'm not sure if they are loaded before or after the message is displayed.
TagsNo tags attached.
FreeCAD Information


related to 0004081 closedwmayer Abillity to show console output when running under Python 



2019-06-13 13:47

administrator   ~0013199

Fix committed to master branch.

Related Changesets

FreeCAD: master 1406c03d

2019-06-13 13:46:49


Details Diff
fixes 0004000: Ability to suppress console output when running under python Affected Issues
mod - src/App/Application.cpp Diff File
mod - src/Main/MainCmd.cpp Diff File
mod - src/Main/MainGui.cpp Diff File
mod - src/Main/MainPy.cpp Diff File

Issue History

Date Modified Username Field Change
2019-06-04 23:15 ardenpm New Issue
2019-06-05 01:33 Kunda1 Description Updated
2019-06-05 01:34 Kunda1 Description Updated
2019-06-13 13:47 wmayer Changeset attached => FreeCAD master 1406c03d
2019-06-13 13:47 wmayer Note Added: 0013199
2019-06-13 13:47 wmayer Assigned To => wmayer
2019-06-13 13:47 wmayer Status new => closed
2019-06-13 13:47 wmayer Resolution open => fixed
2019-06-13 13:47 wmayer Fixed in Version => 0.19
2019-06-13 13:47 wmayer Target Version => 0.19
2020-10-14 21:10 Kunda1 Relationship added related to 0004081