The above code illustrates- while marking row/rows to be bookmarked by the desired bookmark name if the name is not present in the bookmark directory the new bookmark will be created and if the entered bookmark name is already present then it should update it with the new values/rows. The above example code will compile and run successfully without any warning or errors, but it will not give the expected result that is it will not update the bookmarks.
The reason it is not updating is as when the update method is called, then its current state is updated, and its current state should be used in the call SetPublicVisibility()
Below is the example which would help to update the bookmarks correctly via Update API.
def save_bookmark( book_mark, name ):
bookmark_manager = Application.GetService(BookmarkManager)
if book_mark is None:
book_mark = bookmark_manager.AddNew( name, BookmarkComponentFlags.All )
bookmark_manager.SetPublicVisibility( book_mark, True )
else:
updatedBookmark = bookmark_manager.Update(book_mark)
bookmark_manager.SetPublicVisibility( updatedBookmark, True )
The above example stores its current state in a local variable and then the local variable is passed to the SetPublicVisibility method to set its current state. This helps to update the Bookmark in the correct manner.