Can you use a code block as a List.Map function?

I’m passing a list of custom objects from a ZTN into List.Map. I think I should be able to write a code block that returns an attribute from each of the objects in the list, like this:
But no matter what I try, I just get an error that my code block is dereferencing a non-pointer. Which is not true – I have no null items in my list. So is there no way to do this?


What Dynamo version are you using? List levels would probably be easier.

1 Like

This 100x over.

you can - you need to use FunctionObject constructor…


It’s Dynamo 2. I’ll look into list levels. Thanks!

(btw, I really appreciate how quickly you guys respond to these noob questions)

So it turned out that I solved my problem by not even trying to access each element in the list. I passed the list into a code block node that was just this:
program ? program.Quantity : null

And then passed the output of that code block into the next node, and voila! Somehow, Dynamo realized that the code block was receiving a list of programs, applied the code block to each element in the list, and output a list of Quantitys to the next node. And the next node (not pictured in this thread) knew to apply itself to every element of the incoming list, even though it also was showing it expected a single item input, rather than a list of that item. That is some interesting “yeah, I can tell what you mean to do even though your inputs and outputs are lists instead of single items” stuff.

Dynamo uses a kind of “internal” lacing (now Auto in 2.X). It’s usually smart enough to determine the kind of input it’s receiving and how it needs to be handled.

A node with an “item” input that receives a list knows to iterate through each item individually.
A node with a “list” input may need some additional information to know how to handle a list of lists.
A node with multiple inputs will need additional information to know how to handle mismatched input types.

These situations all get handled by lacing or list levels.