Revit Duplicating 1000s of Line Styles

Revit Duplicating 1000s of Line Styles

Anonymous
Not applicable
546 Views
2 Replies
Message 1 of 3

Revit Duplicating 1000s of Line Styles

Anonymous
Not applicable

Hi guys - I ran a search but haven't found a solution to this specific problem so here goes:

 

I believe this is a problem I'll need to address through the Revit API - I've tried deleting these line styles using PythonRevitShell, SharpDevelop and Dynamo. 

 

I'm having problems with Revit 2015 duplicating line styles. This is similar to other problems I've read about where Site Designer duplicates line styles (with the prefix 'SW'). This problem seems to have been fixed in Revit 2017.

 

A highly-detailed write-up of the problem (with images links and previous attempted approaches) can be found here: 
https://forum.dynamobim.com/t/revit-duplicating-1000s-of-line-styles/9492 

 

If anyone has any ideas on how to approach deleting these duplicate linestyles I'd love to hear your suggestions! 

Thanks for reading (and sorry if this isn't in the spirit of the API forum - if it's totally the wrong place please feel free to delete this question)

 

Ollie

0 Likes
Accepted solutions (1)
547 Views
2 Replies
Replies (2)
Message 2 of 3

FAIR59
Advisor
Advisor
Accepted solution

The problem are not LineStyles, but subCategories of the following BuiltInCategories:

  • OST_GenericAnnotation
  • OST_DetailComponents
  • OST_GenericModel

 

this code will remove all the subCategories with "PTE" in the name.

 

    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]

    public class Remove_PTEDuplicates : IExternalCommand
    {
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            try
            {
                Document doc = revit.Application.ActiveUIDocument.Document;

                List<ElementId> toDelete = new List<ElementId>();
                IList<GraphicsStyle> GraphicStyleList = new FilteredElementCollector(doc)
                .OfClass(typeof(GraphicsStyle))
                .Cast<GraphicsStyle>()
                .ToList();

                foreach (var _g in GraphicStyleList)
                {

                    if (_g.GraphicsStyleCategory.Name.Contains("PTE"))
                    {
                        if (!toDelete.Contains(_g.GraphicsStyleCategory.Id))  toDelete.Add(_g.GraphicsStyleCategory.Id);
                    }
                }
                using (Transaction t = new Transaction(doc, "purge PTEStyles"))
                {
                    t.Start();
                    doc.Delete(toDelete);
                    t.Commit();
                }
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                TaskDialog.Show("catch", ex.ToString());
                return Result.Failed;
            }
        }
    }

 

 

Message 3 of 3

Anonymous
Not applicable

Amazing - thank you fair59! 

0 Likes