3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

SCDM Scripting Parametric Selection of Thread Flats on a Nut and Bolt

    • Jake
      Subscriber

      Hello, 

       

      I have a parametric inventor model that is loaded into Spaceclaim and Modified to be 2D geometry as shown below. 

      Using SCDM scripting in python, how can I find the flats (edges) on the nut geometry that contact the bolt flats (edges) and create named selections for each pair. For example:  

      Named selections for the first thread shown above. 

      Named selections for the second set of threads shown above, Etc.

      I can calculate the length of the flats from the pitch on the bolt and nut threads, in this case they’re 0.111" in length.

       

    • Aniket
      Forum Moderator

      you can use PowerSelection APIs to filter all edges with the same length (note this is what it records in the script editor when I select one edge in the tree, and then from the "selection" tab choose "select edges with same length", and insert selection in the script editor):

      PowerSelection.Edges.ByLength(EdgeSelection.Create(GetRootPart().Bodies[0].Edges[2]), 
          PowerSelectOptions(True), #true if you want to search across all bodies, false if you want to search only in the bodies[0]
          SearchCriteria.SizeComparison.Equal)

      now you can get 2 selections for same length, you can pythonically loop in one group of edges, to find if there is another edge coincident with it:

      for example:

      GetRootPart().Bodies[0].Edges[3].Shape.Geometry.IsCoincident(GetRootPart().Bodies[1].Edges[0].Shape.Geometry)

      -Aniket

      How to access Ansys help links

      Guidelines for Posting on Ansys Learning Forum

    • Jake
      Subscriber

      Hi Aniket, 

       

      When I attempt to use the .IsCoincident logic on two of the contacting thread edges python returns False. See screenshot below.

       

    • Aniket
      Forum Moderator

      Are they not coincident? are there gaps in them?

      -Aniket

      How to access Ansys help links

      Guidelines for Posting on Ansys Learning Forum

    • Jake
      Subscriber

      No they are not coincident. 

      • Aniket
        Forum Moderator

        IsCoincident will only work if the edges are coincident. If they are not, you may have to try and check the bounding box of these edges and then decide this.

        You can get a bounding box by:

        e1=GetRootPart().Bodies[0].Edges[0]

        b1=e1.Shape.GetBoundingBox(Matrix.Identity)

        b1.Center

        b1.corner

        -Aniket

        How to access Ansys help links

        Guidelines for Posting on Ansys Learning Forum

         

Viewing 4 reply threads
  • The topic ‘SCDM Scripting Parametric Selection of Thread Flats on a Nut and Bolt’ is closed to new replies.