I am wanting to remove a view template from existing views. I couldn’t find a node that did this so attempted to write some python coding to perform this task. I am getting an error saying that the integer value that I am trying to write the -1 to is read only.
Is there an easy way of doing this using nodes or what am I missing in my python coding?
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
#The inputs to this node will be stored as a list in the IN variables.
views=UnwrapElement(IN[0])
elementlist=list()
for i in views:
i.ViewTemplateId.IntegerValue = -1
elementlist.append(i.ViewTemplateId.IntegerValue)
#Assign your output to the OUT variable.
OUT = elementlist
Sorry Andreas my python coding skills aren’t up to your level.
I’m trying to set the ViewTemplate.IntegerValue parameter. I’m getting an error with the below do I need to “Set” the value of use an “=”?
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variables.
views=UnwrapElement(IN[0])
elementlist=list()
for view in views:
# try:
view.ViewTemplateId.IntegerValue.Set(ElementId(-1))
elementlist.append(i.ViewTemplateId)
# except:
# elementlist.append("fail")
#Assign your output to the OUT variable.
OUT = elementlist
Thanks for your help @Andreas_Dieckmann I have used Konrad’s node but for my education I have tried your suggestion but am still getting an error. Any ideas
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variables.
views=UnwrapElement(IN[0])
elementlist=list()
for view in views:
# try:
view.ViewTemplateId = ElementId(-1)
elementlist.append(i.ViewTemplateId)
# except:
# elementlist.append("fail")
#Assign your output to the OUT variable.
OUT = elementlist
@Dimitar_Venkov, thank you for your input sorry to be a pain but again for my own education what is the coding that uses the static property, I tired the below but received error messages
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variables.
views=UnwrapElement(IN[0])
elementlist=list()
for view in views:
# try:
view.ViewTemplateId.ElementId.InvalidElementId
elementlist.append(i.ViewTemplateId)
# except:
# elementlist.append("fail")
#Assign your output to the OUT variable.
OUT = elementlist
If you input a list of views into that input then the method that you are calling will create a list object and it will cause an error when you try to iterate over it few lines down the line. It basically tries to unwrap a list rather than each view in a list. Instead call UnwrapElement() on each element in the IN[0]
Now, once you get past that you are missing a transaction start and end.
Then you are also calling it all wrong. To assign a new view template you must call it like that:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variables.
views=IN[0]
elementlist=list()
# Start Transaction
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
viewunwrap=UnwrapElement(view)
viewunwrap.ViewTemplateId = ElementId.InvalidElementId
elementlist.append(viewunwrap.ViewTemplateId)
# End Transaction
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
OUT = elementlist
Actually I think this was fixed a couple of years a go in this PR, UnwrapElement() sould be able to handle unwrapping of elements in both flat and nested list. See this issue on github:
Thanks @Einar_Raknes, so based on your advice I tried the following code and it worked perfectly
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variables.
views=UnwrapElement(IN[0])
elementlist=list()
# Start Transaction
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
# try:
view.ViewTemplateId = ElementId.InvalidElementId
elementlist.append(view.ViewTemplateId)
# except:
# elementlist.append("fail")
# End Transaction
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
OUT = elementlist