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:

image_01

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!

Support archi-lab on Patreon!

72 Comments

  1. Orges Lesha says:

    Hi.
    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?
    Thanks

    • Konrad says:

      Orges,

      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:

    Hi,
    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:

    Warning:
    IronPythonEvaluator.EvaluateIronPythonScript
    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 list.map 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!

    -K

    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.

    Thanks.

  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:

    Konrad,

    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?

    Thanks.

  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:
    “IMPORT:…”
    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.

    Thanks

    Attachment:  01.png

  15. Salvo says:

    Apologies, it was a dummy question :-)

    All sorted

    Cheers

  16. Shruti says:

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

    Cheers

  17. Shawn Brennan says:

    Konrad,

    This is awesome. Thank you for sharing this. This was my first dynamo program. While I am just copying what you’ve done, it still lays out a foundation for me to get started.

    I am having an issue though. The Python script is not returning the actual number of Line Patterns removed. I am running v1.2.1.3083 & Revit 2017, also included a ZIP of the program. The python script was also copied and pasted with no alterations.

    Other than that, it appears to work on an out of the box template file with a manually named line pattern.

  18. camuz says:

    WOW!!! Bravísimo Konrad!!

    You just saved me a lot of time!! Thanks for your amazing work! I had the same problem as Sol, maybe you should upload the correction you made on his image.

    Kudos!! (Y)

  19. William McAvoy says:

    Hi Konrad,

    A quick one hopefully. I have followed your above steps, and have also copy and pasted your script. I am however getting the error message ‘File “, line 32, in Attribute error ‘bool’ object has no attribute ‘Id’

  20. Joianna Carson says:

    Hi Konrad,
    I am in need of deleting around 145 Line Styles from a shared revit template. Having never worked with Dynamo (or programming) I was able to rework your example to filter out linestyles. Unfortunately when I finally reach the “Holy Grail” of the script, the deleting part, I wind up with an error message:

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

    What does this mean and is it something I can fix/adjust to work with my LineStyle.dyn?
    I have attached a copy of my .dyn file. I’m sure it’s more cumbersome than it needs to be but this is the first time I have done anything in Dynamo.

    Thank you for your help.

    Attachment:  LineStyle.zip

  21. jon says:

    Hi Konrad,
    this is my first time using Dynamo. i have 15k Cad line patterns i need to get rid of and i followed you instructions and i’m not getting any errors, but its not deleting the patterns. can you please tell me what i’m doing wrong, i cant figure it out.
    thanks!
    jon

  22. RONALD E ALLEN says:

    Great for a purge but what about checking if they are in use first, then if they are swapping in lieu of just deleting?

    Particularly in the line styles and object styles? Then maybe the view templates?

    • Danifly says:

      Hi, Great work Konrad!!!!

      I have the same doubt of Roland, Is there a way to check or filter the element that are in use?

      thanks

  23. Anyone know why I cannot get the Revit Elements to load?

    I cannot get the “All Elements Type” to install… any idea’s why?

    Attachment:  Dynamo_issue.jpg

  24. Christopher R Ganiere says:

    Thank you so much. I was able to follow through and make the node.

  25. Robert Cross says:

    Hi there,

    Can I get my hands on a copy of the dynamo script.

    Thanking you in advance.

  26. Ysh says:

    This was Excellent! Thank you,
    But may I suggest adding a note about Python code on the title of article? this can not be done by Dynamo alone

  27. yethica says:

    Hi Konrad.

    This script is, for the most part, awesome. However, it appears that with later versions of Revit (2016 and beyond) it will only remove line patterns that have IMPORT in the name of the line pattern. With the later versions of Revit, instead of tacking IMPORT onto the front of the line pattern name, Revit now leaves the line pattern name as-is (in some cases) and tracks whether it’s imported in some other way, seemingly by giving it a form of “tag” that says IMPORT:.

    Any idea how we might work around this problem? I can’t figure out what parameter of the line pattern I’d need to extract to find this “tag”. Pic of the weird line pattern types is attached.

    Cheers!

  28. patricia says:

    Thanks for posting this! I had trouble with Line 35 of the Python Script but, after looking at your comments to Konrad, found I was linking the string to to bool mask, not the element. Fixed it and viola! This is also working on Dynamo Player so I can make it available to my workmates.

  29. Daniel says:

    Thanks Konrad!
    It was really useful; however, not all the IMPORT lines were deleted. Somehow Dynamo reads them as “normal” lines. See attached image.

    Attachment:  Line-Patterns.jpg

  30. Patrick S says:

    Thank you for this! 516 Line Patterns accidentally imported in are now deleted from my project! Very helpful.

  31. Jaysyn Quarry says:

    Dynamo 2.0.3.8811
    I am getting the “Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
    Traceback (most recent call last):
    File “”, line 35, in
    AttributeError: ‘str’ object has no attribute ‘Id'”
    error. It worked once and now I get the error. Any idea what the problem is Konrad and how I can fix the python code? I copied it directly from your post FYI

    Thanks a ton for creating this post BTW. =)

    Jaysyn

  32. Jaysyn Quarry says:

    Here is my graph….

    Attachment:  Capture-2.png

  33. Rob says:

    Hi Konrad

    Where can I grab the Delete Elements node from? is it still in the archilab pack? using Dynamo 2.3

    Attachment:  Delete-Elements.png

  34. Andrew Yeh says:

    Good morning Konrad,
    if you have a chance could you able to take a look of this dynamo script please?
    I have used what you taught us so far, and this dynamo script is removing the lines work (from Revit Family) instead of project.

    but, I am stuck in the end and not able to delete the selected list…
    please advice

    Thank you so much!

    Attachment:  Dynamo.png

  35. Aamir says:

    HEY KONARD
    I have copied the python script for deleting line patterns
    is that okay with you please
    regards

  36. Marvin Infante says:

    Is it possible to use this approach to rename a certain filtered list of line patterns brought in from linked CAD files? I’ve seen the graph for replacing a substring of the name, but I’d like to rename the line patterns in this list. I want a more efficient means of renaming the layer’s line pattern name as opposed to changing them in the imported categories tab of the object style window.
    Any direction would be appreciated.

  37. Raqs says:

    Konrad – what happens with the lines that are using these “IMPORT…” patterns? I assume they default to a different pattern, such as solid?

    • Yup. They default to one of the system line patterns. Solid is a good guess. I don’t know which one it is for sure, but Solid is a good guess because it’s not possible to delete it from the model, so it makes sense that it would be set to that.

  38. Christian Jacob says:

    Wow! This is Fantastic! It worked great. Thanks Konrad.

  39. Ibrahim says:

    thanks konrad this script was a great help

  40. Bill Zahurak says:

    Hi Konrad,

    thanks for this much needed script. I’m trying to use on Revit 2020.2.9 with Dynamo version 2.3.2.15724, core 2.3.2.15696 and getting the error below. I believe I used the same node configuration and copied and pasted the python script

  41. Bill Zahurak says:

    sorry, didnt post the error

  42. Hyo says:

    Thanks for your script. I had a lot of unused “IMPORT” line patterns and didn’t know how to delete all these ones. But with this script, I can delete them all even in a few minutes.

Leave a Comment