Select Model Elements as Optional User Input

My script includes a Select Model Elements node that does not need to have a value for the script to work. Using it depends on the use case.

When trying to use it with the Dynamo Player, the Run button is only unlocked after the user has selected the elements.

How can I make this input optional, so that the script can be run without the model element selection?

Hi!

I think you should look into data-shapes :slight_smile: It provides a user friendly interface where you can handle optional inputs better

1 Like

Unfortunately I cant rely on that package for this project. Is there a way to flag a user input as optional in native dynamo? Or some workaround?

Ah thats too bad!

perhaps springNodes can help?

This node gathers the current selection. you could instruct the user to select elements before pressing play, and if they select nothing before running, the script will just have an empty list in the selection output

If you cant use that package, you could use the raw python, made by @Dimitar_Venkov code inside of the custom node:

#Copyright(c) 2016, Dimitar Venkov
# @5devene, dimitar.ven@gmail.com

import clr

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

def output1(l1):
	if len(l1) == 1: return l1[0]
	else: return l1

selid = uidoc.Selection.GetElementIds()
OUT = output1([doc.GetElement(id).ToDSType(True) for id in selid])

Thank you for the suggestions!
Still, none of those work for me as they only work if you open the script itself, not with the Dynamo Player.

My last suggestion works with dynamo player, doesn’t it?

see:

1 Like

test
Have you made sure your “Select Model Elements” node is selected to be “Is Input”

Yes, its flagged as “Is Input” and therefore it appears in the Dynamo Script. What I need is the option to run the script without selecting any element

I see. However my script also has other fields where the user needs to select elements which are not optional, and having this exception of selecting them before hitting run is very confusing.

I really dont understand how Dynamo does not have an “Optional” flag to inputs.

perhaps you could make the user select a random element that you never use, like a detail line or something. You could then filter out the element and proceed as if nothing was selected.

I dont think you can do this any other way besides what ive suggested before

1 Like

Not sure I understand the concept with having the selection function optional within the same script. You will get a run failure message if the selection isn’t made, which defeats knowing if the script ran completely or not, without actually investigating to see if the changes were made in the model. Maybe break the script up into two, one with selection and one without.

If you want to have optional situations, you will probably need to modify the code that @MVE1112 clipped above and write it in or create your own custom node.

More information would be helpful. What is your scenario for selecting or not selecting an element? What happens when an element is selected vs not?

I’m not aware of any way to provide an optional input. You could however provide a toggle to include or not include the selected element. You would of course still need to make a valid selection, but you could ignore it in the graph logic.

Here is a couple pieces of customized code courtesy of @john_pierson. The first has the popup asking the user to select “Yes” if they want to make a selection or “No” to bypass the selection. If yes is selected then true is passed and fires off the Pick Single Element code block and the selected element is returned. If no is selected then the Pick Single Element code block returns “No Selection Made”. In either case, no error is given.

image

Yes-No Popup with User Selection.dyn (6.4 KB)

2 Likes