# Deleting Unwanted Line Styles that are NOT Imported

**URL:** <https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004>\
**Category:** Developers\
**Tags:** archi-lab, python\
**Created:** [January 19, 2017, 8:15pm UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004 "2017-01-19T20:15:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![joianna](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@joianna](https://forum.dynamobim.com/u/joianna)\
**Post date:** [January 19, 2017, 8:15pm UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004/1 "2017-01-19T20:15:36Z")

</div>

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 -  
 ![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/3X/4/5/45bae1cbb930ddb923c4b130f950bacb902b4fb4.png)

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?

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [January 19, 2017, 9:12pm UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004/2 "2017-01-19T21:12:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joianna](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@joianna](https://forum.dynamobim.com/u/joianna)\
**Post date:** [January 19, 2017, 9:31pm UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004/3 "2017-01-19T21:31:20Z")

</div>

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](http://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’))

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [January 19, 2017, 9:40pm UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004/4 "2017-01-19T21:40:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joianna](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@joianna](https://forum.dynamobim.com/u/joianna)\
**Post date:** [January 19, 2017, 10:18pm UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004/5 "2017-01-19T22:18:53Z")

</div>

@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’

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [January 19, 2017, 10:26pm UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004/6 "2017-01-19T22:26:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joianna](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@joianna](https://forum.dynamobim.com/u/joianna)\
**Post date:** [January 19, 2017, 10:50pm UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004/7 "2017-01-19T22:50:04Z")

</div>

@Daniel_Woodcock1

Is this what you are looking for?

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/4/a4b151bf00da8ac3126669cfaca467ac7414e176.png)

---

<div class="post-metadata">

**Author:** ![Daniel\_Woodcock1](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Daniel\_Woodcock1](https://forum.dynamobim.com/u/Daniel_Woodcock1)\
**Post date:** [January 20, 2017, 7:53am UTC](https://forum.dynamobim.com/t/deleting-unwanted-line-styles-that-are-not-imported/9004/8 "2017-01-20T07:53:41Z")

</div>

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.
