On 12/05/2015 at 02:05, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14+
Platform: Windows ;
Language(s) : XPRESSO ;
---------
Hi folks,
In the C++ docs, it says that using GetRange() is faster than looping through all polygons with IsSelected() as follows:
#### Bool GetRange(LONG seg, LONG maxElements, LONG* a, LONG* b) const_<_h4_>_
#### Bool IsSelected(LONG num) co_<_h4_>_h4>
**Note:** If you efficiently want to go through selections you can use the following code:
`
LONG seg=0,a,b,i;
while (bs->GetRange(seg++,&a,&b))
{
for (i=a; i<=b; ++i)
{
// ... do something - i is the selected element
}
}`
This is faster than:
`
for (i=0; i<maxelements; i++)
{
if (bs->IsSelected(i))
{
// ... do something
}
}`
`
I am trying to understand how the above GetRange() code actually works, for example what the hell is a 'segment' as i deal with polygon selections, and how does this method actually work.. The above GetRange example also doesn't use MaxElements and throws an error without it. And do a, b, and maxelements refer to index's within the entire BaseSelect or array index's of the selected elements array only.. Slightly confused :/
Specifically what i am currently doing ( just to complicate matters ), is a multithreaded approach. Each thread loops through a portion of the objects polygons, and does some work with BaseSelect. So the main question is: is it possible to use GetRange() as above, but for each function to only operate on a portion of the range - for example, something like:
`
`LONG seg=0,a=startIndex,b=endIndex,i;
while (bs->GetRange(seg++,(endIndex-startIndex),&a,&b))
{
for (i=a; i<=b; ++i)
{
// ... do something - i is the selected element
}
}`
`
Thanks in advance for any help and advice, it's much appreciated.
`