In Mechanical script, how to code a non global CS in a worksheet named selection?

I have been coding various names selections in Ansys mechanical. I have been able to create a new named selection, specify it as a worksheet based method, add a line item (criterion) to the worksheet and populate all fields except for the “coordinate system” field. Can anyone provide an example of a Worksheet named selection where one of the criterion (lines items) of the worksheet utilizes a non global coordinate system? Thank you.
Comments
-
For reference, I have additionally provided some of the code I have been using. I need help on the last line. "nscriterion_Py_JREF_W_J1_LALL[1].CoordinateSystem =" appears to be looking to be assigned a CS object. Which I have done in various attempts but it never seems to accept it. Any help is appreciated. Thank you.
Code is below. I did not know how to make a "code block." I apologize if the post does not render properly.
nsobj_Py_JREF_W_J1_LALL = Model.AddNamedSelection()
nsobj_Py_JREF_W_J1_LALL.Name ='Py_JREF_W_J1_LALL'
nsobj_Py_JREF_W_J1_LALL.ScopingMethod = GeometryDefineByType.Worksheet # Change Named selection to scoping mode "Worksheet"
Tree.Refresh()nscriterion_Py_JREF_W_J1_LALL = nsobj_Py_JREF_W_J1_LALL.GenerationCriteria
nscriterion_Py_JREF_W_J1_LALL.Add(None)
Tree.Refresh()
nscriterion_Py_JREF_W_J1_LALL[0].EntityType=SelectionType.GeoEdge #Access the first cteria in the crtierion "nsctirerion[0]nscriterion_Py_JREF_W_J1_LALL"
nscriterion_Py_JREF_W_J1_LALL[0].Criterion = SelectionCriterionType .NamedSelection
nscriterion_Py_JREF_W_J1_LALL[0].Operator=SelectionOperatorType.Equal
nscriterion_Py_JREF_W_J1_LALL[0].Value= nsobj_Py_JREF_W_JALL_LALLnscriterion_Py_JREF_W_J1_LALL[1].Action=SelectionActionType.Filter
nscriterion_Py_JREF_W_J1_LALL[1].EntityType=SelectionType.GeoEdge #Access the first cteria in the crtierion "nsctirerion_nscriterion_Py_JREF_W_J1_LALL"
nscriterion_Py_JREF_W_J1_LALL[1].Criterion=SelectionCriterionType.LocationY
nscriterion_Py_JREF_W_J1_LALL[1].Operator=SelectionOperatorType.RangeInclude
nscriterion_Py_JREF_W_J1_LALL[1].LowerBound= Quantity(-4, 'in')
nscriterion_Py_JREF_W_J1_LALL[1].UpperBound= Quantity(4, 'in')
nscriterion_Py_JREF_W_J1_LALL[1].CoordinateSystem = ExtAPI.DataModel.Tree.Find(name="Joint_W_Type1_Group") # Here is where I need help0 -
Update: I am new to the forum, updated previous comment to now include Code block
For reference, I have additionally provided some of the code I have been using. I need help on the last line. "nscriterion_Py_JREF_W_J1_LALL[1].CoordinateSystem =" appears to be looking to be assigned a CS object, which I have done in various attempts, but it never seems to accept it. Any help is appreciated. Thank you.
Code is below.
nsobj_Py_JREF_W_J1_LALL = Model.AddNamedSelection() nsobj_Py_JREF_W_J1_LALL.Name ='Py_JREF_W_J1_LALL' nsobj_Py_JREF_W_J1_LALL.ScopingMethod = GeometryDefineByType.Worksheet # Change Named selection to scoping mode Worksheet Tree.Refresh() nscriterion_Py_JREF_W_J1_LALL = nsobj_Py_JREF_W_J1_LALL.GenerationCriteria nscriterion_Py_JREF_W_J1_LALL.Add(None) Tree.Refresh() nscriterion_Py_JREF_W_J1_LALL[0].EntityType=SelectionType.GeoEdge #Access the first cteria in the crtierion nsctirerion[0]nscriterion_Py_JREF_W_J1_LALL nscriterion_Py_JREF_W_J1_LALL[0].Criterion = SelectionCriterionType .NamedSelection nscriterion_Py_JREF_W_J1_LALL[0].Operator=SelectionOperatorType.Equal nscriterion_Py_JREF_W_J1_LALL[0].Value= nsobj_Py_JREF_W_JALL_LALL nscriterion_Py_JREF_W_J1_LALL[1].Action=SelectionActionType.Filter nscriterion_Py_JREF_W_J1_LALL[1].EntityType=SelectionType.GeoEdge #Access the first cteria in the crtierion nsctirerion_nscriterion_Py_JREF_W_J1_LALL nscriterion_Py_JREF_W_J1_LALL[1].Criterion=SelectionCriterionType.LocationY nscriterion_Py_JREF_W_J1_LALL[1].Operator=SelectionOperatorType.RangeInclude nscriterion_Py_JREF_W_J1_LALL[1].LowerBound= Quantity(-4, 'in') nscriterion_Py_JREF_W_J1_LALL[1].UpperBound= Quantity(4, 'in') nscriterion_Py_JREF_W_J1_LALL[1].CoordinateSystem = ExtAPI.DataModel.Tree.Find(name="Joint_W_Type1_Group") # Here is where I need help
Flag
Quote
Like0 -
This is likely because the line:
ExtAPI.DataModel.Tree.Find(name="Joint_W_Type1_Group") # Here is where I need helpis returning a list of objects. There can be multiple objects with the same name, and finding by name will return a list of all of them (even if there is only 1). So you probably need to do:
ExtAPI.DataModel.Tree.Find(name="Joint_W_Type1_Group") [0]This will get the first one.
You can also find objects by object Id, but in general searching by name you should make sure you are getting the object instead of a list of one object.
0 -
Thank you so much for the thorough response. This was in fact the issue. My code was returning a a list of CS objects, where this list was only 1 Csys object. The below code you mentioned fixed this issue. Thank you. I appreciate your efforts.
ExtAPI.DataModel.Tree.Find(name="Joint_W_Type1_Group") [0]
0