General Mechanical

General Mechanical

Topics relate to Mechanical Enterprise, Motion, Additive Print and more

Associating a part geometry to a named selection via Scripting

    • thermalsr71
      Subscriber

      Hello,

      First time in this forum. I want to do a script that associates a part geometry from the Geometry tree to a named selection. It looks auite simple at first sight.

      Here's my script.

      model = ExtAPI.DataModel.Project.Model    
      geom = model.Geometry
      selection_manager = ExtAPI.SelectionManager

      for part in geom.Children:
          bodyName = body.Name

          selection_manager.ClearSelection()
          selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
          
          selection.Ids = [part.ObjectId]                                          ! at this point, I associate my part ID to the selection
          selection_manager.NewSelection(selection)


          new_namedSelection = model.AddNamedSelection()
          new_namedSelection.Name = 'b_'+body.Name   

          new_namedSelection.Location.Ids= selection.Ids           ! HERE IS THE PROBLEM         

      The problem here is that if I do a print(selection.ids), I'll get the Id associated to the part I want the named selection to be associated to. So far so good. But if I do a print(new_namedSelection.Name.Location.Ids), I'll get an empty list, when it should be a one-item list with the Id I'm interested in.

      I don't understand why the last line does not work properly.

       

      Thank for your time

    • Erik Kostson
      Ansys Employee

      Hi

       

      This post is relevant.

      https://forum.ansys.com/forums/topic/act-script-assign-items-to-a-named-selection/

       

       

       

       

      All the best

       

      Erik

    • thermalsr71
      Subscriber

      Hi Erik,

       

      The GetGeoBody() was what I was missing. It worked. 

       

      Thanks

    • Erik Kostson
      Ansys Employee

      Yes we need the body id to define the NS. Great that it worked. Erik

    • thermalsr71
      Subscriber

      However, is there a method  similar to NamedSelection.Location.Ids that gets the ids of the nodes associated to the name selection geometry, instead of the ids of the geometric entities?

       

      Thanks in advance 

Viewing 4 reply threads
  • You must be logged in to reply to this topic.