How to Delete Line Styles


public void deleteLineStyle()
{
    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;
    Category linesCat = doc.Settings.Categories.get_Item("Lines");

    IList<Category> categoryList = linesCat.SubCategories.Cast<Category>().Where(c => c.Name.StartsWith("A-") || c.Name.StartsWith("S-")).ToList();
    IList<ElementId> idsToDelete = new List<ElementId>();
    foreach (Category cat in categoryList)
    {
        idsToDelete.Add(cat.Id);
    }

    using (Transaction t = new Transaction(doc,"Delete LineStyle"))
    {
        t.Start();
        doc.Delete(idsToDelete);
        t.Commit();
    }
}
Advertisements

20 thoughts on “How to Delete Line Styles

    • Have you tried something like
      Category linesCat = doc.Settings.Categories.get_Item(“Lines”);
      Category subCat = document.Settings.Categories.NewSubcategory(linesCat, “NewSubCat”);

  1. thanks Harry… it works

    public void addLineStyle(UIDocument uidoc)
    {
    Document doc = uidoc.Document;
    Category linesCat = doc.Settings.Categories.get_Item(“Lines”);

    using (Transaction t = new Transaction(doc, “New LineStyle”))
    {
    t.Start();
    Category subCat = doc.Settings.Categories.NewSubcategory(linesCat, “NewSubCat”);
    t.Commit();
    }
    }

  2. Hi- at the portion-
    doc.Settings.Categories.get_Item(“Lines”)
    Is there a line patterns that we can grab to say purge out all the IMPORT-ACAD* patterns? I get tons of imported CAD file junk and end up purging this manually every time. Even better to search out the line patterns, offer to replace them with a ‘standard’ revit pattern and the purge em! : )

  3. Harry,

    I’m using this code to try and remove a few hundred duplicate linestyles created by Siteworks. I changed the search string to “SW ” as all the linestyles start with that. But the macro doesn’t seem to do anything. It runs without error but doesn’t actually remove the linestyles. Any ideas?

  4. I kept all the code from your example, just changed the string that is being searched. I ended up using a python script to do it. Did not get a list or anything. https://github.com/eirannejad/pyRevit/blob/master/pyRevit/Wipe_deleteSiteDesignerLineStyles.py

    Problem is being caused by a plugin. Documented here:
    https://knowledge.autodesk.com/support/revit-products/troubleshooting/caas/sfdcarticles/sfdcarticles/Revit-Thousands-of-new-Linestyles-show-up-in-project.html

  5. Hi Harry,
    I cant see any immediate way of doing this after checking with intellisense, however is it possible to get collections of each linestyle within a detail component familyinstance and then change these out for another linestyle type?

  6. Just trying to remove the ‘over generic’ lines sub-category called “Lines”. Revit says it cant find the elementId, even though it is in the revit file. Is there a way to at least rename that sub-category?

    { UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;
    Category linesCat = doc.Settings.Categories.get_Item(“Lines”);
    Category idsToDelete = linesCat.SubCategories.get_Item(“Lines”);

    using (Transaction t = new Transaction(doc,”Delete LineStyle”))
    {
    t.Start();
    doc.Delete(idsToDelete.Id);
    t.Commit();
    }

    }

  7. Simple and tough one – my aim is to programatically rename Line Styles. Perfectly easy in the UI, seems to be not that easy via API – any pointer appreciated..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s