How to test if object's display mode includes "Shaded"

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

How to test if object's display mode includes "Shaded"

Post by DorinDXN »

Hi all, hope you're well :)

To avoid this error
.. 'Shaded' is not part of the enumeration

How to test if object's display mode includes (i.e. can accept) "Shaded"?

This is not working

Code: Select all

if App.ActiveDocument.getObject"Test").ViewObject.DisplayMode.includes("Shaded"):
..
cheers,
Dorin
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: How to test if object's display mode includes "Shaded"

Post by Chris_G »

You can get the list of available display modes with :

Code: Select all

obj.ViewObject.getEnumerationsOfProperty("DisplayMode")
So the test statement will be :

Code: Select all

if "Shaded" in obj.ViewObject.getEnumerationsOfProperty("DisplayMode"):
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: How to test if object's display mode includes "Shaded"

Post by DorinDXN »

Thnks for reply,

it doens't work as expected,
in FreeCAD 0.18 raises

Code: Select all

'Gui.ViewProviderDocumentObject' object has no attribute 'getEnumerationsOfProperty'
in FreeCAD 0.21 there is no error but returns False even if the objects accepts "Shaded"

but I solved due to the fact that all objects I want to set as "Shaded" and I cannot,
had either "Base" or "Group" so, for now, I'm using this workaround

Code: Select all

if not(("Base" == App.ActiveDocument.getObject(s[p].Name).ViewObject.DisplayMode) or ("Group" == App.ActiveDocument.getObject(s[p].Name).ViewObject.DisplayMode)):
	..
which works in FC 0.18 and not in FC 0.21
but I'll use FC 0.18 anyways

cheers,
Dorin
Post Reply