3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

Creating batch of geometries

    • Merel Meulendijks
      Subscriber

      I created this script below in the spaceclaim script environment. The goal is to import a .txt file, create the wanted geometry, save it and repeat this process so that 50 geometries are created and saved. However, when I run it, my previous geometry gets overwritten by the next one (in the same design file). How can I fix this? So the goal is to: create the geometry in new design, save and close the new design and open a new design to create the next geometry:

      # Python Script, API Version = V23

      filename = r"C:\Users\20182785\iCloudDrive\TUe\BMT\Year 3\Q4\BEP\Matlab_probeersels\1000_cosines\trimmed_cos_points_"

      txtnums = map(str, range(1,51))

      for i in txtnums:
          DocumentInsert.Execute(filename+i+".txt", FileSettings1, GetMaps("f5a15159"))
          
         # Set Sketch Plane
          sectionPlane = Plane.PlaneXY
          result = ViewHelper.SetSketchPlane(sectionPlane, Info6)
          # EndBlock

          # Solidify Sketch
          mode = InteractionMode.Solid
          result = ViewHelper.SetViewMode(mode, Info5)
          # EndBlock

          # Revolve 1 Sketch Curve
          selection = Curve2
          result = RevolveEdges.Execute(selection, Line.Create(Point.Create(MM(0), MM(0), MM(0)), 
              Direction.DirY), DEG(360), False, ExtrudeType.None)
          # EndBlock
          
           # Delete Objects
          selection = CurveFolder1
          result = Delete.Execute(selection)
          # EndBlock
          
             # Extrude 1 Edge
          selection = Edge2
          secondarySelection = Edge2
          options = ExtrudeEdgeOptions()
          result = ExtrudeEdges.Execute(selection, secondarySelection, MM(-20), options, Info7)
          # EndBlock
          
           # Extrude 1 Edge
          selection = Edge1
          secondarySelection = Edge1
          options = ExtrudeEdgeOptions()
          result = ExtrudeEdges.Execute(selection, secondarySelection, MM(20), options, Info8)
          # EndBlock
      # Fill
          selection = Edge3
          secondarySelection = Selection.Empty()
          options = FillOptions()
          result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info11)
          # EndBlock

          # Fill
          selection = Edge4
          secondarySelection = Selection.Empty()
          options = FillOptions()
          result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info12)
          # EndBlock

          # Rotate About X Handle
          selection = Body1
          anchorPoint = Move.GetAnchorPoint(selection)
          axis = Line.Create(anchorPoint, Direction.DirX)
          options = MoveOptions()
          result = Move.Rotate(selection, axis, DEG(90.0000000000002), options, Info9)
          # EndBlock

          # Create Named Selection Group
          primarySelection = Face1
          secondarySelection = Selection.Empty()
          result = NamedSelection.Create(primarySelection, secondarySelection)
          # EndBlock

          # Rename Named Selection
          result = NamedSelection.Rename("Group1", "Inlet")
          # EndBlock

          # Create Named Selection Group
          primarySelection = Face2
          secondarySelection = Selection.Empty()
          result = NamedSelection.Create(primarySelection, secondarySelection)
          # EndBlock

          # Rename Named Selection
          result = NamedSelection.Rename("Group1", "Outlet")
          # EndBlock

          # Create Named Selection Group
          primarySelection = FaceRegion1
          secondarySelection = Selection.Empty()
          result = NamedSelection.Create(primarySelection, secondarySelection)
          # EndBlock

          # Rename Named Selection
          result = NamedSelection.Rename("Group1", "Wall")
          # EndBlock

          # Create Named Selection Group
          primarySelection = Body2
          secondarySelection = Selection.Empty()
          result = NamedSelection.Create(primarySelection, secondarySelection)
          # EndBlock

          # Rename Named Selection
          result = NamedSelection.Rename("Group1", "Fluid_domain")
          # EndBlock
          
          filename1 = r"C:\Users\20182785\iCloudDrive\TUe\BMT\Year 3\Q4\BEP\Save_geometries\Automated\scdocs\cartery
          DocumentSave.Execute(filename1+i+".scdoc")

       

    • mjmiddle
      Ansys Employee

       

      There is more than one way to to go about this.

       

      1. You can use DocumentOpen.Execute() instead of DocumentInsert.Execute(), to open in a new document instead of opening into the existing document. Don’t forget to close the current document at the end of the script using Window.ActiveWindow.Close().
      2. You could simply delete all geometry at the beginning of the loop just before the DocumentInsert.Execute() using the ClearAll() command. This way you keep working in the same document.

       

      Also, rather than creating a map, using “txtnums = map(str, range(1,51)),” you can loop on the integer, which is more normal, and just convert to string where that type is necessary:

      DocumentSave.Execute(filename1+str(i)+”.scdoc”)

       

Viewing 1 reply thread
  • You must be logged in to reply to this topic.