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
openfablab
Posts: 62
Joined: Wed Nov 02, 2016 4:42 pm
Contact:

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

Post by openfablab »

mario52 wrote: Wed Nov 11, 2015 12:22 pm hi
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
novis.png (91.15 KiB) Viewed 1463 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
change.png (68.29 KiB) Viewed 1453 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
__title__="Macro_ToggleSelectedObjectVisibility"
__author__ = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.02"
__date__    = "12/11/2015"
FreeCAD.actual=[]
try: 
    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:
            FreeCAD.actual.append(ShapeNameObj.Name)
            #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
            else:
                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:
    None 

Code: Select all

import FreeCAD
#Macro_VisibleAlls
__title__="Macro_DisplayAllObjects"
__author__ = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.00"
__date__    = "11/11/2015"

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

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

Post by mario52 »

hi openfablab

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

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
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.

Post by Renato Rebelo »

Good job
thank you :D
my native language is not English, please excuse me any incorrectness, I apologize for any inconvenience caused, thank you
freewheel
Posts: 1
Joined: Tue Sep 22, 2020 2:58 am

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

Post by freewheel »

Freecad 0.18.4 Windows 10 64
Using the latest two part version of the script here:
https://wiki.freecadweb.org/Macro_Toggl ... ility2_1-2

Bug 1:
If I have nested "parts" the 1-2 script sets the selected part to visible, but its parents get set to not visible, and all its daughters get set to not visible. In the case of daughters, it could be hard to define the "correct" behavior. I guess leaving them alone is ok. Making them all invisible certainly isn't right. But parents should certainly be made visible.

Also if you
1) Open the EngineBlock example that comes with FreeCad,
2)go in the Construction group, turn off visibility of all polygons,
3) go to Engineblock, select "Block with headbolts" (not visible)
4) run the 1-2 script, that works, only see "Block with headbolts"
5) run the 2-2 script
then...

Bug 2:
The polygons from the Construction group are also again visible.

Bug 3
Now the "Block with headbolts" is still visible. Not a big deal, could call that one a feature I guess. Pressing space fixes it.

Of course I realize this is just user macro, and I take it as a potentially useful hack.

Ideally it would be great to have this built into FreeCAD. The ability to select something and see just that seems pretty basic, and yet, it's not so simple.
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

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

Post by mario52 »

hi
openfablab wrote:ping
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
openfablab
Posts: 62
Joined: Wed Nov 02, 2016 4:42 pm
Contact:

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

Post by openfablab »

freewheel wrote: Tue Sep 22, 2020 3:24 am Freecad 0.18.4 Windows 10 64
mario52 wrote: Thu Sep 24, 2020 6:27 pm hi
Hello! Sorry, I did not try to code for modern Part/Body system which came from 0.18. Now I also suffer from these bugs on 0.19.
And I am not sure I can fix it now in reasonable time :( .
Post Reply