Hi everyone!
So, I’m working on a routine that I should create a legend … But since the API won’t let me create legends what I’m trying to do is:
If there is no pre-defined legend, duplicate any legend (the duplicate one needs to be blank) and change its name…
I was able to do this on two nodes, but I wanted to insert this into just one… The problem is that when I try it returns:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 55, in
AttributeError: ‘View’ object has no attribute ‘ToDSType’
My code:
import clr
Import RevitAPI
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *
Import DocumentManager and TransactionManager
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#allow us to use Dynamo nodes
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
doc = DocumentManager.Instance.CurrentDBDocument
########################################
INPUTS
viewName = IN [0]
elementlist = list()
Collecting just LEGENDS
#Parameter
param = BuiltInParameter.VIEW_TYPE
#Provider and evaluator
provider = ParameterValueProvider(ElementId(param))
evaluator = FilterStringEquals()
for n in viewName:
#rules
rule = FilterStringRule(provider, evaluator, “Legends”, False)
filterparm = ElementParameterFilter(rule)
Collector
collector = FilteredElementCollector(doc).OfClass(View).WherePasses(filterparm).ToElements()
######## APPLYING CONDITIONS ######
existview =
view =
for i in collector:
if i.Name == viewName:
view = i
elif i.ViewType == ViewType.Legend:
existview.append(i)
TransactionManager.Instance.EnsureInTransaction(doc)
##duplicate view and get it
view= existview[0].Duplicate(ViewDuplicateOption.Duplicate)
TransactionManager.Instance.ForceCloseTransaction()
“”"" WHAT I’m strugling
x = doc.GetElement(view).ToDSType(True)
view = u.SetParameterByName(“View Name”, viewName)
“”"
else:
view = “no legend in this project”
OUT = view
Sample_workaround.dyn (8.4 KB)
has anyone found a solution for this?