Export Line Pattern or create Line Pattern

Hello pyRevit friends :slight_smile:

I want to add fill patterns and line patterns to a project.
It seems that they can´t be created with the revit API…

So I exported the fill patterns with the pyRevit “make pattern” tool. But how can I export line patterns?

Appreciate any advice! :slight_smile:

they can be created

Line patterns constructor class

a snippet

from pyrevit.framework import List
from pyrevit import DB, revit

doc = revit.doc

#Create list of segments which define the line pattern
lstSegments = List[DB.LinePatternSegment]()
lstSegments.Add(DB.LinePatternSegment(DB.LinePatternSegmentType.Dot, 0.0))
lstSegments.Add(DB.LinePatternSegment(DB.LinePatternSegmentType.Space, 0.02))
lstSegments.Add(DB.LinePatternSegment(DB.LinePatternSegmentType.Dash, 0.03))
lstSegments.Add(DB.LinePatternSegment(DB.LinePatternSegmentType.Space, 0.02))

linePattern = DB.LinePattern('Name of the pattern')

#Create a linepattern element
with revit.Transaction('Create line pattern'):
    linePatternElement = DB.LinePatternElement.Create(doc, linePattern)

look here for FillPattern Constructor class

1 Like

Uh, nice, much better for my use case than having to export import!

Thanks a lot @Jean-Marc :slight_smile:

1 Like

While creating a fill pattern was easy, I´m now struggling to get the fill pattern id. :confused:
I need the Id to use this pattern for graphic overrides for view filters. A fill pattern has no Id, only a fill pattern element has an Id. So what do I have to do?

def create_fill_pattern():
    pattern = FillPattern("_later blocks", FillPatternTarget.Drafting, FillPatternHostOrientation.ToView, 45, 0.003)
    return pattern

Need the Id for this method:

You should be able to get going looking at the code from the repo
From the fillpattern, you need to create a fillpattern element

1 Like

There is also a thorough explanation Revit API : FilledRegion – TwentyTwo

Watch out though, this part of the api changed a bit, be on the lookout for the version of Revit you are running it against

1 Like

Got it :slight_smile: Thanks again!

def create_fill_pattern():

    pattern_name = "_later blocks"
    t = Transaction(doc, 'Create Fill Pattern')
    pattern = FillPattern(pattern_name, FillPatternTarget.Drafting, FillPatternHostOrientation.ToView, 45, 0.003)
    pattern_element = FillPatternElement.Create(doc, pattern)
    return pattern_element.Id
1 Like