How to set Viewport Type?

revit
archi-lab
clockwork

#1

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).

Thank you!

Bot - Set Viewport Types for 3D Views.dyn (11.6 KB)


#2

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

#3

Where do you put this python script…can’t get it to work


#4

@Arno_De_Lange search for a Python Script node and copy the code above.


#5

I get how we get the Python node in, but i can’t get what we feed it… how does it fit in the flow…


#6

Post a screenshot of what you have tried so we can help with your current roadblock.


#7

so the element.SetParameterByName… doesn’t give an error but it doesn’t change the viewport either

pythonscript is the script above in this thread

Arno


#8

@Greg_McDowell, no Python needed. We can set the appropriate parameter by using the BuiltInParameter nodes from Archi-lab.

@Arno_De_Lange, This should do the trick:

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.


Collect the texts of the viewports tags directly on the drawing sheet
#9

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.

but now i don’t get the pull down menu any more
Capture


#10

That node outputs a string: “ELEM_TYPE_PARAM” so you can just hard code that instead. Of course it would be easier to get the actual thing to work.


#11

Works perfect thank you Konrad


#12

What did you do to get this working?


#13

the parametername input was a string called ELEM _TYPE_PARAM in my case


#14

Your using a string node and at what place did you put?
Or did you use a code to place it in to replace the Get BipParameter Name?


#15

Anthony, did you figure this one out? can’t read your picture it has no headers


#16

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.


I have tried different ways but I’m not sure what to do.


#17

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.


#18

You are getting a NAME (string, text) and feeding it into the Element input. Please feed it an element (one, 1).


#19

This works with @Greg_McDowell Python code:


#20

Where the node Viewport.ViewName does come from? I could not find it.