-
-
December 23, 2021 at 2:25 pm
hatchet666
SubscriberI´m trying to write a python script for set up Named Selection
My first try is the following short script:
sel=DataModel.Project.Model.AddNamedSelection()
sel.ScopingMethod=GeometryDefineByType.Worksheet
sel.Name="Groove Edges"
CRC=sel.GenerationCriteria
CRC.Add(None)
CRC[0]=Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion()
CRC[0].Action=SelectionActionType.Add
CRC[0].EntityType=SelectionType.GeoEdge
CRC[0].Criterion=SelectionCriterionType.NamedSelection
CRC[0].Operator=SelectionOperatorType.Equal
CRC[0].Value=ExtAPI.DataModel.Project.Model.NamedSelections.Children[3]
sel.Generate()
It generate a new Named Selection from the NS list.
But I want to set the value to a name like "NS_Edge_groove_01".
Can someone help?
January 6, 2022 at 1:28 pmAniket Chavan
Forum Moderatorso instead of using:
CRC[0].Value=ExtAPI.DataModel.Project.Model.NamedSelections.Children[3]
you want to use Named selection name "NS_Edge_groove_01"
then you can loop through all the Model.NamedSelections.Children using a for loop and check the name of each named selection and once you find required namedselection, just use that in the value.
or
you can use the helpers available in the console:
DataModel.GetObjectsByName("NS_Edge_groove_01")[0] #so basically same for loop logic above, just using a single API method
and then
CRC[0].Value=DataModel.GetObjectsByName("NS_Edge_groove_01")[0]
hope that helps!
-Aniket
How to access Ansys help links
Guidelines for Posting on Ansys Learning Forum
January 11, 2022 at 5:30 amhatchet666
SubscriberHi
thanks for the hint. It works!
sel=DataModel.Project.Model.AddNamedSelection sel.ScopingMethod=GeometryDefineByType.Worksheet
sel.Name="Test"
CRC=sel.GenerationCriteria
CRC.Add(None)
CRC[0]=Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion CRC[0].Action=SelectionActionType.Add
CRC[0].EntityType=SelectionType.GeoEdge
CRC[0].Criterion=SelectionCriterionType.NamedSelection
CRC[0].Operator=SelectionOperatorType.Equal
CRC[0].Value=ExtAPI.DataModel.GetObjectsByName("NS_Edge_Nut-1")[0]
CRC.Add(None)
CRC[1]=Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion CRC[1].Action=SelectionActionType.Add
CRC[1].EntityType=SelectionType.GeoEdge
CRC[1].Criterion=SelectionCriterionType.NamedSelection
CRC[1].Operator=SelectionOperatorType.Equal
CRC[1].Value=ExtAPI.DataModel.GetObjectsByName("NS_Edge_Nut-2")[0]
CRC.Add(None)
CRC[2]=Ansys.ACT.Automation.Mechanical.NamedSelectionCriterion CRC[2].Action=SelectionActionType.Add
CRC[2].EntityType=SelectionType.GeoEdge
CRC[2].Criterion=SelectionCriterionType.NamedSelection
CRC[2].Operator=SelectionOperatorType.Equal
CRC[2].Value=ExtAPI.DataModel.GetObjectsByName("NS_Edge_Nut-",i)[0]
sel.Generate
One more question. How can I access to the named selection list? I want to filter only some ns with a similar name:
typical example in python:
mylist = ['face-1','face-2','face-3','face-4','edge-2','edge-1']
search = [s for s in mylist if "edge" in s]
print (search)
January 11, 2022 at 6:59 amErKo
Ansys EmployeeHi
There are many ways of doing something like this, and below is just one way (the filtered named selection names are in the list edgename):
nslist=ExtAPI.DataModel.Project.Model.NamedSelections.Children
filterstr="edge"
edgename=[]
for ns in nslist:
sch=ns.Name.Split('-')
if sch[0]==filterstr:
edgename.append(ch.Name)
or
nslist=ExtAPI.DataModel.Project.Model.NamedSelections.Children
filterstr="edge"
edgename=[]
for ns in nslist:
if filterstr in ns.Name:
edgename.append(ns.Name)
All the best
Erik
Viewing 3 reply threads- The topic ‘Set up a Named Selection referencing to other’ is closed to new replies.
Innovation SpaceTrending discussionsTop Contributors-
6279
-
1906
-
1457
-
1308
-
1022
Top Rated Tags© 2026 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.
-
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.