Jump to content

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.

Share this post

Link to post

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


    gNumObjects : INTEGER;
    Procedure CountThem(h1 : HANDLE);
        IF GetType(GetParent(h1)) = 31 THEN gNumObjects := gNumObjects + 1;
    gNumObjects := 0;
    ForEachObject(CountThem, (Sel = True));

Share this post

Link to post

@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.

Share this post

Link to post

VW is changing in leaps and bounds but what about ScriptFunctionReference.html. It's always behind the times and doesn't offer explanations nor examples.

Thanks Pat

Share this post

Link to post

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.

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.


7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114


© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

  • Create New...