Skip to content

Instantly share code, notes, and snippets.

@cfobel
Created July 20, 2017 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfobel/a74526d1762a22094e01cb18945103a2 to your computer and use it in GitHub Desktop.
Save cfobel/a74526d1762a22094e01cb18945103a2 to your computer and use it in GitHub Desktop.
FreeCAD macros for showing all parts (not sketches or drafts); isolating view of selected objects
# Isolate selected item(s):
# - Save list of selected items
# - Save list of visible items
# - Hide non-selected items that are currently visible
import FreeCAD
selected_objects = set(object_i.Label for object_i in Gui.Selection.getSelection())
objects_by_label = {object_i.Label: object_i for object_i in Gui.ActiveDocument.Document.Objects if object_i.ViewObject.Visibility}
[setattr(object_i.ViewObject, 'Visibility', False) for label_i, object_i in objects_by_label.iteritems()]
[setattr(object_i.ViewObject, 'Visibility', True) for object_i in Gui.ActiveDocument.Document.Objects if object_i.Label in selected_objects]
FreeCAD._isolated__objects_to_restore = objects_by_label
# Restore original visibility of each item.
# Isolate selected item(s):
# - Save list of selected items
# - Save list of visible items
# - Hide non-selected items that are currently visible
import FreeCAD
objects_by_label = FreeCAD._isolated__objects_to_restore
[setattr(object_i.ViewObject, 'Visibility', True) for object_i in Gui.ActiveDocument.Document.Objects if object_i.Label in objects_by_label]
[setattr(object_i.ViewObject, 'Visibility', False) for object_i in Gui.ActiveDocument.Document.Objects if object_i.Label not in objects_by_label]
# Hide:
# - All sketches
# - All objects that end with `- Draft`
#
# Show:
# - All objects that end with `- Part`
objects_by_label = {object_i.Label: object_i for object_i in Gui.ActiveDocument.Document.Objects}
[setattr(object_i.ViewObject, 'Visibility', True) for label_i, object_i in objects_by_label.iteritems() if label_i.endswith('- Part')]
[setattr(object_i.ViewObject, 'Visibility', False) for label_i, object_i in objects_by_label.iteritems() if (label_i.endswith('- Draft') or 'sketch' in object_i.TypeId.lower())]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment