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?
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
Thank you I was looking for this block
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