In Revit, I have a script I use to change the line type of all filled regions to Invisible Line, using the Plissken package.
It worked perfectly for projects in Revit 2021 but in Revit 2022, it seems to break no matter what I change the input values to. Is there another package that will fix this (or another solution)? I am relatively new to Dynamo and need this to work for all versions of Revit.
Removing the space is the first step, but the input name also canât be a class name. You need to change it to something else like FilledRegion, filledRegions, or Filled_Regions for example.
Whenever I try FilledRegion, it gives me the same error. filledRegion, filledRegions and Filled_Regions no longer produce an error, but nothing happens to the filled region bordersâŚ
Thatâs because these changes were made in R22. It removes confusion and saves class names specifically for classes. FilledRegion is still a class. Thatâs my fault.
Can you show us what your graph is doing now that the inputs are working?
Copy the contents of the custom node and use that in your graph instead. That way it shows the errors or warnings that youâre getting. And make sure you have all the node preview bubbles pinned so we can see the data as well.
Side note, I tried to âSave Asâ the edited custom node to keep it separate (as to not mess up my R21 one), but it inserts the edited one into both. Hopefully it applies to both versions once fixedâŚ
Correct. Instead of feeding your data into the custom node where the internal warnings wonât show, we can pull out the âgutsâ of the node and run everything in the main graph so that all the warnings are visible.
Assuming Iâve set this up right, I get no errors, but nothing happens⌠Still works for older versions when changing to FilledRegions (2020) and Filled Regions (2021). R22 just yields nothingâŚ
The â==â node wonât compare elements like that. Itâs fine for strings, integers, etc, but with elements itâll just return everything as false. You can either turn the element into something that â==â can compare, e.g. use String.FromObject or get the element IDs, or you can use a different comparison node, such as List.Equals with the inputs set to L1@. Though this has been the case in older versions of Revit/Dynamo too, so Iâm not sure how you got a result out of 2020 and 2021.
My bad, I thought the == node was comparing the two FilledRegion lists but itâs actually just checking for nulls. The Element.Id node isnât actually necessary in that case, but it doesnât hurt either.
Can you post the python code for us to look at? Please be sure to use the Preformatted Text option (</>) when sharing code.
##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