VEX: How do I append a list of attribute into an array prim attribute

   13512   4   1
User Avatar
Member
42 posts
Joined: Aug. 2016
Offline
I have list of objects have primitive attribute : instance (Image : Highlighted in Yellow)

how could I append the instance attribute by unique value into an array prim attribute ? (Image : In green text)

Thanks a lot
Edited by cgmagic.sunhe - Dec. 10, 2017 17:37:59

Attachments:
Untitled-2.jpg (106.1 KB)

User Avatar
Member
2040 posts
Joined: Sept. 2015
Offline
Is this what your looking for?

Put the following in a wrangle for primitives run over.

You say you want to append, which is why what I wrote takes the existing instance value puts it as the first value of the corresponding new primitive array attribute.

i[]@Instance_Array;

int Transfered_Instance;
Transfered_Instance = prim(geoself(), "instance", @primnum) ;
push(@Instance_Array, Transfered_Instance);
push(@Instance_Array, 1);
push(@Instance_Array, 2);
User Avatar
Member
42 posts
Joined: Aug. 2016
Offline
Sorry, maybe I could explain better. I am looking for

// Get each @instance from each prim.

// Make a new array attribute for each prim called @instance_array.

// only push each @instance from prim into the new @instance_array, if the item is not already in the list. For example, if there are more than one @instance==1, only push one of them into the array.in the array you won't have the same value twice.
User Avatar
Member
8554 posts
Joined: July 2007
Offline
since the array will be the same, there is no need to store it on each primitive
so I suggest running this in Detail mode
however if you want you can over Primitives
int n = nuniqueval(0, "primitive", "instance");
for (int i=0; i<n; i++){
    int inst = uniqueval(0, "primitive", "instance", i);
    append(i[]@instarray, inst);
}
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2040 posts
Joined: Sept. 2015
Offline
Thanks for this post Tomas.

I wasn't aware of the functions nuniqueval/uniqueval.

Definitely reduces the amount of code to do the task otherwise.
  • Quick Links