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!
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 » Tue Nov 10, 2020 10:52 am

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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest