image by unknown

delete imported line patterns using dynamo

image by unknown

If you are managing a Revit project chances are that you have to deal with some consultants working in AutoCAD platform. It’s not an ideal situation. If I had to compare it to something it would be that awful roommate you had in college that just would never keep the place clean. This is how it is with AutoCAD – Revit situation. You want to do everything you can to keep that CAD trash out of your Revit model. So you drill your team on importance of cleaning the CAD files of all layers and purging it nicely and of course NEVER IMPORT, if anything link that beast in. Even though, someone will always import some CAD in and with it comes the trash: LINE PATTERNS:


Yes, this is annoying to say the least, especially if you have roughly 8585 of those! This is insane!

Here’s how to get rid of ones that are named in a way that my gut feeling tells me come from AutoCAD – IMPORT – Xref – …. yes I can see you from a mile away!

First let’s get all Line Patterns using Element Types and All Elements of Type. Once you have all of them you can see their name with Element.Name node.

Next step is to filter line patterns that we think came from AutoCAD. We are looking for any line pattern that has IMPORT in its name. Here’s how:

String.Contains node will return a boolean True or False if word IMPORT is contained in a line pattern name. We can next use that to filter element list like so:

You can see that using List.FilterByBoolMask will return only desired elements. Also, a quick glance at List. Count reveals that our filtered list contains “only” 8543 elements from the original 8585. Now let’s get them deleted from the model. Since Dynamo currently doesn’t have a delete elements node (and rightfully so, its a bit scary to throw one in for every beginner user) i created my own. Here’s code for the Python node that will do the Deleting:

Here’s what you will get when you run it:

Now I am just going to re-run my definition and pull off a Watch component from All Elements of Type node to see what I am left with after the deletion process:

Yes, this looks a lot better now. I only have 42 line patterns left in the project. Congratulations, you have just taken out AutoCAD trash!


  1. Orges Lesha says:

    This is quite useful, especially when working with a lot of new user that like to import. Was trying to do this myself, but I couldn’t find the nodes on Dynamo Library. Are them so customized combined nodes?

    • Konrad says:


      I have not been very diligent about posting my nodes in Dynamo’s Package Manager. I need to get better at that as I realize that a lot of people use it. Also, sometimes I write posts and post Python code for certain things that I don’t want to post to Package Manager. Some workflows are very specific and I don’t think would make for a great node so I just keep them as Python custom components. When you see Python code posted just copy and paste it into a Python node and that will do the trick. Good luck!

  2. Gio says:

    the “Element.Name” node is not happy with the “in” value coming from List.FilterByBoolMask” node… it produces the “Dereferenceing a non-pointer” error.

    How come it seem to work in your script?

    How do you extract the elements from the “in” of the mask node (which is a list) and feed them to the delete script?

    thank you!

    • Gio,

      This might happen for a number of reasons but usually because a different than expected type was supplied somewhere in the input list. When you use All Elements of Type node there is a chance that a family type (not a family instance) will get included (if family type name matches family instance name for example), and that can cause Element.Name node to turn yellow and display an error. You can see its yellow in my tutorial as well, but it still works. I wasn’t worried about it. As long as it does what I need it can be whatever color it wants to be. :-)

  3. Sol Amour says:

    Hello Konrad. Very very cool workflow and script creation! Mightily impressed.

    We have this issue currently in our office on a job – someone’s inadvertently imported a CAD file. I was hoping to use it to cut out a lot of manual deletion.

    When copy/pasting your Python node I get the following error:

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

    I’m wondering if the latest Dynamo release has changed things slightly?

    • Sol,

      So somewhere in the filtering process you managed to feed text into the Python node instead of elements. I would suggest that you backtrack your steps and see what output you get from the FilterByBooleanMask node and make sure they are all elements.
      This error shouldnt be generated by latest Dynamo.

  4. Sol Amour says:

    Hello Konrad. That makes perfect sense. I’ve gone through my script and do believe I’ve followed your examples.

    I’m feeding in a string into ‘searchFor’ – but unless I’m mistaken, that is what you have above? Beyond that I’m a bit stumped.

    I’m wondering if somehow I didn’t copy your code over correctly? I tried it three times however.

    While I’m picking up Dynamo now (The snowball is gaining momentum), Python is still anathema to me (But it’s on the to-do-list!).

    Thank you so much for your time – you don’t know how much it helps :)

    • Sol,

      You have a list problem. I am not sure if you noticed but the output of your get all elements of type returns a nested list or so called Nested List. When you make that an input into String.SearchFor it checks just the top most list and not the sublists. Either flatten it or use List.Map with String.SearchFor as a Function. Let me know if that worked.

  5. Sol Amour says:

    Hello Konrad.

    First of all thank you for your time, I really do appreciate it.
    Secondly, I have attached another image showcasing the flatten method. I’ve also tried the to no avail. I’m wondering if I’m inputting it wrong however.

    As per your previous comment, the things I’ve highlighted in Pink, are in fact nested lists? I assumed it was just a title stating that the output was in fact a list. If nested, the flatten node isn’t functioning on them. Obviously the one highlighted in blue is a sub-list.

    I’m wondering if this could be anything to do with Revit? I’m using 2014 right now for a job (Spanning a couple of years – consistency etc). I do have 2015 as well but don’t use it at the moment.

    Thanks for your help

    • List.Flatten is a good node when you want to flatten a list by a given amount, but in this case the best solution is just Flatten. List.FilterByBooleanMask is to filter line pattern elements, so that is what needs to be inputted into it. Give that a whirl and see what happens.

      Attachment:  Capture.png

  6. Sol Amour says:

    Ah-ha! Success. Thanks a million Konrad – you rock.

  7. Szymon says:

    Super, działa ! Dzięki za dokładny opis .

  8. Krishna says:

    Hi Konrad,

    I seem to have a strange result where the line style itself ( 0.18_JX ) is delete from within the drafting view but is still “there” under the Manage Line Styles menu with settings cleared. Do you happen to know an approach to delete the line style itsef as opposed to the line pattern?

    Thanks in advance!


    Attachment:  Issue.jpg

    • Krishna,

      Yes, this is expected as the post was about deleting LINE PATTERNS and not LINE STYLES. Those are two different objects. Luckily deleting Line Styles is not very difficult. Please see attached image. All nodes used are part of Archi-lab package. Good luck!
      ps. Remember that not all line styles can be deleted. There are some line styles like Wide Lines, Room Seperation, Hidden Lines, etc that are built in and cannot be deleted. Only User Created Line Styles can be deleted.

      Attachment:  Capture1.png

  9. Arsanios says:

    Hi Konrad,
    I did follow your steps but still I can’t delete these line patterns.
    I think there is something with Python Script node I’m not understanding.


  10. andrew says:

    I’m getting a return of 0.00 when i run this whole thing. what version of dynamo was the python code written for?

    Attachment:  img1.png

  11. Shaun Peppers says:


    You showed a way to delete Line Styles. You use a node called “Get All Line Styles”. I cant seem to find this node. Do you have an updated way of doing this? We have thousands of line styles that were repeated in Revit that need to be purged.

  12. Mike says:

    Hi Konrad

    Thanks for this post – very helpful. I’m attempting to do this with your Delete Elements node rather than the Python script and it’s not working. Any ideas?


  13. Adrian says:

    Thank you! I had over 17500~ line patterns and managed to delete them by following your tutorial. The file size went from 600mb to 300mb. I don’t even know much about dynamo. Your post was really helpful!

  14. Salvo says:

    Hi Konrad,
    I some some patterns that couldn’t be deleted. In Revit they start like that:
    In Dynamo the “IMPORT:” is removed.
    See attached image.
    I can’t figure out how you select the pattern to be deleted in your code.


    Attachment:  01.png

  15. Salvo says:

    Apologies, it was a dummy question :-)

    All sorted


  16. Shruti says:

    Thank you, this is life saver. I deleted 13500 line patterns just now.


Leave a Comment