Proposal: select one or more pieces, hide the others.

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
Posts: 20
Joined: Wed Nov 02, 2016 4:42 pm

Re: Proposal: select one or more pieces, hide the others.

Postby openfablab » Thu Jul 27, 2017 9:19 am

mario52 wrote:
Wed Nov 11, 2015 12:22 pm
see here Macro Toggle Visibility
set of tree macro
Hello, mario52!

I have tried this macros and it works. But... when I call it to make all object visible, it makes visible all prevously hidden parent objects, sketches, etc. It is not convenient :( .

novis.png (91.15 KiB) Viewed 445 times

How can we upgrade this macro to make visible only objects that already were visible before hiding?

I assume there should be some list of "actual" objects. Should it be some variable inside macro or some mark in object properties?

This function is invaluable when one preparing complex dense metal assemblies for lasercut and need to do some laser-friendly post-procesing (fillets, dogbones, etc) after finishing rough design.

I have fixed it in this way. You can add similar change to original macro code (may be with more reasonable and safe variable names) if you find it useful:

change.png (68.29 KiB) Viewed 435 times

But I leave some objects unhidden, of course, to modify them. And there is no need to make this selected objects visible again:

Code: Select all

import FreeCAD
# Macro_ToggleSelectedObjectVisibility
__author__ = "Mario52"
__url__     = ""
__version__ = "00.02"
__date__    = "12/11/2015"
    compt = 0
    for ShapeNameObj in FreeCAD.ActiveDocument.Objects:                                   # list alls objet for test if alls hidden
        if (FreeCADGui.ActiveDocument.getObject(ShapeNameObj.Name).Visibility == False) and (Gui.Selection.isSelected(ShapeNameObj) == False):
            compt += 1                                                                    # if hidden : compt += 1
            #print "False : ",ShapeNameObj.Name
        elif Gui.Selection.isSelected(ShapeNameObj) == False:
            #print "Actual : ",ShapeNameObj.Name
    if compt == len(FreeCAD.ActiveDocument.Objects):                                      # if (compt = Alls objects hidden) then Visibility = True
        for ShapeNameObj in FreeCAD.ActiveDocument.Objects:
            FreeCADGui.ActiveDocument.getObject(ShapeNameObj.Name).Visibility = True      # Visibility = True
            #print "True  : ",ShapeNameObj.Name
        compt = 0
    else :
        for ShapeNameObj in FreeCAD.ActiveDocument.Objects:                               # hidde objects not selecteds
            if Gui.Selection.isSelected(ShapeNameObj) == False:
                FreeCADGui.ActiveDocument.getObject(ShapeNameObj.Name).Visibility = False # if objects is not selected then Visibility = False (Hidden)
                #print "False : ",ShapeNameObj.Name
                FreeCADGui.ActiveDocument.getObject(ShapeNameObj.Name).Visibility = True  # if objects are hidden and selected then Visibility = True and hidden alls objects visibles
                #print "True  : ",ShapeNameObj.Name
except Exception:

Code: Select all

import FreeCAD
__author__ = "Mario52"
__url__     = ""
__version__ = "00.00"
__date__    = "11/11/2015"

    for ShapeNameObj in FreeCAD.actual:   # displyed alls objects
        #print ShapeNameObj
        FreeCADGui.ActiveDocument.getObject(ShapeNameObj).Visibility = True
except Exception:
Posts: 2857
Joined: Wed May 16, 2012 2:13 pm

Re: Proposal: select one or more pieces, hide the others.

Postby mario52 » Tue Aug 15, 2017 11:48 am

hi openfablab

thanks for appreciate my macro i create a new page with your modification for a new feature Macro_Toggle_Visibility2

Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
Renato Rebelo
Posts: 255
Joined: Mon May 19, 2014 1:14 pm
Location: Vouzela - Portugal

Re: Proposal: select one or more pieces, hide the others.

Postby Renato Rebelo » Tue Aug 15, 2017 10:33 pm

Good job
thank you :D
my native language is not English, please excuse me any incorrectness, I apologize for any inconvenience caused, thank you