A brief post as an answer to this post. The Dynamo definition I propose to you does exactly the same action as the code provided by Simon.
Select a target workset by the name, assign Reference planes and Scope boxes to this workset.
Some packages are required from the package manager, Match regular expression and Toggle.
Definition is available for download here.