Delete un used Lines subcategories

hello
can i remove unused Lines subcategories
I cant find any way to remove them by dynamo

yes, you can remove them…here where do you need help?


i can’t find an element to delete all i have is subcategories names

do you want delete the marked elements of need to filter from unwanted?

yes, but the issue that i can’t get the subcategory

?

but you can’t delete them

try like this, use the spring node to delete the subcategory.

Line.dyn (16.3 KB)

2 Likes

Thank you I was looking for this block image

1 Like

how do you know if that thing is not being used in the project file?

It doesn’t

I take the approach that even if linesStyles are not used, that doesn’t mean they shouldn’t be there.
My general approach is to instead amalgamate all the rouge linestyles into the correct ones.

However, if you were to simply check if the linestyle existed in the proejct and delete it if it was not then you can use this approach. (Gets All Lines, Gets All Lines in Project for Each Subcategory, if the list of lines in the project for the subcategory is empty, then it it un-used. Filter the Subcat list by that boolean and then delete the resulting subcategories.

Python - Line Details
#╦╔╦╗╔═╗╔═╗╦═╗╔╦╗╔═╗
#║║║║╠═╝║ ║╠╦╝ β•‘ β•šβ•β•—
#β•©β•© β•©β•©  β•šβ•β•β•©β•šβ• β•© β•šβ•β• IMPORTS
#================================================================

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *


clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *


#╦  ╦╔═╗╦═╗╦╔═╗╔╗ ╦  ╔═╗╔═╗
#β•šβ•—β•”β•β• β•β•£β• β•¦β•β•‘β• β•β•£β• β•©β•—β•‘  β•‘β•£ β•šβ•β•—
# β•šβ• β•© β•©β•©β•šβ•β•©β•© β•©β•šβ•β•β•©β•β•β•šβ•β•β•šβ•β• VARIABLES
#================================================================
# Current doc/app/ui

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

LineStyles = []
LineGraphicStyle = []
LineRGB = []
LineStyleID = []
LineStyleName = []
LineUserMadeBool = []
listPattern = []
listpatid = []
patname = []
lineWeight = []

#╔═╗╔═╗╦  ╦  ╔═╗╔═╗╔╦╗  ╦  ╦╔╗╔╔═╗╔═╗
#β•‘  β•‘ β•‘β•‘  β•‘  β•‘β•£ β•‘   β•‘   β•‘  β•‘β•‘β•‘β•‘β•‘β•£ β•šβ•β•—
#β•šβ•β•β•šβ•β•β•©β•β•β•©β•β•β•šβ•β•β•šβ•β• β•©   β•©β•β•β•©β•β•šβ•β•šβ•β•β•šβ•β• COLLECT LINES
#================================================================
# Collect the BIC
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Lines).ToElements()

# Isolate BIC from collection
bic = collector[0].Category
subcats = bic.SubCategories

# Determine LineUserMadeBool values
for subcat in subcats:
    subcatid = subcat.Id.IntegerValue
    subcatidasint = int(subcatid.ToString())

    if subcatidasint > 0:
        LineUserMadeBool.append(True)
    else:
        LineUserMadeBool.append(False)

# Filter subcats based on LineUserMadeBool
subcats_filtered = [subcat for subcat, usermade in zip(subcats, LineUserMadeBool) if usermade]

for subcat in subcats_filtered:
    subcatid = subcat.Id.IntegerValue
    subcatidasint = int(subcatid.ToString())
    LineStyleID.append(subcatidasint)

    subcatele = Revit.Elements.Category.ById(subcatid)
    LineStyles.append(subcatele)

    LineStyle = subcat.GetGraphicsStyle(GraphicsStyleType.Projection)
    LineGraphicStyle.append(LineStyle)

    subcatname = LineStyle.Name
    LineStyleName.append(subcatname)

#╦  ╦╔╗╔╔═╗╔═╗  ╦╔╗╔  ╔╦╗╔═╗╔╦╗╔═╗╦  
#β•‘  β•‘β•‘β•‘β•‘β•‘β•£ β•šβ•β•—  β•‘β•‘β•‘β•‘  β•‘β•‘β•‘β•‘ β•‘ β•‘β•‘β•‘β•£ β•‘  
#β•©β•β•β•©β•β•šβ•β•šβ•β•β•šβ•β•  β•©β•β•šβ•  β•© β•©β•šβ•β•β•β•©β•β•šβ•β•β•©β•β• LINES IN MODEL
#================================================================

if isinstance(LineStyleName, list):
    names = UnwrapElement(LineStyleName)
else:
    names = [UnwrapElement(LineStyleName)]
    
alllines = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Lines)

lines = []

for n in names:
    lines.append([x for x in alllines if x.LineStyle.Name == n ])

# Outputs for Dynamo
OUT = LineGraphicStyle, LineStyleName, lines, subcats_filtered
Python - Eraser Tool
#python nodes in dynamo 1.0
#proposed by Julien Benoit @jbenoit44 
#http://aecuandme.wordpress.com/
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

elt = []
for i in IN[0]:
	elt.append(UnwrapElement(i).Id)

# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)


cantdelete=[]
for item in elt:
	try:
		doc.Delete(item)
	except:
		cantdelete.append(item)
		

# End Transaction
TransactionManager.Instance.TransactionTaskDone()
doc.Regenerate()
OUT=cantdelete
1 Like