[VEX] How to setdetailattrib() to a dictionary?

   3635   2   1
User Avatar
Member
899 posts
Joined: Feb. 2016
Offline
I need to build a detail dictionary with key/values from point attributes.

Ideally something like this in a point wrangle would work:
setdetailattrib(0, d@mydict[itoa(@ptnum)], myvalue, "append");
The offender is the second argument of course, as it is expecting a string.
Edited by Andr - Dec. 8, 2020 07:30:01
User Avatar
Member
899 posts
Joined: Feb. 2016
Offline
So I managed to do it from a detail wrangle with a for-loop.
My only question: is there a more direct way to assign the key values without using the intermediate dummy array?

for(int i=0; i<@numpt; i++)
{
    string key = point(0, "key", i);
    int dummy[] = d@mydict[key];
    append(dummy, i);
    d@mydict[key] = dummy;
}

Attachments:
point att to dict.JPG (96.4 KB)

User Avatar
Member
24 posts
Joined: Oct. 2015
Online
Can also be done via set() and insert():

In a detail wrangle:

string names[] = {'foo','bar','foobar'};
float vals[] = {.123,.234,.345};

d@myDict;

for( int i = 0; i < len( names); i++)
{

    string thisName = names[i];
    float thisVal = vals[i];
    
    insert(d@myDict,set( thisName, thisVal));
    
}
Tighe Rzankowski

trzankofx@gmail.com
  • Quick Links