I am trying to create a Python Node for deleting Filled Regions with a given name. I keep getting the error shown in the image.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Analysis import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
regions = UnwrapElement(IN[0])
strUnwantedNames = IN[1]
#inView = FilteredElementCollector(doc, view.Id).OfClass(FilledRegion)
unwantedRegionList = []
for region in regions:
for name in strUnwantedNames:
if region.Name() = name:
unwantedRegionList.append(region)
try:
doc.Delete(region.Id)
except:
pass
#Assign your output to the OUT variable
OUT = unwantedRegionList
an if statement requires ==
so your line should run like:
if region.Name == name:
Hi @Ben_Veasey ,
this might not be the only issue, but the exception reffers to this line :
if region.Name() = name:
change it to :
if region.Name() == name:
Ah, excellent responses. Thanks.
I am getting a new error shown in the image…
WIP View Filters-Legend From Selection OP.dyn (20.3 KB)
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Analysis import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
regions = UnwrapElement(IN[0])
unwantedNames = IN[1]
#inView = FilteredElementCollector(doc, view.Id).OfClass(FilledRegion)
unwanted = []
for i in unwantedNames:
unwanted.append(i)
unwantedRegionList = []
for region in regions:
for name in unwanted:
if region.Name() == name:
unwantedRegionList.append(region)
try:
doc.Delete(region.Id)
except:
pass
#Assign your output to the OUT variable
OUT = unwantedRegionList
Name is a property not a method, so you don’t need the “()” .
Just replace :
if region.Name() == name:
with :
if region.Name == name:
about the accepted solution.
my reply was the exact solution.
maybe have a closer look at solutions
You are right…I would love to have ticked both as the Solution. Mostafa’s statement "Name is a property not a method, so you don’t need the “()” " was extremely helpful to me too…