DeepSOIC wrote: ↑Mon Mar 29, 2021 4:57 pm
My Part-o-magic addon is all about that! Though it's not a separate view.
I used it years ago and can barely remember how it works.... Doesn't it need additional/non-standard FC containers? Does it modify the model so it is no more compatible to standard 0.19 FC?
Is it compatible with current fc versions and is it still developed?
BR
HoWil wrote: ↑Wed Mar 31, 2021 5:59 am
Doesn't it need additional/non-standard FC containers?
It does provide ones, but it doesn't "need" them, it will affect how Parts and Bodies behave and does not cause any incompatibility, except for actively changing display modes of bodies which may make some people think it makes models incompatible with vanilla freecad. But it doesn't really.
HoWil wrote: ↑Wed Mar 31, 2021 5:59 am
Is it compatible with current fc versions and is it still developed?
Mostly compatible, with the exception it may misbehave with Link-related stuff. It is not actively developed, but i'm trying to at least fix big bugs from time to time, because i use it myself.
# Togglevis is a macro created for FreeCAD .19 and is intended to toggle the visibility of selected/non selected objects to make it easer to edit when you have many objects in scene
#
# HOW TO USE: select the objects you want to keep visible (any vertex, edge, face will work) then run the macro.
# All non selected objects will be hidden.
# Run the macro again to restore previsous visibility state.
# - Alternatively, bind it to some keyboard shortcut (im using Ctrl+spacebar)
#
__title__ = "ToggleVis.py"
__author__ = "Paulo Rogerio de Oliveira"
__version__ = "1.0"
__date__ = "2021/03/31" #YYY/MM/DD
__Comment__ = "Hide unselected objects so you can edit then easily. restore prior visibility state running the macro again"
__Help__ = "Select objects you must keep visible and run the macro. Run it again to restore previsous visibility."
__Status__ = "stable"
__Requires__ = "freecad 0.19 (not tested in previous versions)"
import FreeCAD
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
# clear output window
mw=Gui.getMainWindow()
# c=mw.findChild(QtGui.QPlainTextEdit, "Python console")
# c.clear()
# r=mw.findChild(QtGui.QTextEdit, "Report view")
# r.clear()
#initialize cache
if not hasattr(FreeCAD, "previouslyVisibleObjects"):
FreeCAD.previouslyVisibleObjects=[]
if not hasattr(FreeCAD, "previouslyHiddenObjects"):
FreeCAD.previouslyHiddenObjects=[]
# store all parents of all selected objects to ensure its keep visible (store the Label)
# for parentList and selectedList, store the QTreeWidgetItem reference. Try to avoid error if change label while in edit mode
parentList = []
selectedList = []
# try to get internal object associated with QTreeWidgetItem
def getInternalObject(treeItem):
# first looks by Label
obj = App.ActiveDocument.getObjectsByLabel(treeItem.data(0,0))
if len(obj) > 0:
return obj[0]
else:
# if not found, looks by Name
return App.ActiveDocument.getObject(treeItem.data(0,0))
pass
# for each object in treeview
def traverse(list, pad):
# for each child
for idx in range(list.childCount()):
item = list.child(idx)
name = item.data(0, 0)
obj = getInternalObject(item)
isParent = name in parentList
isSelected = name in selectedList
# hide any object that is visible and not parent of selected or selected itself - store it on list to restore state later
if obj.Visibility == True and not isParent and not isSelected:
obj.Visibility = False
FreeCAD.previouslyVisibleObjects.append(item)
# if not selected, not a group or if its parent of selected, traverse childs
if not isSelected:
if not hasattr(obj, "Group") or isParent:
traverse (item, pad + " ")
# if there are objects in visibility cache, you are in edit mode
inEdit = len(FreeCAD.previouslyVisibleObjects) > 0
if inEdit:
FreeCAD.Console.PrintWarning("Leaving edig mode...")
# show all objects that where visible when entered edit mode
for object in FreeCAD.previouslyVisibleObjects:
obj = getInternalObject(object)
try:
obj.Visibility = True
except:
pass
# hide all objects that where hidden when entered edit mode
for object in FreeCAD.previouslyHiddenObjects:
obj = getInternalObject(object)
try:
obj.Visibility = True
except:
pass
# reset visibility cache
FreeCAD.previouslyVisibleObjects = []
FreeCAD.previouslyHiddenObjects = []
#FreeCADGui.SendMsgToActiveView("ViewFit")
else:
tab = mw.findChild(QtGui.QTabWidget, u'combiTab')
tree = tab.widget(0).findChildren(QtGui.QTreeWidget)[0]
top = tree.invisibleRootItem().child(0)
# get selected objects
sels = FreeCADGui.Selection.getSelection()
if not sels:
FreeCAD.Console.PrintWarning("Select something first!\n\n")
else:
FreeCAD.Console.PrintWarning("Entering edit mode!\n\n")
# find the treeitem for ActiveDocument
for idx in range(top.childCount()):
doc = top.child(idx)
if doc.data(0,0) == App.ActiveDocument.Label:
top = doc
# store a list of selected items and its parents to keep it visible
for sel in tree.selectedItems():
current = sel
selectedList.append(current.data(0,0))
while current != None:
obj = getInternalObject(current)
if hasattr(obj, "Visibility") and obj.Visibility == False:
FreeCAD.previouslyHiddenObjects.append(current)
current = current.parent()
if current != None:
parentList.append(current.data(0,0))
traverse(top, "")
Last edited by paulo_cmv on Thu Apr 01, 2021 1:05 pm, edited 1 time in total.
mario52 wrote: ↑Mon Mar 29, 2021 4:24 pm
good macro, when it is finished you must adding in Macro Recipes section 3D View operations with Macro Toggle Visibility (serial)
How can it be made?
How can i ask to add it to Addon Manager / Macros?
paulo_cmv wrote: ↑Wed Mar 31, 2021 2:16 pm
- Correct some bugs
- Added use info
- Alternatively, bind it to some keyboard shortcut (im using Ctrl+spacebar)
Thanks for the macro! However, on my system I get the following error when I try and use it:
Traceback (most recent call last):
File "/Users/XXXXXX/Library/Preferences/FreeCAD/Macro/ToggleVisibility.FCMacro", line 121, in <module>
while current != None:
<class 'NotImplementedError'>: operator not implemented.
Strange because I can do the following in the console:
Traceback (most recent call last):
File "/Users/XXXXXX/Library/Preferences/FreeCAD/Macro/ToggleVisibility.FCMacro", line 121, in <module>
while current != None:
<class 'NotImplementedError'>: operator not implemented.
while current != None:
obj = getInternalObject(current)
if hasattr(obj, "Visibility") and obj.Visibility == False:
FreeCAD.previouslyHiddenObjects.append(current)
current = current.parent()
if current != None:
parentList.append(current.data(0,0))
while current:
obj = getInternalObject(current)
if hasattr(obj, "Visibility") and obj.Visibility == False:
FreeCAD.previouslyHiddenObjects.append(current)
current = current.parent()
if current:
parentList.append(current.data(0,0))
I don't have Python 3.9.x to test with at present but tweak this still works on 3.8.x and is a little more Pythonic IMHO so I'm hoping it gets you up and running.
OS: Windows 7 Version 6.1 (Build 7601: SP 1)
Word size of FreeCAD: 64-bit
Version: 0.20.24673 (Git)
Build type: Release
Branch: master
Hash: e66ed26769ce8affe0a4ed330ff0435f4802f05e
Python version: 3.8.6+
Qt version: 5.15.1
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United Kingdom (en_GB)
HoWil wrote: ↑Wed Mar 31, 2021 5:59 am
Doesn't it need additional/non-standard FC containers?
It does provide ones, but it doesn't "need" them, it will affect how Parts and Bodies behave and does not cause any incompatibility, except for actively changing display modes of bodies which may make some people think it makes models incompatible with vanilla freecad. But it doesn't really.
HoWil wrote: ↑Wed Mar 31, 2021 5:59 am
Is it compatible with current fc versions and is it still developed?
Mostly compatible, with the exception it may misbehave with Link-related stuff. It is not actively developed, but i'm trying to at least fix big bugs from time to time, because i use it myself.
Would be nice to see this functionality in main FC.