Your Python code indicates that you’re more inclined towards Imperative Programming (IP) than Functional (FP). Dynamo tends to prefer the FP approach, actually in this case even Python would be more optimal going with the FP approach. E.g.
The Python being:
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variable.
strList = IN
strSearch = IN
def ReplaceIfNotFound (s):
if strSearch in s:
return s + strSearch
#Assign your output to the OUT variable
OUT = map(ReplaceIfNotFound, strList)
The reason the ReplaceByCondition (and for that matter a List.Map) doesn’t work is something I regard as a bug in Dynamo. The trouble is you generate a “function” to send to the mapping node. This function consists of many nodes taking inputs and calculating a result from those. Now Dynamo builds this function by checking which nodes have empty inputs, those it then deems as the parameters the function requires. So if it sees 2 empty inputs it “knows” the map function needs 2 lists of inputs.
If this wasn’t buggy in current dynamo 8 this one should have worked:
See … 3 empty inputs and 3 lists of inputs. But as you can see it simply doesn’t --> bug.
Another alternative would be to gather one input and reuse it numerous times like this:
Again, there’s an issue, in this case the Formula node changes the type of the input to something other than a String (??? WTF ???). And a Code Block simply results in null objects, same with Object.Identity. I’m not certain of any other means to gather such inputs.
However, there is “one” way to “force” Dynamo to understand that your “function” only requires the one input value even though it may be using it numerous times over. That is to make your function in a custom node:
Which then works as expected:
Strange to have to jump through such hoops to get even just this one simple thing working. I’ve even tried making a custom node which just passes the input as the output so I can collect the List.Map’s function parameter and reuse it many times inside the function. But that also produces null results as Code Blocks and Object.Identity does. This is why I think it’s a bug in Dynamo, at least for now.