Line Styles

Is there any way to create and delete Line Styles on Dynamo using Python.

All the solutions I found wants me to use the Bimorph Package and I don’t want to use it. As my dynamo script will be shared with other people who don’t use the Bimorph package

Awaiting for your response

you can do it via revit python shell, collect all the linestyles using FilteredElementCollector, get the specific line style name, then delete. For creation, you can also do via api, create the line pattern first, then set it into the line style together with all the properties, that way you won’t have to use any package on dynamo.

2 Likes

Any element in Revit can be deleted. You just need the ElementId of the object.

Document.Delete(ElementId)
1 Like

Thank you @jmark and @aaronrumple for your guidance.

I was able to create and delete line style in python

Create:

# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument

# The inputs to this node will be stored as a list in the IN variables
TransactionManager.Instance.EnsureInTransaction(doc)

# Place your code below this line
cat = doc.Settings.Categories
linecat =  cat.get_Item(BuiltInCategory.OST_Lines)  
lineStyle = cat.NewSubcategory(lineCat, "NewLine");
lineStyle.LineColor = new Color(255,0,255);
lineStyle.SetLineWeight(2, GraphicsStyleType.Projection);
# Assign your output to the OUT variable.
TransactionManager.Instance.TransactionTaskDone()
OUT = lineStyle