How to save particleIDs in a variable after selecting a bunch of particles in the viewport?

How to save particleIDs in a variable after selecting a bunch of particles in the viewport?

Anonymous
Not applicable
403 Views
2 Replies
Message 1 of 3

How to save particleIDs in a variable after selecting a bunch of particles in the viewport?

Anonymous
Not applicable
Hi,
I've been facing problem with saving the particle IDs of selected particles in a variable.
This is what I am doing:

Selected few random particles( particleShape1) in the viewport in component mode and ran the code:

string $sel[] = `ls -sl`;
for($each in $sel)
{
print ($each + "\n")
}

Result:

particle1.pt
particle1.pt
particle1.pt
particle1.pt
particle1.pt

Now my problem is, how can I store only the numbers in a variable? from the above example, I only want the numbers 4, 11, 27, 28, 29 and so on in a variable, not the whole string particle1.pt or particle1.pt
One problem could be that here it stores the output as a string. Did some tests on getParticleAttr, but no progress.
I am not sure how to go about it, or maybe my whole approach is wrong.

NEED HELP!!!!!

Thanks
0 Likes
404 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
select -cl  ;
select -r particle1.pt ;
select -tgl particle1.pt ;
select -tgl particle1.pt ;
select -tgl particle1.pt ;
select -tgl particle1.pt ;
select -tgl particle1.pt ;
getParticleAttr -at id -array true `ls -sl`;
// Result: 10 52 57 80 95 113 //
0 Likes
Message 3 of 3

Anonymous
Not applicable
WOW!! Just one line command :)
I've just recently started studying MEL. Thanks so much for your help.
Cheers!
0 Likes