Overwrite Filled Region Pattern

Hi,

Hoping someone can help, apologies for my terrible python…

I am trying to set graphic overrides in a view just for patterns, I am trying to do this through python, I have got it working, but only for a single element, could someone point out my mistake? Big thanks to Konrad @ Archi-Lab for the original code…

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 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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

def ProcessList(_func, _list):
return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )

def Unwrap(e):
return UnwrapElement(e)

def OverrideColorPattern(e, f):
gSettings = OverrideGraphicSettings()
gSettings.SetProjectionFillPatternId(f)
doc.ActiveView.SetElementOverrides(e.Id, gSettings)
return e

elements = ProcessList(Unwrap, IN[0])

fillPat = UnwrapElement(IN[1])

try:
errorReport = None
TransactionManager.Instance.EnsureInTransaction(doc)

test = []
for i in elements:
test.append(OverrideColorPattern(i, fillPat))

TransactionManager.Instance.TransactionTaskDone()
except:
# if error accurs anywhere in the process catch it
import traceback
errorReport = traceback.format_exc()

#Assign your output to the OUT variable
if errorReport == None:
OUT = test
else:
OUT = errorReport

You need to indent this line (with Tab)

Thanks Alban, I’ll have a go and let you know!

EDIT: That’s odd, my formatting didn’t copy and lost all the indents!

Hi Mark,

I edited your script :

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 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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

def ProcessList(_func, _list):
	return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )

def Unwrap(e):
	return UnwrapElement(e)

def OverrideColorPattern(e, f):
	gSettings = OverrideGraphicSettings()
	gSettings.SetProjectionFillPatternId(f)
	doc.ActiveView.SetElementOverrides(e.Id, gSettings)
	return e

if isinstance(IN[1], list):
	elements = ProcessList(Unwrap, IN[0])
else:
	elements = list(Unwrap(IN[0]))


fillPat = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)

test = []
for i in elements:
	test.append(OverrideColorPattern(i, fillPat.Id))

TransactionManager.Instance.TransactionTaskDone()

OUT = test

Fil%20pattern%20override

1 Like

Thanks Alban,

Apologies but I didn’t explain myself very well…

What I should have said is… Say I have a list of 4 filled regions, I want to feed in a list of 4 different hatches.

Currently the script only works with a single hatch input.

Thank you for your time,

Mark

Why don’t you use a custom node and levels ?

Override FillPattern.dyf (4.2 KB)

1 Like

Thanks Alban, that works great!