Using Code Blocks with Lists

I’m really hoping I didn’t imagine this:
I have used a code block to simply access parts of a list along with the Get.ItemAtIndex node…
Somehow I managed to ‘label’ each index number with the name of the list item being targeted.
Somewhere along the line I wound up deleting what I had done and now I’m struggling to replicate.
This is a mock-up of what I can remember using GIMP:
CodeBlock

I know I could just use a note, but this would be so much neater.
If anyone has ever done this before, would you be kind enough to point me in the right direction…?
Many Thanks

Using Dynamo 2.16.1

Would it be this?

ProjectNum = 0;
ProjNam = 1;
Workstage = 2;
BuildingName = 3;
1 Like

@DoubleG ,

or this

grafik

KR

Andreas

1 Like

Thanks Mike,
That works, the node doesn’t quite look the same at the end, but that doesn’t matter, it still works.
Thanks again

Thanx Draxl_Andreas,
This also works, doesn’t look like I remembered, but it still does the job.

Thank you for your help.

I think you’re thinking of dictionaries.

dictionary = {"ProjectNum":0, "ProjNam":1, "Workstage":2,"BuildingName":3};

You then access the data by requesting content via the key instead of the index.

projNum = dictionary["ProjectNum"];

1 Like

Thanks Jacob,
My skill level in Dynamo wouldn’t allow me to type that, even by accident.
I consider myself as a beginner/intermediate user of dynamo.
But now I have something to aim for. :nerd_face:

do not hesitate to consult this nugget of information

cordially
christian.stan

1 Like

Wow, Thanks.
That looks super useful

1 Like

You can utilize the default constructor instead of hard coding it as well.

Dictionary.ByKeysValues is the node name, place it, wire the keys (strings you want to use) and values (data you want associated to them). Then select the nodes, right click the workspace background, and select Node To Code to get started.

1 Like

I guess you want to add comments directly to each line, like this:
image

2 Likes

Are you talking about this?

Hi pyXam,
Thanks for your reply, but the result I had from my accidental typing looked just like the image I posted yesterday.
Anyway, I think I have used up too much time of the very kind people on this forum trying to recreate a happy accident, so I’ll use some of the very good suggestions I’ve already received on here.

1 Like