Set Parent View

I would like to replicate the functionality described in this post, but in native pyrevit / revit api. Here’s what I have so far:

from pyrevit import forms
from pyrevit import revit

selected_views = forms.select_views(title='Select Views to Reassign Parent View',use_selection=True)
if selected_views:
    parent_view = forms.select_views(title='Select New Parent View',multiple=False)
    if parent_view:
        missed = []
        with revit.Transaction('Set Parent View'):
            for v in selected_views:
                try:
                    v.LookupParameter('Parent View').Set(parent_view.Id)
                except Exception as err:
                    print(err)
                    missed.append(v.Name)
        if missed:
            forms.alert('Could not assign parent to the following views. \n{}'.format(missed))

This was just a quick try. Doesn’t work - should have guessed that!

I’m not sure how that magical SetParameterByName node works and it doesn’t seem to have a parallel in the API. Is this sort of thing not possible at the moment or just far more complicated than I realized? The Autodesk forum post makes it seem soo easy.

Note, I would just use the Dynamo script (and still might) but my coworkers aren’t used to the Dynamo UI - though it’s definitely gotten better in recent releases!

Oh! I got it. It wasn’t working because I was selecting views that were not of “Detail” type. Reading a little further down the forum post that I linked above I came across this bit of advice:

That works in all views when the Callouts are Detail Views/Wall Section/Building - When you invoke the Callout command >>> select appropriate type/one of the above from the type selector…

In case of Plane views, if you do not select “Detail View”, the Callout will be a “Floor Plan” associated with the original view (hence the Read Only Parameter).