Creating a Loop to replace parameter values

Using Design Script
SplitAndAssignParameterValueDS.dyn (2.9 KB)

prmVl1=Element.GetParameterValueByName(elm,"SignageTypes");
prmVl2=String.TrimWhitespace(String.Split(prmVl1,","));

lst11=SetDifference(prmVl2,{"ST13","ST14"});
lst12=List.AllIndicesOf(List.IsEmpty(lst11<1>),true);
prmVl11=Flatten(List.ReplaceItemAtIndex(lst11,lst12,""));

prmVl21=List.AddItemToFront("",prmVl2<1>);
ind21=Transpose(IndexOf(prmVl2<1>,{"ST13","ST14"}<2>)+1);
prmVl22=List.GetItemAtIndex({prmVl21,prmVl21}<1><2>,ind21<1><2>);

prmVl31=List.AddItemToFront(prmVl11,prmVl22);

elmPrm=Element.SetParameterByName(elm,{"SignageOther",
"SignageFire","SignageFM"}<1>,prmVl31<1>);
1 Like

Another way …
SplitAndAssignParameterValueDS1.dyn (3.0 KB)

prmVl1=Element.GetParameterValueByName(elm,"SignageTypes");
prmVl2=String.TrimWhitespace(String.Split(prmVl1,","));

prRpl1[{"ST13","ST14"}]={"SignageFire","SignageFM"};
prmVl3=List.Chop(prRpl1[prmVl2],List.Count(prmVl2<1>));

msk1=List.AddItemToFront("a"/1,prmVl3<1>);
msk2=DSCore.Object.IsNull(msk1<1>);
idx1=List.LastItem(List.AllIndicesOf(msk2<1>,true)<1>);

prmNm1=List.ReplaceItemAtIndex(msk1<1>,idx1<1>,"SignageOther");
prmNm2=List.RestOfItems(prmNm1<1>);

setPm=elm.SetParameterByName(prmNm2<1>,prmVl2<1>);

Thanks everyone - lots to go and look at and try to figure out. You have all been very helpful, it’s greatly appreciated.

Einar,

I like this - it make sense and I should be able to adapt it to other uses. However when I run it I’m getting an error which is odd as all the lists all seem to match… any thoughts?

I’m not sure, it might

  • Have you tested it with the example you provided?

  • Are there any empty lists or similar in one of your watch nodes?

  • What Dynamo version are you on? There’s been some changes to how the nodes handles lists in 1.0, you might need to use List.Combine to make it work in older versions.

  • Have you tried to change lacing on SetParameterByName?

Hi Einar,

I’ve tried it on the example file I provided.

No empty lists

Dynamo 1.0, Clockwork 0.90.7

Lacing set to shortest. Setting to Longest completes one of the parameters with the correct value. Setting to Cross completes one of the parameters with the wrong value…

Kinda weird…

Did it work on the example file? If so, I can have a look at the other file if you want. You can use dropbox or wetransfer.com or something similar if the file size is too big.

You can also try this modified version witch matches the elementlist to the other lists “manually”, also the clockwork node is replaced by String.Split
splitParameter-v2.DYN (10.6 KB)

2 Likes

Realized that the solutions I’ve provided above are unnecessarily complicated. The solution could be far less convoluted :slight_smile:
SplitAndAssignParameterValue1.dyn (5.8 KB)

2 Likes

The above solution in Design Script

st=String.TrimWhitespace(String.Split(elm.GetParameterValueByName("SignageTypes"),",")<1>);
pn=elm.SetParameterByName(st=="ST13"?"SignageFire":(st=="ST14"?"SignageFM":"SignageOther"),st);
1 Like

Okay, there’s something weird going on here.

@Vikram_Subbaiah - if I run your script I get the same error with Element.SetParameterByName - yet clearly your image shows it running correctly.

If I run @Einar_Raknes last script it runs fine - the difference between the two is the Element input in this case which has a list which matches the inputs fro both parameter name and value.

So the question is, is my Element.SetParameterByName node somehow broken that it’s not accepting the input that others seem to be?

(Note in both instances I’m using the test file I uploaded)

You could try to uninstall all dynamo versions and do a clean 1.0 install, if not it’s nice to know that you can solve your problem with Chop and Cylcle.

yes, I think a clean install might be a good idea. I’ve got versions stretching back to about 0.6.0…

BINGO!!

That’s sorted it. Obviously a conflict in there somewhere but now we’re cooking on gas and as you say I’ve learn something new about Chop and Cycle!

thanks again for all your help guys.

1 Like

Glad it worked out for you, I marked Virkrams last graph as solution. I don’t think it’s much room for optimization there :wink:

2 Likes

Can’t argue with that. TBH I hadn’t noticed the solution option in the new forum, good to know.

Am I right in thinking in the code block the ‘?’ denotes ‘then’ - e.g. if Input = ST13 ‘then’ output is Signage Fire ? I’ve been wondering for a while how to do if statements in code like that, I understood your method but this does seem like a cleaner way of doing it.

It’s like in excel: if( test , true , false)
Designscript: test ? true : false

3 Likes

Thanks - that’s very helpful.