Good morning,
I would like to assign a template to a 3D view with dynamo but I can’t do it.
is this something possible?
Currently I am duplicating a view but I am missing the state of the template. I tried with python but I can’t do it. I’m stuck with the views
Can you share what you have tried so far?
currently in code I have this. but I get the name of the views and their IDs. but I don’t know what to do to find the templates that would be assigned to a view. and then assigns it to another view.
sorry for the explanations in French
Charger les bibliothèques DesignScript et Standard Python
import clr
clr.AddReference(“RevitServices”)
clr.AddReference(“RevitAPI”)
from RevitServices.Persistence import DocumentManager
from Autodesk.Revit.DB import FilteredElementCollector, View
Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
doc = DocumentManager.Instance.CurrentDBDocument
Filtrer les éléments pour obtenir les vues qui sont des gabarits de vue
view_templates = FilteredElementCollector(doc)
.OfClass(View)
.WhereElementIsNotElementType()
.ToElements()
Liste pour stocker les noms et IDs des gabarits de vue
template_names_ids =
Boucle sur chaque vue pour vérifier si elle est un gabarit de vue
for view in view_templates:
if view.IsTemplate:
template_names_ids.append((view.Name, view.Id.IntegerValue))
Affectez la sortie à la variable OUT.
OUT = template_names_ids
Not sure why you are going with Python rather than just Dynamo, but in Dynamo it looks something like this:
- Collect the views that you want to get the templates from (example just gets current view)
- Extract the view template parameter (Element.GetParameterValueByName)
- Use Element.SetParameterByName to set the view template
Not sure how you are duplicating the view, but the View.DuplicateView node seems to keep the assigned View Template parameter in the new one.
You code appears to just be getting the list of all view templates in the project, not a specific one for whatever view you care about. (In Revit, a View Template IS a view, just a special one.)
Make sure you’re posting code as preformatted text so it doesn’t lose its formatting.
You actually have to use python when dealing with 3D View Templates. There’s a known issue with the how the Dynamo wrapper handles them. The process is still the same though: get the value of the View Template parameter and then set the parameter of the target view using that value.
I did not know that! Thanks.
yes then it works well for plan views but for 3D views this way of doing things does not work.
Currently I am duplicating a 3D view and renaming it to my liking. But not to assign a template to it.
Otherwise my other solution is to succeed in emptying the “definition zone” parameter in the parameters of a 3D view to put it in ".
so it would work by id number for attribution maybe ?
Parameters that store element values store the Element Id of the assigned object. In Dynamo, those values are passed and returned as the actual Element object instead of the Id. (The Id assignment still happens in the background through the typical API methods.)
This means that to assign the template through nodes, Dynamo would have to convert that Element Id to the actual Element object, which is where the wrapper fails. If you were to assign the template in Python, through the actual API, it would be as the Element Id anyway.
So long answer short, you need to keep the whole operation (that deals with 3D View Templates) in python and the Revit API.
I was just playing around with this and the View.Duplicate Node assigned the correct view template when duplicating a 3d view when I tried it (Duplicating a 3d view with a template assigned already). (in Revit 2023, just what my current project is in) Do you have more information about the issue? (Link to a post or bug report?)
So the view kept the original template or you assigned a new one? The only issue with 3D View Templates is their Dynamo wrapper. Any functionality that doesn’t return the 3D View Template object in Dynamo still works.
wow I’ll look but I know very little python. I know the basics I will look at it when I have time.
Thanks
Kept the original template… As we haven’t seen @pierre.martinA96CS’s entire graph, we don’t know if that is what he intends, but I assume from this in his first post:
…that is exactly what he wants to do… So my hope was that pointing that out would solve the original problem and avoid any complications with Python and just use all OOTB nodes.
@pierre.martinA96CS can you clarify? Are you wanting to assign a new template to a view or just ensure that the original template is retained when duplicating a view? The former will require python for 3D View Templates. The latter will not.
Sorry if what I got isn’t clear.
what I want to do is duplicate a view that does not have an attribute template. I want to assign this new view to a template that already exists in the project but I can’t do this.
otherwise I have another solution which is to duplicate a 3D view which already has the template I want. But I have a problem that follows. it is that there is a definition zone which is allocated. and I don’t have any. But I can’t delete the definition zone in the view that is being created.
is it clearer?
Getting and setting parameters through the API is pretty straightforward. I would start there. You can find plenty of general examples here on the forum, but Revit API Docs has all the API methods documented if you get stuck.
What does the error say when getting that parameter? Also, what is that parameter in English? Out of curiosity.
for the definition area, the problem is that the views have an assigned area. But I wouldn’t want any of them. set the parameter blank.
I can assign a zone to a view but cannot set the parameter empty. If I can do it it will be much simpler
the parameter storage type is not a string. but in the end he is waiting for an element. but i want it to be empty i don’t know how to do it
For element parameters like that you usually need to provide the InvalidElementId
to set them null or “clear the value”. You can do this through the API, but I don’t think there’s a way to do it in Dynamo currently.
“Zone de definition” is a “Scope Box” in English Revit terminology, maybe?
In that case you can use Springs’ SetParameterToNone
node to assign an invalid Id.