Line Styles in Filled Region

Hi All,

It’s been a while, following up this thread Filled Region Line Style . Has anyone successfully changed just one Line Style Inside filled region?

Code below from Plissken works great but it’s changing all linestyle inside filledregion. Any idea how to make it work for specified linestyle only?TIA

##Written By Thed Hogan

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPIUI')
from  Autodesk.Revit.UI import Selection , TaskDialog
Alert = TaskDialog
title = "Change Filled Region Line Style"

clr.AddReference('System')
from System import *

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1] 

#The inputs to this node will be stored as a list in the IN variables.
doc =  DocumentManager.Instance.CurrentDBDocument
app =  DocumentManager.Instance.CurrentUIApplication.Application
#These are my inputs for the Node
filledRegion = tolist(IN[0])
toggle = IN[1]
gStyle = tolist(IN[2])
views = tolist(UnwrapElement(IN[3]))

#Declared Variables
output = list()
startPoint = list()
endPoint = list()
existingLines = list()
profiles = list()
filledRegionCount = 0

for view in views:
	vid = view.Id
	collector = FilteredElementCollector(doc).WherePasses(ElementOwnerViewFilter(vid)).OfClass(CurveElement)

for element in filledRegion:
	filledRegionCount = filledRegionCount + 1
	notProfile = True
	idSub = 1
	while notProfile:
		if doc.GetElement(Autodesk.Revit.DB.ElementId(element.Id - idSub)).ToString() == "Autodesk.Revit.DB.Sketch":
			profiles.append(doc.GetElement(Autodesk.Revit.DB.ElementId(element.Id - idSub)))
			notProfile = False
		
		else:
			idSub = idSub + 1
			if idSub > 1000:
				notProfile = False
#Collect existing <sketch> lines in the view, the toggle can reset the collection
if toggle == True:
    for detailLine in collector:
        if detailLine.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM).AsValueString() == "<Sketch>":
        	startPoint.append(detailLine.GeometryCurve.GetEndPoint(0).ToString())
        	endPoint.append(detailLine.GeometryCurve.GetEndPoint(1).ToString())
        	existingLines.append(detailLine)

#Check each filled region
for i in range(0, filledRegionCount):
	#Set currentRegion:
	currentRegion = profiles[i].Profile.get_Item(0)
	changeRegion = False
	#Find the Curves of Each Filled Region, using start and end points of existing lines in the <sketch> Category of the current view
	#Compare the lines current linestyle to the given linestyle and determine if a change needs to happen
	for curve in currentRegion:
		if curve.GetEndPoint(0).ToString() in startPoint and curve.GetEndPoint(1).ToString() == endPoint[startPoint.index(curve.GetEndPoint(0).ToString())]:
			#The Method .get_Parameter() was depricated after Revit 2015
			try:
				if gStyle[0].Name != existingLines[startPoint.index(curve.GetEndPoint(0).ToString())].get_Parameter('Subcategory').AsValueString():
					changeRegion = True
			#If the above fails, it means this is is being run in Revit 2016 or later, so we will use .LookupParameter() instead, the try/except allows us to avoid having to perform a Revit version check for a relatively minor change
			except:
				if gStyle[0].Name.ToString() != existingLines[startPoint.index(curve.GetEndPoint(0).ToString())].LookupParameter('Subcategory').AsValueString():
					changeRegion = True
				
	#If one or more Lines in the border are not the same as the given linestyle, begin a transaction to change that filled region
	#This transaction must be nested inside of an if statement, to prevent it from running indefinitely and crashing the file while Dynamo is set to Automatic
	if changeRegion == True:
		TransactionManager.Instance.EnsureInTransaction(doc)
		UnwrapElement(filledRegion[i]).SetLineStyleId(ElementId(gStyle[0].Id))
		Alert.Show(title, "Filled Region(s) Line Style changed!")
	else:
		Alert.Show(title, "Failed!")
		TransactionManager.Instance.TransactionTaskDone()
	#Send back the list of Filled Regions
	output.append(filledRegion[i])

#Assign your output to the OUT variable.
OUT = detailLine

image

@Myr try this way;
Code provided below and the file is here Change_FillRegion_LineStyles.dyn (3.7 KB)

# dynamo version - 1.3.2
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

frtId = UnwrapElement(IN[0]).Id
lineId = UnwrapElement(IN[1]).Id
active_view = IN[2]

if active_view:
	elems = FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(FilledRegion)
else:
	elems = FilteredElementCollector(doc).OfClass(FilledRegion)

res = []

TransactionManager.Instance.EnsureInTransaction(doc)

for i in elems:
		if frtId == i.GetTypeId():
			i.SetLineStyleId(lineId)
			res.append(i)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = res
1 Like

Hi Jean,

Thanks for this, but is it possible to change only the selected linestyle and not all of them? for example change only the type of the green thick line in above example?

Thanks Jean i just reused this code :slight_smile: