I want to delete hidden objects via the objecttable using Rhino, python, rhinoscript, and combinations of those.
def RunCommand():
#all non-light objects that are selected
object_enumerator_settings = ObjectEnumeratorSettings()
object_enumerator_settings.NormalObjects = False
object_enumerator_settings.LockedObjects = True
object_enumerator_settings.HiddenObjects = True
selected_objects = doc.Objects.GetObjectList(object_enumerator_settings)
#Loop through hidden (?) objects?
for select_object in selected_objects:
#Delete them
select_object.Attributes.Visible = True
doc.Objects.Delete(select_object)
select_object.CommitChanges()
doc.Views.Redraw()
return Result.Success
if __name__ == '__main__':
RunCommand()
This Deletes the objects that i can see in Rhino however if i run the command show the hidden object is still there, can i reverse this? Or am i doing it completely wrong?
import scriptcontext as sc
import Rhino.DocObjects as do
import Rhino.Commands as rc
def RunCommand():
# any object, visible or hidden
object_enumerator_settings = do.ObjectEnumeratorSettings()
object_enumerator_settings.ObjectTypeFilter = do.ObjectType.AnyObject
object_enumerator_settings.HiddenObjects = True
# this gets any object, visible and hidden
all_obs = sc.doc.Objects.GetObjectList(object_enumerator_settings)
# pick only those that are hidden
hidden_objects = [o for o in all_obs if o.Visible==False]
for hidden_object in hidden_objects:
# first set the hidden object to visible
hidden_object.Attributes.Visible = True
hidden_object.CommitChanges()
sc.doc.Views.Redraw()
#then delete
print "deleting", hidden_object
sc.doc.Objects.Delete(hidden_object.Id, False)
#done
sc.doc.Views.Redraw()
return rc.Result.Success
if __name__ == '__main__':
RunCommand()
There is version of Delete that takes a toggle to “Ignore Modes” which will also delete Hidden and/or Locked Objects. Sorry for reviving an old thread, but I figured this might help people finding this thread in the future.
import scriptcontext as sc
import Rhino.DocObjects as do
import Rhino.Commands as rc
def RunCommand():
# any object, visible or hidden
object_enumerator_settings = do.ObjectEnumeratorSettings()
object_enumerator_settings.ObjectTypeFilter = do.ObjectType.AnyObject
object_enumerator_settings.HiddenObjects = True
# this gets any object, visible and hidden
all_obs = sc.doc.Objects.GetObjectList(object_enumerator_settings)
# pick only those that are hidden
hidden_objects = [o for o in all_obs if o.Visible==False]
for hidden_object in hidden_objects:
#then delete
print "deleting", hidden_object
sc.doc.Objects.Delete(hidden_object.Id, False, True)
#done
sc.doc.Views.Redraw()
return rc.Result.Success
if __name__ == '__main__':
RunCommand()