If condition fails

Hi all I am trying to use if condition in python and get the result. But it is failing to give the required result.
image

my IN[0] is elements and IN[1] true or false

the code is as below:

import clr

import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')

import System
from System.Collections.Generic import *

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

#Preparing input from dynamo to revit
element = UnwrapElement(IN[0])

#Do some action in a Transaction

TransactionManager.Instance.EnsureInTransaction(doc)
if IN[1] == "False":
	OUT = element

else:
	OUT = []

TransactionManager.Instance.TransactionTaskDone()

It should give me out put as elements what I fed the list of elements based on the condition. But it is always giving me the empty list only.

Please let me know where I am missing

@shashank.baganeACM ,

OUT = []

for i in element:
    if i == "False":
	OUT.append(i)

else:
	OUT.append("no element")

try this in your code

1 Like

Are you feeding a boolean or a string? Either way, they don’t match. I’m guessing you have a boolean, which would just be False in Python. Right now you’re checking for a string.

1 Like

Thanks @Nick_Boyts It worked for me. I was feeding the boolen and I have changed it to False.

Thanks @Draxl_Andreas for your response.