Calling for View Templates using Code Blocks or Python

Hello All,

I was wondering is it possible to use a code block to call for all View Templates within the Current Document so that I can use them as inputs for applying view templates to certain views?

Thank you for your help :slight_smile:

I don’t think it’s possible without Python. If you have Crumple package installed, there is a node that already does that.

You can get all Views (which includes templates) using All Elements of Category and then filter for those that are templates.

@Nick_Boyts
I knew you could get all views, but I didn’t know you could utilize the IsTemplate function in a codeblock?

If you’re sticking to code blocks, you cannot. But you can use other indicators to differentiate between views and templates. For example, templates do not have a Family or Type.

However, @Benji-BIM, I would recommend using the best available solution in any case. Why do you specifically need a code block or python solution?

1 Like

Hi Nick - I’ve found that there is a node in the Crumple package that will call for all view templates in the current project. The reason I wanted this in a code block or python format was so that the script wasn’t reliant on custom packages being installed in order for the script to work in its entirety as that would make it easier to roll out across the firm I work for. However I will be taking the route of custom packages and will be getting the IT department to install the custom package across all users profiles.

I actually support avoiding custom packages whenever possible for that same reason. However, your wording made it sound like you were also avoiding all core nodes, which shouldn’t be an issue and is still the better solution. You can easily do this with just a few core nodes.

The reason I “avoided” core nodes was that I am also utilising Data shapes in order to create a User Interface and the drop down data from the view templates node that’s Dynamo Core wont collate all the templates in the current document in a list format which can be fed into the drop down/ list input node in the data shape package. The reason I’m using Data shapes is because we are utilising Pyrevit for deployment of the scripts in a manner that is easier for the users to access and understand as we’ve found through testing and feedback that this is the best approach for the way the firm is working i.e through Virtual Machines where the need to occasionally move the scripts to a folder that Dynamo player can find is something we have to deal with due to how the virtual machines are assigned to a user (not Ideal I know but working around obstacles to get results here)

You would have to use the core nodes to get all views, filter for templates, and then pass that list as the drop down data for Data-Shapes. None of the input nodes accept drop downs. They have to be actual lists.

Hi Nick I understand that none of the inputs accept drop downs hence why I explored other options and also opened up this forum post.

I suppose I could get all views in project, filter parameters to get their view templates, get a list of isolated unique instances and then feed that in. However I have since managed to get crumple to be permanently installed to our firms trusted packages folder so all this has been negated with one node.

Thank you for your responses im sure we have given plenty of options for anyone else seeking out a resolution to a similar problem.

Hi Benji, the packages you mentioned you were using are both open source, you can unpack the python in both of them to python nodes in dynamo which voids thr need for other users to install the packages to use them.

Just make sure you credit the package and the author when doing so :slight_smile:

This will save your IT team from spending time on this.

2 Likes

It’s even simpler than that. All Elements of Category (using Views) will also return all the view templates in your project. So all you have to do is determine which elements are templates and which are view instances. You can do this with a single View.IsViewTemplate node and a FilterByBoolMask.