List.ReplaceItemAtIndex (sometimes index input is an Empty List)

Hello all,

I started writing this post when I had an idea and it worked but I am wondering if there is a better way.

I am writing a script to find what sheets legend views are placed. If they are not placed on a Sheet I want to replace the returned Empty List with “Not on Sheet”. In the first image there are Legend not placed on a sheet and some that are. (Each list of sheet numbers is a single Legend and all the sheets it is on). If the Legend is not on a sheet (Index 3) an Empty List is returned and every thing works.

Image 2. All Legens are placed on sheets. Since there are no Empty Lists there are no Indices being fed to List.ReplaceItemAtIndex and returns Empty List its self.

Image 3. My solution is to check if the list of Indices is empty and then pull from the original list or the one with the replaced items. (note I swetched out List.Firstitem with AllTrue.)

Is this the best solution for this or is there a better way. I think I might be over looking something and its going to fail at some point.

If It is the best solution then hope it helps you if you are looking to solve the same problem.


1 Like

I think this is a better solution. I just found it on the forum while looking for something else.
I will try it out later and get back to this post but for now I would say try this instead.