No Input Value custom Node

Hi,

I was wondering if it’s possible with a custom node with more input options and one is left open the node is still working. For example in the picture shown below when there is no input from the pattern.

I added Pattern : string = null; to the pattern input node but that isn’t working.

Anyone ideas?

Thanks

You still need to make sure your Python node will work with a null value. Does it work if your input is set to null?

No it doesn’t work with null. This is the Pyhton code:

import clr 

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

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

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

doc = DocumentManager.Instance.CurrentDBDocument

namel = IN[3]
patterns = FilteredElementCollector(doc).OfClass(LinePatternElement).ToElements()

fillPatSelected = list()
for i in range(len(patterns)):
    namepick = patterns[i].ToDSType(True)
    if namepick.Name == namel:
        fillPatSelected.append(patterns[i])
     
def ConvertColor(element):
	return Autodesk.Revit.DB.Color(element.Red, element.Green, element.Blue)
	
def OverrideElement(element, weight, color, fill, halftone):
 ogs = OverrideGraphicSettings()
 ogs.SetCutLineWeight(weight)
 ogs.SetCutLineColor(color)
 ogs.SetCutLinePatternId(fill.Id)
 ogs.SetHalftone(halftone)
 doc.ActiveView.SetElementOverrides(element.Id, ogs)

elements = UnwrapElement(IN[0])
weight = UnwrapElement(IN[1])
colors = ConvertColor(IN[2])
half = IN[4]

for i in elements:
    TransactionManager.Instance.EnsureInTransaction(doc)
    OverrideElement(i, weight, colors, fillPatSelected[0], half)
    TransactionManager.Instance.TransactionTaskDone()

You can’t apply a null value as your pattern override. I don’t know if the None pattern is available in the API so I would suggest removing fill from your OverrideElement definition. Then you can override the pattern separately if you have a matching pattern name or skip it if you find no matches.

1 Like

I can’t find anything that looks like a None pattern in the API. So i have to make a work arround :frowning:

Thanks for helping

I couldn’t find anything when I checked a while back either. You’re best option is probably to separate the pattern override function.

You could use the try / except as your workaround, that way there is very little change needed and only this small addition to the last few lines would give you a output (e.g null) if no input is present :slight_smile:

Okey

Never made a code with a try / except

I’ve seen it in some codes but don’t know how to add that to this code :flushed:

The “try” and “except” is more or less a “attempt to do this, if you fail do return this instead”, so that you are sure to get a output and not a failing node. implementing it on your code would look something like this:

import clr 

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

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

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

doc = DocumentManager.Instance.CurrentDBDocument

namel = IN[3]
patterns = FilteredElementCollector(doc).OfClass(LinePatternElement).ToElements()
try:
	fillPatSelected = list()
	for i in range(len(patterns)):
		namepick = patterns[i].ToDSType(True)
		if namepick.Name == namel:
			fillPatSelected.append(patterns[i])
		
	def ConvertColor(element):
		return Autodesk.Revit.DB.Color(element.Red, element.Green, element.Blue)
		
	def OverrideElement(element, weight, color, fill, halftone):
	ogs = OverrideGraphicSettings()
	ogs.SetCutLineWeight(weight)
	ogs.SetCutLineColor(color)
	ogs.SetCutLinePatternId(fill.Id)
	ogs.SetHalftone(halftone)
	doc.ActiveView.SetElementOverrides(element.Id, ogs)

	elements = UnwrapElement(IN[0])
	weight = UnwrapElement(IN[1])
	colors = ConvertColor(IN[2])
	half = IN[4]

	for i in elements:
		TransactionManager.Instance.EnsureInTransaction(doc)
		OverrideElement(i, weight, colors, fillPatSelected[0], half)
		TransactionManager.Instance.TransactionTaskDone()
except:
	OUT = Null

My assumption was that if a pattern is not provided the other overrides still need to be applied.
In that case you would remove the fill line from the OverrideElement definition and move it under the if namepick.Name == namel: line. That way if you find a match pattern it gets overriden and if you don’t… everything else still runs.

You could also run each override separately within its own if statement to allow for any number of the inputs to be null and still override the ones given.

1 Like

I tried this one but the code doesn’t do anything anymore :frowning:

So i will try Nick’s sollution

fillPatSelected = list()
	for i in range(len(patterns)):
		namepick = patterns[i].ToDSType(True)
		if namepick.Name == namel:
			fillPatSelected.append(patterns[i])
            SetCutLinePatternId(patterns[i])
		
	def ConvertColor(element):
		return Autodesk.Revit.DB.Color(element.Red, element.Green, element.Blue)
		
	def OverrideElement(element, weight, color, halftone):
	ogs = OverrideGraphicSettings()
	ogs.SetCutLineWeight(weight)
	ogs.SetCutLineColor(color)
	ogs.SetHalftone(halftone)
	doc.ActiveView.SetElementOverrides(element.Id, ogs)

I only have copied the part Nick said. But is that what you mean?

You would have to define ogs outside of your function so that you can use ogs.SetCutLinePatternId under your if statement, but that’s basically the idea, yes.

1 Like

I will give it a try tomorrow