Jump to content

Syntax to build a dictionary in a Foreach SOP loop


Recommended Posts

Posted (edited)

I'm trying to iterate over named primitives to create a dictionary that hold, say the bounding boxes of each group of primitives.

What is the correct syntax ?  I always end up with a dictionary with one element and it's actually in feedback mode..

 

For now, I managed to reimplement it in one detail wrangle like this:

string names[] = uniquevals(0,"prim","name");
s[]@names=names;

foreach(string s; s[]@names) {
if (strlen(s)==0) continue; // skip empty groups
string gn = sprintf("@name==%s",s);
int prims[] = expandprimgroup(0,gn);
vector size= getbbox_size(0,gn);
string ssz = sprintf("%f, %f, %f", size.x, size.y, size.z);

d@infos[s]=gn;
d@primCount[s]=len(prims);
d@sizes[s]=ssz;
}

 

But I'm still looking for the reason why the dictionary doesn't seem to like the assignation of its keys in a feedback loop.

Edited by AntoineSfx
Link to comment
Share on other sites

Don't see that uniquevals works to create sets, we should see a,b,c in foreach, right?

names >> [ a0, a1, a2, a3, b0, b1, c0, c1, c2, c3 ]
infos >> {"a0": "@name==a0", "a1": "@name==a1", "a2": "@name==a2", "a3": "@name==a3", "b0": "@name==b0", "b1": "@name==b1", "c0": "@name==c0", "c1": "@name==c1", "c2": "@name==c2", "c3": "@name==c3"}

 

Link to comment
Share on other sites

2 hours ago, fencer said:

Don't see that uniquevals works to create sets, we should see a,b,c in foreach, right?

names >> [ a0, a1, a2, a3, b0, b1, c0, c1, c2, c3 ]
infos >> {"a0": "@name==a0", "a1": "@name==a1", "a2": "@name==a2", "a3": "@name==a3", "b0": "@name==b0", "b1": "@name==b1", "c0": "@name==c0", "c1": "@name==c1", "c2": "@name==c2", "c3": "@name==c3"}

 

 I don´t undertstand what you are asking.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...