Jump to content
Developer Wiki and Function Reference Links ×

Count objects but not within a group


Recommended Posts

I thought this was easy but alas it's not.

 

I want to 

x := Count ((Sel = True)); Message (x);

 

However, if I have a group of 3 objects and only this group object selected then x := 4

 

Some of my selected objects will be polygons, rectangles & groups of them.

Link to comment

You will need something like this, which only counts object whose parent is a layer:

 

PROCEDURE xxxxx;
VAR
    gNumObjects : INTEGER;
    
    Procedure CountThem(h1 : HANDLE);
    BEGIN
        IF GetType(GetParent(h1)) = 31 THEN gNumObjects := gNumObjects + 1;
    END;
        
BEGIN
    gNumObjects := 0;
    ForEachObject(CountThem, (Sel = True));
    Message(gNumObjects);
END;
RUN(xxxxx);

Link to comment

@Julian Carr Sometimes having been around for a long time is a hinderance. I just found out about this one myself a few months ago.

 

There is a new criteria called Visible Selection State. It only returns the objects that are individually visible (i.e. container objects) and ignores any selected objects inside those containers.

 

Try count(((VSel=True)))

 

In a file with a selected group made up of three selected objects, when I put the following formulas into a worksheet I get:

 

Count(Sel=True) returns 4

Count(VSel=True) returns 1

 

I think this is what @WhoCanDo is actually looking for.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...