Clear or Reset Geometry Workspace in Python?
-
Hello,
Is there a way to clear or reset the geometry in a Python script? ie. delete all objects & start over?
If you run the same script multiple times (ie. while developing/debugging) you wind up with multiple geometry objects.
Currently I'm deleting them by hand to start over.
What's the recommended workflow for this?
Thank you!
-
Happy to stand corrected as I have a very crude way to reset geometries.
I search for the geometry entities by names and move them together into an entity group which gets deleted as a whole. This was to avoid the ACIS access error when trying to delete entities one by one by iterating over a list of entities. Please let me know if there are better ways to do this!
def Delete_entities(keyword):
alist = [ent for ent in model.AllEntities() if keyword in ent.Name]
if len(alist) > 0:
EG = model.EntityGroup()
EG.Add(alist)
EG.Delete()
else:
print(f"Couldn't find entities matching the keyword {keyword} to delete.") -
You could also delete all of the model entities by filtering by type. Visible geometry objects have type 'body', so you could do:
import s4l_v1.model as model entities_to_delete = [e for e in model.AllEntities() if e.Type == 'body'] for e in entities_to_delete: e.Delete()
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login