THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/12/2006 at 16:39, xxxxxxxx wrote:
GetActiveObjects() fills AtomArray with every selected object in the document. The TRUE argument says to consider selected children as well - otherwise only selected parent objects are appended to the AtomArray. With GetActiveObjects(), you don't have to check whether or not objects are selected.
I think that you are confusing 'selecting' and 'selected'. Selecting objects in the document requires SetBit(BIT_ACTIVE) or user-interactive selection (PERIOD - there is no other way to select objects). Getting the selected objects into an AtomArray is best done with GetActiveObjects().
So, you've selected all of the objects in the document with a particular material (either by selection in the Object Manager, Editor, or by obj->SetBit(BIT_ACTIVE)). They are 'selected'. No need for 'selecting' at this stage.
Now you want to know how many are selected. You do this:
// Get the currently selected objects in the current document
AutoAlloc<AtomArray> bsobs;
GetActiveDocument()->GetActiveObjects(bsobs, TRUE);
LONG count = bsobs->GetCount();
GetCount() returns the number of objects added to the AtomArray. This happens to be the same as the number of currently selected objects in the document.
Now, if your problem is programmatically 'selecting' the objects that meet the same material criteria, then you need to do the recursive method and find the matching material and call SetBit() if it matches. If you want to be thorough, you can call DelBit() for any non-matches to mitigate existing user object selections.