This is just a guess, because I can’t see the lists you are feeding it, but I suspect there is some kind of a mismatch between the number of elements in each list you are feeding it.
“Open Instance” is a list of elements (I’m guessing)? “doesNameExist” is a matching list with a true/false for each element in the list “OpenInstance”?
However, “listContainsTrue” is a list with a single element: Either true or False. So when this code attempts to iterate through the lists, you only get one shot at the first part of the IF statement.
Instead, your “IF” test should check whether the value for each entry in the “doesNameExist” is True or False, and then operate on the corresponding element from the “OpenInstance” list. This may be easier to do as a separate function, something like the attached image (see the end of this post).
Actually, it seems like you could do a lot of this right in your code block, instead of generating a bunch of lists outside the code block and attempting to pass them in.
Many of the parameters that you are passing in as lists: Element Type, Element Type Name, Opening diameter, could all be gotten on the fly within the loop, with less list management.
Also, your checks and generation of new data could be done right within the loops. For example, your test of “does the type already exist”: that is, if “currentType” is a list that matches each element in the “OpenInstance” list, and “allRndTypes” is the list you are searching through.
Though, the more I think about it- if you are adding a new Type for each size that doesn’t exist, you probably want to update the list of existing types after each iteration of the loop, since you may have more than one opening of a size that doesn’t have a type yet? Something like this: “OpenInstance” is a list of opening elements.
OpenInstance;
[Imperative]
{
for (opening in OpenInstance)
//(Do whatever you did outside of here to generate the allRndTypes list)
allRndTypes = {};
currentType = Element.Type(Opening);
currentTypeName = Element.GetParameterValueByName(opening,"Type");
if(List.ContainsItem(currentTypeName, allRndTypes))
{
// It's not clear to me why you need to do anything if the current type already
// exists, but here's where you'd do it anyway
}
elseif (!List.ContainsItem(currentTypeName, allRndTypes))
{
//(Do whatever you did outside of here to generate the newTypeName)
newOpenType = ElementTypes.Duplicate(currentType,newTypeName);
// Whatever else you're doing
Elements.View.SetParameterByName(opening,"Type",newOpenTypeFinal);
}
else
{
return = "error";
}
}
}
good luck!
Joe