Deleting Unwanted Line Styles that are NOT Imported

I have decided to delve into the world of Dynamo and for my first script I am attempting to delete all of the unwanted line styles in a shared revit template.

I started by utilizing the “Delete-Imported-Line-Patterns-Using-Dynamo” script created by Konrad Sobon and modifying it to work for line styles instead of line patterns. All seemed to be working well until reaching the actual delete node. This node required a python script, which was provided. I inserted the python script but it failed to execute completely. I am thinking this is because the script was written to delete line patterns and not line styles.

Here is my Dynamo script -

The error message I receive -
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 35, in
AttributeError: ‘List[object]’ object has no attribute ‘Id’

If someone could point me in the right direction so that I might get this code to work I would appreciate it.
Should I provide a copy of the python script for better understanding?

Hi @joianna,

You’ll find that error message pop up quite often when you are not handling lists correctly or not at all. Usually this is resolved by looping through the items in a list and performing the function for each…

Could you copy and paste the code here so we can have a look?

Cheers,
Dan

Here is the code -

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

Import DocumentManager and TransactionManager

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import RevitAPI

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

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

from System.Collections.Generic import *

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

#unwrap all elements to use with API
elements = []
for i in IN[0]:
elements.append(UnwrapElement(i))

idsToDelete = ListAutodesk.Revit.DB.ElementId
for i in elements:
idsToDelete.Add(i.Id)

“Start” the transaction

TransactionManager.Instance.EnsureInTransaction(doc)

doc.Delete(idsToDelete)

“End” the transaction

TransactionManager.Instance.TransactionTaskDone()

message = “You have successfully deleted n " + str(idsToDelete.Count) + " elements from Revit model.”

OUT = ‘n’.join(’{:^35}’.format(s) for s in message.split(‘n’))

The script looks ok. Doesn’t handle single items though. I think the problem is you have a list of more than one level. Try flattening your list first before plugging it into the script. You can use the list.flatten node

@Daniel_Woodcock1 Thank you for your help.

I was able to flatten the list per your suggestion, alas I am now receiving a new error message

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 35, in
AttributeError: ‘str’ object has no attribute ‘Id’

Hi @joianna,

I can’t see the names of any of your nodes in the script image you uploaded earlier. Could you just do a snippet instead and add some watch nodes to see what your data is doing in different places of your graph - no need to do the whole thing, just one of the runs as it looks like you have copied/pasted the same thing a few times.

The error is saying that you need to pass an Element, not a string. It appears you are passing just the name of the element and not the element itself. Elements are shown in watch nodes (or in node drop downs) with an ElementId next to it in green.

Cheers,
Dan

@Daniel_Woodcock1

Is this what you are looking for?

Hi @joianna,

I’ve never used that LineStyle node before, but the “All LS Names” port you are using doesn’t give you the Elements, just the name. This is great for how you are using it until the filter by bool node where you really want to filter the Elements. I am assuming the “All Linestyles” port are the Elements and are in the same order as the All LS Names.

I think only one little change is needed and it is to wire the OUT port “All Linestyles” into the filter by Bool’s “List” IN port.

1 Like