Revit '22 Script No Longer Working? (Filled Region Lines)

All of a sudden, a script I’ve been using in R22 no longer works in R22. However, it still works in older versions. The script runs without errors, but nothing happens (filled regions show null). What needs to change?

Script:

Continuing the discussion from Set ALL Filled Regions to Invisible Lines:

The node says your filled region input is null. Can you confirm that? Are you sure you have filled regions in your active view?

Yes, I do. It lists all of them, but the node shows up null for some reason.

Can you show a screenshot with all the node preview bubbles pinned instead of just the last node? Can you also post either a screenshot or a formatted copy of the code from the python nodes inside the custom node?

Well now, it’s actually showing correctly, but still, nothing happens:

##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('System')
from System import *

#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 = IN[0]
toggle = IN[1]
gStyle = IN[2]

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

collector = FilteredElementCollector(doc).WherePasses(ElementOwnerViewFilter(doc.ActiveView.Id)).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))
		TransactionManager.Instance.TransactionTaskDone()
	#Send back the list of Filled Regions
	output.append(filledRegion[i])

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

If it matters, it’s IronPython2.

Now it looks like you’re using a different node. What happened to the old one? Is the new node just the python you shared? Can you copy the python node to your graph and use that instead? It should then give you any errors that might be occurring, although it looks like there should be none.

Sorry, forgot I edited without saving in case I messed anything up. Here is the original node error:

# Enable Python support and load DesignScript library
import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument

#The inputs to this node will be stored as a list in the IN variable.
filled_regions = IN[0]
line_style = IN[1]


def function(filled_region, line_style):
	filled_region.SetLineStyleId(line_style.Id)
	
	return filled_region


output = None


TransactionManager.Instance.EnsureInTransaction(doc)

if isinstance(filled_regions, list):
	output = [function(
		UnwrapElement(a), UnwrapElement(line_style)) for a in filled_regions]
else:
	output = function(
		UnwrapElement(filled_regions), UnwrapElement(line_style))

TransactionManager.Instance.TransactionTaskDone()

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

Your function is trying to get the Id of the line style object but you’re providing a list currently. Just convert your input from a list to a single item.

And the node I showed with a bool input runs without error. Nothing happens using either node.

Are you saying to delete the ,list from isinstance? That didn’t seem to fix it.

Or changing the IN inputs list?

It’s really confusing trying to follow both graphs at the same time. Let’s just focus on the original node for now.

Based on this screenshot, your line style is in a list. The python node is expecting a single item , which is why you get the error ‘List[object]’ has no attribute ‘Id’.
image
You need to provide a singleton with no list structure. Easiest way is to just get the item from your list.

2 Likes

Well, that worked! Sorry for confusion. I was editing all over the place troubleshooting and didn’t realize I posted another node.

That fixed it! No idea why this worked in '21 without editing and not '22.

Thanks!