Hidding a Slice

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
iari
Posts: 42
Joined: Mon Nov 18, 2013 8:52 pm

Hidding a Slice

Post by iari »

Hi!
I would like to hide a "Slice" object created after a "ExplodeCompound" command:

Code: Select all

# ...
Slice_group = CompoundTools.Explode.explodeCompound(f) # Creation of "Exploded Slice"
Now, if I do this operation manually, the python code is:

Code: Select all

Gui.ActiveDocument.getObject("Slice_child0").Visibility=False
But I want to do it in a function; thus I need to call the object without knowledge of the label. Unfortunately, the following attempt fails:

Code: Select all

Gui.ActiveDocument.getObject(Slice_group[1][0].Label).Visibility=False
as "Slice_group[1][0].Label" is of 'NoneType'.

Attached, my model tree.
How can I access the Visibility property of the Slices?

Thank you!
Igmar
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16110 (Git)
Build type: Release
Branch: (HEAD detached at upstream/releases/FreeCAD-0-18)
Hash: f7dccfaa909e5b9da26bf50c4a22ccca9bb10c40
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Italian/Italy (it_IT)
Attachments
Slice to hide.png
Slice to hide.png (7.07 KiB) Viewed 590 times
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Hidding a Slice

Post by Chris_G »

Code: Select all

Slice_group = CompoundTools.Explode.explodeCompound(f) # Creation of "Exploded Slice"
Here, Slice_group is a tuple : (group_object, list_slice_objects)

Be careful, group_object can be None, if there is only 1 slice part.
So you'd better use the slice objects from list_slice_objects.

These are App objects, but you want to use a Gui functionality.
So you need to use their ViewObject :

Code: Select all

Slice_group = CompoundTools.Explode.explodeCompound(f) # Creation of "Exploded Slice"
for slice in Slice_group[1]:
	slice.ViewObject.hide()

iari
Posts: 42
Joined: Mon Nov 18, 2013 8:52 pm

Re: Hidding a Slice

Post by iari »

I want to hide the objects in the list_slice_objects, but Label didn't work. I found that with:

Code: Select all

Gui.ActiveDocument.getObject(Slice_group[1][0].Name).Visibility=False
it works!

Thanks
Igmar
Post Reply