How do I add to a `List[NamedSelection]` object?

tlewis3348
tlewis3348 Member Posts: 24
10 Comments Name Dropper Photogenic
**

When the Analysis Settings object of a Static Structural analysis is selected and the "Output Selection" property is set to "By Named Selection", Tree.FirstActiveObject.NamedSelection returns a List[NamedSelection] object. I would like to understand how to add named selections to this list. When I execute, dir(Tree.FirstActiveObject.NamedSelection), this is returned:

['Add', 'AddRange', 'AsReadOnly', 'BinarySearch', 'Capacity', 'Clear', 'Contains', 'ConvertAll', 'CopyTo', 'Count', 'Enumerator', 'Equals', 'Exists', 'Find', 'FindAll', 'FindIndex', 'FindLast', 'FindLastIndex', 'ForEach', 'GetEnumerator', 'GetHashCode', 'GetRange', 'GetType', 'IndexOf', 'Insert', 'InsertRange', 'IsReadOnly', 'IsSynchronized', 'Item', 'LastIndexOf', 'MemberwiseClone', 'ReferenceEquals', 'Remove', 'RemoveAll', 'RemoveAt', 'RemoveRange', 'Reverse', 'Sort', 'SyncRoot', 'ToArray', 'ToString', 'TrimExcess', 'TrueForAll', '__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__']

I was thinking that either Add() or Insert() would do what I am needing. For example, help(Tree.FirstActiveObject.NamedSelection.Add) returns this:

Help on built-in function Add

 |  Add(...)
 |          Add(self: List[NamedSelection], item: NamedSelection)

Therefore, I expected Tree.FirstActiveObject.NamedSelection.Add(ns) (where ns is the named selection object) to add the named selection object to the list of named selections for the "Output Selection". However, executing this seems to have no effect.

Does anyone know how I would go about adding to the list?

Best Answer

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee, GitHub-issue-creator Posts: 327
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    Answer ✓

    Here is one way:
    analysis_settings.NamedSelection = list(analysis_settings.NamedSelection) + [ns2]