Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. Clear or Reset Geometry Workspace in Python?

Clear or Reset Geometry Workspace in Python?

Scheduled Pinned Locked Moved Python API
pythongeometry
4 Posts 4 Posters 646 Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dbsim4
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NaraSakamoto
      wrote on last edited by NaraSakamoto
      #2

      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.")

      1 Reply Last reply
      0
      • B Offline
        B Offline
        brown
        ZMT
        wrote on last edited by
        #3

        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()
        
        1 Reply Last reply
        1
        • brynB Offline
          brynB Offline
          bryn
          ZMT
          wrote on last edited by bryn
          #4

          I typically do the following (which also clears the history and frees memory):

          import XCoreModeling as xcm
          xcm.GetActiveModel().Clear()
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Search