Assign a number to items in a list with same value

Hi everyone,

Using node “SharedParameters.Info” I have a list of items that indicates the shared parameters groups of shared parameters in a project. So I have a list of 435 items, namely 435 shared parameters. With node “List.UniqueItems” I found 16 unique shared parameters groups.
I would like to assign a number from 1 to 16 to each group and then list the 435 shared parameters with the corrisponding numer. So, for example, SP group named “PG_STRUCTURAL” corresponds to 1, “PG_IDENTITY_DATA” corresponds to 2, etc.
I really don’t know how to tackle this problem, as my knowledge of dynamo is pretty basic and I didn’t find anything on the forum to solve this.

Thanks in advance!

What is you goal with this?

Was about to say this :point_down:. Francois beat me to it.

Hi @samuele.fuda
Did you try List.GroupByKey ?

1 Like

The general goal of this script is to create the shared parameters file from a rvt file of which I don’t have the SP .txt file. In the SP file for each parameter is indicated the SP group, which is represented by a progressive number.

1 Like

I have tried it but the two list have a different number of items, so it doesn’t work. Plus, if I am not wrong, this node would group the items by entry and I want to mantain the number of items in the original list of shared parameters, just with a number instead of the name.

It might be better to start of with Get Shared Parameter from the Genius.Loci package.

I also think the way to go IS List.GroupByKey. Go from there and see what you can come up with.
Then when you get stuck we can help you from there.

1 Like

first of all, thanks for your help. I’ve tried Get Shared Parameter from the Genius.Loci package, but it doesn’t work because this node gets the parameters from the shared parameter file, which I don’t have, I am trying to create it from this script. Then I tried the List.GroupbyKey as you can see in the image attached. Probably I didn’t get how it works, but if I try to associate a number to each item in the list i just get a list in which the numbers from 1 to 16 are listed in order and after the sixteenth entry it repeat 16 unitlll the end. Instead I would like that for each of the sixteen group name is associated a number.
I’ve attached also a couple of images to clarify what I’m trying to say. Thanks Again!

Group Shared_Parameter_List

So when you create the new SP file you also wanna rename the parameter and parameter groups (with a number as a prefix).

But for your first question this should work :point_down:

Knipsel2

@samuele.fuda
To replace the values you can use a dictionary



replace_in_dictionary.dyn (41.4 KB)

Partially yes, I want to assign A group ID (a number) to each parameter group. This because without a group ID the shared parameter file doesn’t work (see the attached file of a shared parameter txt file). I guess that i could just assign a unique group to all shared parameters, but it wont’ be ideal.

Sorry forgot the image

Can you please try my suggestion first?

Knipsel2

I agree List.GroupByKey should be the easier way


(i like doing dictionary because the hierarchy is not lost and it can be use for other parameters…)

In that case the keys have to come from the inputs values, when they are grouped you can then set the values

Hi,

I have tried your solution and it almost works, but at the end it seems that the replacing values with the dictionary are not correct. As you can see in the image attached the values of the shared parameter don’t correspond to the values of the groups name. There is something that i’m missing?

I’ve tried your solution and it works, but not as I intended. It gives me the shared paramaters divided by parameter group, but in this way i lose the original index order

@samuele.fuda
Could you check the dictionary by scrolling down the result of the node, is there something weird here ?
Is there really a shared group named INVALID ?

Yes apparently there is a entry named INVALID. Unfortunately I can’t reach out to the people who originally made this project. This is also the reason why I don’t have the shared parameter file.

it made me doubting, but INVALID is a valid entry :roll_eyes:
i replicate the error with my graph, so i think the error doesn’t come from the inputs but something is wrong with my graph, i am checking…

@samuele.fuda
Here it is !


I am sorry for the error…
I forgot to convert the keys (strings) to number, so when sorting it goes 0,1,10,2,3,… instead of 0,1,2,3,4…
As i worked with a generic sample with a list<10 i missed it…sorry again.

1 Like