ThreeDimensional view type

Hi,
I am trying to create three dimensional views in Revit via Dynamo. The script is working just fine, but every now and then this error pops up and if I restart it, it goes away. I don’t see an issue in the code or the nodes. Any suggestions?

I have attached the image for reference!

while (count < len(Min)):
b=View3D.CreateIsometric(doc, typeid)
viewlist.append(b)
box = app.Create.NewBoundingBoxXYZ()
box.Min = Min[count]
box.Max = Max[count]
bbox.append(box)
a=View3D.SetSectionBox(b,box)
count = count + 1

The error is referring to the highlighted code above.

Can you show us the rest of your code (using preformatted text please </>) so we can see where typeid is coming from?

1 Like

@Nick_Boyts ! Thank you for your response, here is the entire code.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

Min=[]
Max=[]
viewlist=[]
bbox=[]
for i in IN[0]:
	Min.append(UnwrapElement(i.ToXyz(True)))
for i in IN[1]:
	Max.append(UnwrapElement(i.ToXyz(True)))

TransactionManager.Instance.EnsureInTransaction(doc)
activeview=doc.ActiveView
typeid=View.GetTypeId(activeview)

count = 0
while (count < len(Min)):
	b=View3D.CreateIsometric(doc, typeid)
	viewlist.append(b)
	box = app.Create.NewBoundingBoxXYZ()
	box.Min = Min[count]
	box.Max = Max[count]
	bbox.append(box)
	a=View3D.SetSectionBox(b,box)
	count = count + 1

TransactionManager.Instance.TransactionTaskDone()
OUT=viewlist

Are you sure that somewhere you’re not accidentally activating a non-3D view? I’d recommend selecting a 3D view type through a FilteredElementCollector instead of pulling from the active view to prevent this.

1 Like

@Nick_Boyts ,

I tried the suggestion, now I have a new error “Type Error: Expected Element, got List”.

image

I am fairly new to all this but believe because am creating multiple views is the reason for error pop-up, but then I don’t understand why it does not with active view. Any suggestions?

The updated code for your reference:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

Min=[]
Max=[]
viewlist=[]
bbox=[]
for i in IN[0]:
	Min.append(UnwrapElement(i.ToXyz(True)))
for i in IN[1]:
	Max.append(UnwrapElement(i.ToXyz(True)))

TransactionManager.Instance.EnsureInTransaction(doc)
def filter_list(elements, search_str):
	passed = []
	for element in elements:
		name = element.Name
		if search_str in name:
			passed.append(element)
	return passed
views3d = []
views3d = FilteredElementCollector(doc).OfClass(View3D).WhereElementIsNotElementType().ToElements()
D = filter_list(views3d, 'ThreeD')
typeid=View3D.GetTypeId(D) #Line of error
count = 0

while (count < len(Min)):
	b=View3D.CreateIsometric(doc, typeid)
	viewlist.append(b)
	box = app.Create.NewBoundingBoxXYZ()
	box.Min = Min[count]
	box.Max = Max[count]
	bbox.append(box)
	a=View3D.SetSectionBox(b,box)
	count = count + 1
	
TransactionManager.Instance.TransactionTaskDone()
OUT=bbox,viewlist

anything that is being created in script will need to be converted to Dynamo Type wouldn’t it? by DSType(false)

@sensiblehira Thank you for response. Yes, you are correct, the thing is, it is working for me with ‘activeview’ [ThreeDimensional view type - #3 by H.S] but is not working when I choose a specific view [ThreeDimensional view type - #6 by H.S] . Hence, I am confused about where it is not making sense.

Pull the element from the list index [0]. It dismisses the error.

D = filter_list(views3d, 'ThreeD')
reqview = D[0]
typeid = View3D.GetTypeId(reqview)