We’re putting the final touches on our new badges platform. Badge issuance remains temporarily paused, but all completions are being recorded and will be fulfilled once the platform is live. Thank you for your patience.
3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

Creating 1000 geometries

    • Merel Meulendijks
      Subscriber

      Hi guys! I really need your help.

      I created 1000 .txt files with each .txt file containing the coordinates of a trimmed cosine curve. This is the format:

      1 2.41 -7.07
      1 2.41 -7.0558
      1 2.41 -7.0417
      1 2.41 -7.0275
      1 2.4099 -7.0134
      1 2.4099 -6.9992  etc. 


      In this example below, I load in one of these files in the SpaceClaim script editor: 

      # Insert From File
      DocumentInsert.Execute(r"C:\Users\20182785\iCloudDrive\TUe\BMT\Year 3\Q4\BEP\Matlab_probeersels\1000_cosines\trimmed_cos_points_7.txt", FileSettings1, GetMaps("f5a15159"))
      # EndBlock
       
      # Set Sketch Plane
      sectionPlane = Plane.PlaneXY
      result = ViewHelper.SetSketchPlane(sectionPlane, Info1)
      # EndBlock
       
      # Solidify Sketch
      mode = InteractionMode.Solid
      result = ViewHelper.SetViewMode(mode, Info2)
      # 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, Info4)
      # EndBlock
       
      # Extrude 1 Edge
      selection = Edge1
      secondarySelection = Edge1
      options = ExtrudeEdgeOptions()
      result = ExtrudeEdges.Execute(selection, secondarySelection, MM(20), options, Info5)
      # 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, Info3)
      # EndBlock
       
      filename = r"C:\Users\20182785\iCloudDrive\TUe\BMT\Year 3\Q4\BEP\Save_geometries\Automated\scdocs\Artery7.scdoc"
       
      # Save File
      DocumentSave.Execute(filename)
      # EndBlock

       

      If I run this script, the following geometry is created:

      The problem is that I want to create a loop (in the script editor) in which I can loop over the 1000 txt files containing the trimmed cosine curve coordinates (instead of only loading in one file) in order to create and save the 1000 geometries. How can I do this? A large problem is that once one geometry is created, the second one will be created in the same "design" file resulting in geometries that overwrite each other (and errors). For that, a new 'design' file needs te be opened in each run of the loop. How can this be done? Thank you in advance. 

    • Aniket
      Forum Moderator

      If you check DocumentInsert.Execute command in the interpreter:

      It can also be used as follows:

      DocumentInsert.Execute(r"D:\Desktop\Desktop\test1.txt")

      DocumentInsert.Execute(r"D:\Desktop\Desktop\test1.txt")

      Now you can use other modules to get all files in a directory and import them in a for loop if you want the geometries in a single file. If you want them in different files, then you can simply use save as before importing new text file each time:

      # Save File
      options = ExportOptions.Create()
      DocumentSave.Execute(r"D:\Desktop\Desktop\test3.scdoc", options)
      # EndBlock

      -Aniket

      How to access Ansys help links

      Guidelines for Posting on Ansys Learning Forum

Viewing 1 reply thread
  • The topic ‘Creating 1000 geometries’ is closed to new replies.