How to generate DuplicateView with Detailing


I am trying to generate DuplictedView WithDetailing and then apply ViewTemplate,
I am struggling with python script,
Would appreciate any help,

import sys
import clr
from System.Collections.Generic import *
from Autodesk.Revit.DB import *
import Autodesk

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
References = UnwrapElement(IN[0])
Templates = UnwrapElement(IN[1])
ViewTypeId = References[0].GetTypeId()
DupWithDtl = Autodesk.Revit.DB.ViewDuplicateOption.WithDetailing

for Reference in References:
	LvlId = Reference.GenLevel.Id
	ReferenceScopeBox = Reference.GetParameters('Scope Box')[0].AsElementId()
	DependentViewsId = Reference.GetDependentViewIds()
	if len(DependentViewsId) != 0:
		DependentViews = FilteredElementCollector(doc, DependentViewsId)
		DepScopeBoxes = []
		for DependentView in DependentViews:
			DepScopeBoxes.append(DependentView.GetParameters('Scope Box')[0].AsElementId())
	for Template in Templates:
		NewView = View.Duplicate(Reference, DupWithDtl)
		NewView.ViewTemplateId = Template.Id
		NewView.Name = str(Reference.GenLevel.Name) + '_' + str(Template.Name)
		NewView.GetParameters('Scope Box')[0].Set(ReferenceScopeBox)
		NewView.GetParameters('Scope Box')[1].Set(ReferenceScopeBox)
		if len(DependentViewsId) != 0:
			for DepScopeBox in DepScopeBoxes:
				NewViewDep = NewView.Duplicate(AsDependent)
				NewViewDep.GetParameters('Scope Box')[0].Set(DepScopeBox)
				NewViewDep.GetParameters('Scope Box')[1].Set(DepScopeBox)
OUT = References

Without testing your code, its safe to say that your new view is a Revit ElementId object, not a View object and thats the cause of the execption. You therefore need to get the View object before you can call the ApplyViewTemplateParameters() method. Try this on the problem line (and any other method that is a member of the View class):


1 Like

thanks a lot, I love this forum,

hi, Michel could you please share the script with us
many thanks