Ticket #6069 - Shape color is not displayed correctly after change in tree

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
JohnThinger
Posts: 1
Joined: Tue Nov 10, 2020 9:58 am

Re: Shape color is not displayed correctly after change in tree

Post by JohnThinger »

This topic has been discussed in some other threads. If a sub-element of a combined part (union, cut, common or similar) is changed, the part color is going back to standard-grey and transparency to non-transparent. The original color and transparency values are still stored in the object data, but they are not visually applied.

It seems to be complex to fully resolve this, e.g. if different colors or materials are used on single faces. Nevertheless, the following approach works for single-color parts.

As written in the posts above, changing the color manually (to another color and then back to the desired color) resolves the problem. However, doing this manually after each change is annoying.

Hence, the following macro automates the process. Just select all (top-level) objects that have been modified and then run the macro. It will first invert the color and transparency values and then set the original values again.

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD

selection = FreeCADGui.Selection.getSelection()
for item in selection:
	tempColor = item.ViewObject.ShapeColor
	transparency = item.ViewObject.Transparency
	# Invert the color of all selected shapes.
	item.ViewObject.ShapeColor = (1 - tempColor[0], 1 - tempColor[1], 1 - tempColor[2])
	item.ViewObject.Transparency = 100 - item.ViewObject.Transparency
	# Reset the original color.
	item.ViewObject.ShapeColor = tempColor 
	item.ViewObject.Transparency = transparency
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ticket #6069 - Shape color is not displayed correctly after change in tree

Post by Kunda1 »

Ticket migrated to issue #6069. Needs reviewing
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ticket #6069 - Shape color is not displayed correctly after change in tree

Post by Kunda1 »

Bumping for activity (issue #6069)
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply