Good morning! I’m hoping someone can solve my mystery! I have a relatively simple script that assigns a specific viewport type to a certain set of views. It works 90% of the time. The trouble is, it doesn’t work 100% of the time and I can’t understand why. Sometimes I just have to run it several times and then it works. Sometimes I have to swap the viewport type then run the script and it works.
This might be tricky to test since it is tailored specifically for our model set-up, but any feedback is welcome. (Elements.FilterByName is from the Clockwork package).
Looks like the viewport has 2 parameters called Type that are in different orders in the list (and apparently different at every run).
This is me hacking Python together but, so far, it seems to work;
import clr
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
#The inputs to this node will be stored as a list in the IN variable.
viewPort=UnwrapElement(IN[0])
newId=UnwrapElement(IN[1])
TransactionManager.Instance.EnsureInTransaction(doc)
for i in viewPort:
i.ChangeTypeId(ElementId(newId))
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable
OUT = newId
Ps. The issue with the OOTB parameter nodes are as stated above. There are multiple parameters with the same name, and they are stored in a ParameterSet so an unordered collection. Please use BIP to get the “right” parameter every time.
I got the nodes in … and the get BipParameterName and the first time i got the pulldown menu and could select intstance|type. but there where two in the list. so the script didn’t work probably have the wrong one.
No, I did not figure it out yet. Been going through and recreating the views and schedules that were an issue. It would be awesome if it just made all views, schedules, etc just into one so we could delete all the rest out.
Actually I figured this out getting this to work. I am trying to delete the viewport types that have been brought in through the insert view from file command. Instead of having to find it manually and delete the view or schedule to get rid of the additional families in a template or project.