I could simplify and control the graph I am working on a lot better if I knew a little python. I need to write a boolean, and I can write exactly what I need in Revit syntax. Here is how it would look if it were a Revit Family Formula:
IF(OR(FloorPlan, CeilingPlan, Areaplan, 1<2, IF(OR(Elevation, Section, 2<1, 2<1))
So basically, if input is Floorplan, Celingplan, or Areaplan, True; if input is Elevation or Section, False, if none, False.
What I really need in python is the same, except for my first boolean result I need a specific list of indices (0, 1, 9) and for my second boolean result a different list of indices (9, 19). For the third boolean result, I dont know, probably null. I know this is super basic but Im a super noob to python. Plz send help
Assuming your input is a string (text), then the below statement would work. You have some redundancy in your statement as you’re yielding false under the condition that nothing or an elevation/section is provided, so you could just check for the things that yield true, and return false otherwise.
Python is a bit different to how Revit manages if statements, but this should work for an input into a Python node as a string. I’ve added some redundancy to make the control flow logic a bit clearer. You wouldn’t have to technically pass the input/result variables if you went completely efficiently (you could just reference IN[0] each time, and OUT for the true/false outcome.
input = IN[0]
if input == "FloorPlan" or input == "Ceilingplan" or input == "Areaplan":
result = True
else:
result = False
OUT = result
I’d suggest trying out my series here on Python, and don’t rush:
This part deals with If statements specifically:
2 Likes
In addition to previous reply, you’d use an elif: statement as well so you could test for items that arent views to return a null result.
You would also have to wrap it all up in a for statement assuming you are passing in a list of items.
input = IN[0]
results = []
for i in input:
if i == "FloorPlan" or i == "Ceilingplan" or i == "Areaplan":
result = True
elif i == "Section" or i == "Elevation":
result = False
else:
result = ""
results.append(result)
OUT = results
2 Likes
Even shorter
items = {"Item1","Item2","Item3"}
input = IN[0]
OUT = input in items
3 Likes
Thanks Gavin, Ive really been meaning to get through your python for Dynamo series Maybe this is the kick in the ass I needed to finally buckle down on it. Feel like Ive been stuck in hello world for an eternity
1 Like
No worries - I’m still moreorless sitting at hello world for C# so I know the feeling. Any queries feel free to drop a comment on the videos
1 Like