hi everyone I want to open a topic that I haven’t seen much on the forum; in fact i tried to find a way to create a cut pattern with dynamo. First of all i tried manually in revit and the file that i have works perfectly:
In this case, I just created a new material and after verifying that the file.PAT works i just tried to do the same thing in Dynamo. I couldn’t find a node that created that type of pattern but only one that set this pattern by the Orchid packages:
So i tried to create a python script:
(I have written the script in the note below)
but this is the error that the Python script gave me:
[
Error creating pattern: fillPattern does not have a valid Target.
Parameter name: fillPattern
at Autodesk.Revit.DB.FillPatternElement.Create(Document document, FillPattern fillPattern)
]
this is the complete node:
in the end i just want to know if there are some packages that can create the pattern or if someone can help me with the code because i don’t have a lot of skills with coding.
Btw i thought that this conversation could be very usefull because i didnt found anythging about this content in the forum.
Best regards, Samuel
Python script:
import sys
import clr
import os
# Import required references
clr.AddReference("RevitServices")
clr.AddReference("RevitAPI")
clr.AddReference("RevitNodes")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.DB import *
# Get the active Revit document
doc = DocumentManager.Instance.CurrentDBDocument
# Convert the input (File Path node) to a string
pat_file_path = str(IN[0])
# Function to read the .PAT file in the specified format
def read_pat_file(file_path):
pattern_data = {}
try:
with open(file_path, "r") as file:
# Read all lines and strip whitespace, ignoring empty lines
lines = [line.strip() for line in file if line.strip()]
# The first line is the pattern name
if lines:
pattern_data["name"] = lines[0]
# The remaining lines are the pattern definitions
pattern_data["lines"] = lines[1:]
else:
return None
except Exception as e:
return "Error reading file: {}".format(str(e))
return pattern_data
# Function to create a cut background pattern in Revit
def create_cut_background_pattern(doc, pattern_data):
try:
pattern_name = pattern_data["name"]
# To create a cut background pattern we use FillPatternTarget.Model
fill_pattern = FillPattern(pattern_name, FillPatternTarget.Model)
# Start a transaction to create the element
TransactionManager.Instance.EnsureInTransaction(doc)
fill_pattern_element = FillPatternElement.Create(doc, fill_pattern)
TransactionManager.Instance.TransactionTaskDone()
return "Cut background pattern '{}' created successfully!".format(pattern_name)
except Exception as e:
return "Error creating pattern: {}".format(str(e))
# Read the .PAT file
pattern_data = read_pat_file(pat_file_path)
# Check that the data is valid and create the pattern
if isinstance(pattern_data, dict) and "name" in pattern_data:
result = create_cut_background_pattern(doc, pattern_data)
else:
result = "Invalid pattern data or empty .PAT file."
# Output the result from the Dynamo node
OUT = result
There aren’t any specific nodes since you don’t need any specific nodes to create hatch patterns. They’re just a formatted string in the PAT file, so you can create new patterns just by modifying the PAT directly, just like you’re doing.
The following line in your code doesn’t look like it uses a valid method:
fill_pattern = FillPattern(pattern_name, FillPatternTarget.Model)
FillPattern Members