Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
General Mechanical

General Mechanical

Topics related to Mechanical Enterprise, Motion, Additive Print and more.

Get Objects/Bodies from Named Selections

    • Antonio Györög Chang
      Subscriber

      Hello Ansys-Community,

      Is there a way to get the objects that a Named Selection is containing? 

      My Problem: 
      I am creating cylindrical coordinate systems (CS) and define the Origin Location by a Named Selection.
      Of course I also want to change the CS for the geometry body. I can't do that with Named Selections (at least I think so?)
      How do I get the Body that is in my Named Selection?

      Best Regards,
      Toni

       

       

       

    • Akshay Maniyar
      Ansys Employee

      Hi Antonio Györög,

      You can select the objects in the named selection using "Select item in group" as shown below.

      I am not sure if understand your query correctly, but you can edit the origin for the coordinate system(if you don't want it at the centroid of geometry you defined using the named selection) by changing the coordinate values as shown in the image.  Can you share some images of the issue you are facing, so that it will be easy to understand and help?

      Thank you,

      Akshay Maniyar

      How to access Ansys help links

      Guidelines for Posting on Ansys Learning Forum

       

    • Antonio Györög Chang
      Subscriber

      Hello Akshar Maniyar,

      sorry for my bad despriction of my problem. I didn't mention that I'm doing this in a script. And trying to get the Items in the Named Selection via script. It looks like follows:

      model = ExtAPI.DataModel.Project.Model
      mesh = model.Mesh
      materials = model.Materials
      analysis = model.Analyses[0]
      solution = analysis.Solution
       
      nsel = DataModel.GetObjectsByType(DataModelObjectCategory.NamedSelection)
      nsel_str = [obj_nsel.Name for obj_nsel in nsel]
       
      base_NSel = ['Example1', 'Example2', 'Example3']
       
      for i in nsel:
          for j in base_NSel:
              if i.Name == j:
                  coordinate_system = Model.CoordinateSystems.AddCoordinateSystem()
                  coordinate_system.OriginDefineBy = CoordinateSystemAlignmentType.Component
                  coordinate_system.OriginLocation = i
                  coordinate_system.CoordinateSystemType = CoordinateSystemTypeEnum.Cylindrical
                  # Here I need some code to assign the Items of the Named Selection (since you can just assign coordinate systems to bodies not Named Selections)
                  #  to the just created cylindrical coordinate system
                  # The thing is I don't know how to get the ID of  the body that is in a Named Selection 
       
              else:
                  pass

      I hope this made it a bit clearer.

      Best regards,
      Toni

    • ErKo
      Ansys Employee

       

       

       

      Hi

      The below code should help to get the body ID (nID)

      model = ExtAPI.DataModel.Project.Model
      analysis=model.Analyses[0]
      ns=model.NamedSelections.Children
      for n in ns:
          print(n.Name)
          nId=n.Location.Ids
          print(nId[0])

       

      To then assign it (nId):

      coordinate_system=ExtAPI.DataModel.Project.Model.CoordinateSystems.AddCoordinateSystem()
      selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
      selection.Ids = nId
      coordinate_system.OriginLocation = selection

       

      You can record when scripting to see the commands.

       

      All the best

      Erik

       

       

    • Antonio Györög Chang
      Subscriber

      Hello Erik, 

      thank you for the response, but this was not quite what I was looking for. So the Coordinate Systems are created that is quite fine. 

      But the next step is to assign the coordinate systems to the bodies, that are in the Named Selections.

      Until now my script and also yours, creates the coordinate systems based on the Named Selections (coordinate_system.OriginLocation = selection) 
      This step was also already in my code

      But when I go to the geometry in the tree, the body (which is in the named selection) is still assigned to the Default Coordinate System

      With this code I only get the IDs from the Named Selection right? 

      model = ExtAPI.DataModel.Project.Model
      analysis=model.Analyses[0]
      ns=model.NamedSelections.Children
      for n in ns:
          print(n.Name)
          nId=n.Location.Ids

      What I actually need to assign the geometrical body to my new created coordinate systems is the body ID or? So basically I want to extract the Body IDs from the Bodies that are in my named selection
      This step is still missing for me 

      I hope I could make my issue clearer.
      Thanks a lot,
      Toni

    • ErKo
      Ansys Employee

       

      Hi. No the nId is the Body Id (geobody id).

      To go from this geobody id (if needed) to a treebody id we can use (this is confusing but for another discussion, for geobody and treeebody):

      body = ExtAPI.DataModel.GeoData.GeoEntityById(nId[0])

      treebody=ExtAPI.DataModel.Project.Model.Geometry.GetBody(body)

      Erik

       

Viewing 5 reply threads
  • The topic ‘Get Objects/Bodies from Named Selections’ is closed to new replies.