Create a custom Line Style and apply to Detail line

I’m getting errors while trying to developing a custom line style with the following attributes:

Help

Can you share a screenshot of your full graph, with all node preview bubbles pinned? Make sure you’re zoomed in so everything is visible (like node titles) and use the Export as Image option.

Hi @Nick_Boyts . Thank you for responding. My attachments are restricted. I shared dynamo file in link above and attaching image below.

@Nick_Boyts I tried to attach. Hope it will help.
I want to make it work only by using Dynamo and Py (if required, because py is default built in) and do not want to use external tools or add-ins.

Could you copy the python code as preformatted text (</> in the formatting toolbar) and include the error message so we have a better view of what you’re doing? It might also be helpful to return each of the properties you’re getting in python as a check, rather than getting everything and then trying to set them. That would help show us what’s working and what’s not.

import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

# Inputs
style_name = IN[0]           # e.g. "Thin Lines"
line_weight = IN[1]          # e.g. 5
line_pattern_name = IN[2]    # e.g. "Dash"
color_name = IN[3]           # e.g. "Red"
detail_curve = IN[4]         # DetailCurve element

doc = DocumentManager.Instance.CurrentDBDocument

# Color name to RGB map
color_map = {
    "Black": [0, 0, 0],
    "White": [255, 255, 255],
    "Red": [255, 0, 0],
    "Green": [0, 255, 0],
    "Blue": [0, 0, 255],
    "Yellow": [255, 255, 0],
    "Cyan": [0, 255, 255],
    "Magenta": [255, 0, 255],
    "Orange": [255, 165, 0],
    "Purple": [128, 0, 128],
    "Brown": [165, 42, 42],
    "Gray": [128, 128, 128],
    "Light Gray": [211, 211, 211],
    "Dark Gray": [64, 64, 64],
    "Pink": [255, 192, 203],
    "Lime": [191, 255, 0],
    "Teal": [0, 128, 128],
    "Navy": [0, 0, 128],
    "Gold": [255, 215, 0],
    "Silver": [192, 192, 192]
}

def get_graphics_style(name):
    styles = FilteredElementCollector(doc).OfClass(GraphicsStyle)
    for s in styles:
        if s.GraphicsStyleType == GraphicsStyleType.Detail and s.Name == name:
            return s
    return None

def get_line_pattern(name):
    patterns = FilteredElementCollector(doc).OfClass(LinePatternElement)
    for p in patterns:
        if p.Name == name:
            return p
    return None

TransactionManager.Instance.EnsureInTransaction(doc)

graphics_style = get_graphics_style(style_name)
line_pattern = get_line_pattern(line_pattern_name)
rgb = color_map.get(color_name, [0, 0, 0])  # Default to black if not found

if graphics_style and detail_curve:
    try:
        cat = graphics_style.GraphicsStyleCategory
        cat.SetLineWeight(line_weight, GraphicsStyleType.Detail)
        if line_pattern:
            cat.SetLinePatternId(line_pattern.Id, GraphicsStyleType.Detail)
        cat.LineColor = Color(rgb[0], rgb[1], rgb[2])
        detail_curve.LineStyle = graphics_style
        OUT = detail_curve
    except Exception as e:
        OUT = "Error: " + str(e)
else:
    OUT = "Style or pattern not found"

TransactionManager.Instance.TransactionTaskDone()

I want to create a ‘Line Style’ and apply to annotation line created using DetailCurve.ByCurve node. Please suggest me

The error you’re getting is very important. Again, I’d suggest you just focus on getting the properties first, as I think that’s where your issue lies.

Detail is not a GraphicStyleType. Line styles are not specific to detail or model lines so you can get rid of the condition all together.

1 Like

Hi @khajaafroz.jamal, did the post from @Nick_Boyts help you solve this issue?

I’m looking for method that does close to the same thing as what your post is about.