Jump to content
Developer Wiki and Function Reference Links ×

Count objects using the record field value


Recommended Posts



I wish to count objects which have a field value in their records of 2001 (ie 'Group-A'.'Mark' = '2001')


This works ..

Message (Count ('Group-A'.'Mark'='2001'));


This doesn't work ..

Mark := '2001';
GroupPanelCount := Count (Concat ('''Group-A''', '.', '''Mark''', '=''', Mark, ''''));
Message (GroupPanelCount);


This shows that the string is correct but count won't see it that way ..

Message ('''Group-A''', '.', '''Mark''', '=''', Mark, '''');


How can I count objects with a changing field value if I don't want to select them prior to counting. 



Link to comment

One of the reasons I jumped to learning python was the Criteria String building in vectorscript, proved really difficult for me.


try this, in python:


RecordName = "Group-A"
FieldName = "Mark"
FieldValue = "2001"
crit = "'{}'.'{}'='{}'".format(RecordName,FieldName,FieldValue)
GroupPanelCount = vs.Count(crit)
vs.Message("Total Count = {}".format(GroupPanelCount))


Link to comment

I haven't tested the code below, but I believe it goes something like that:

(You'll have to declare those variables though; ah Vectorscript :P)

{ Orso *********************************************** }
{ wraps a string in '' }
		T_Apo := Concat(Chr(39), str, Chr(39));
RecordName := 'Group-A'
FieldName := 'Mark'
FieldValue := '2001'
crit := Concat(T_Apo(RecordName),T_Apo('.'),T_Apo(FieldName),'=',T_Apo(FieldValue))
Counter = Count(crit)
Message(Concat('Total Count = ',Counter_))


Edited by twk
Link to comment

Unfortunately, this returns zero as my code did. Your loop added too many quotes. But you gave me a good idea. This works ..


FieldValue := '2001';

crit := Concat (Chr(39), 'Group-A', Chr(39), '.', Chr(39), 'Mark', Chr(39), '=', Chr(39), FieldValue, Chr(39));

Counter := Count (crit);
Message (Concat ('Total Count = ', Counter));


Good work. Thanks

Link to comment
  • Vectorworks, Inc Employee

As pat said it's best to put everything into a single string before using it in the criteria.

This should work:


    Mark := '2001';
    qstr := Concat ('''Group-A''', '.', '''Mark''', '=', '''',Mark, '''');
    GroupPanelCount := Count (qstr);
    Message (GroupPanelCount);


Link to comment

Thanks Guys, so I was on the right track with ..


GroupPanelCount := Count (Concat ('''Group-A''', '.', '''Mark''', '=''', Mark, ''''));


except that I was over nesting it for VW. This works ..


crit := Concat ('''Group-A''', '.', '''Mark''', '=''', Mark, '''');

GroupPanelCount := Count (crit);


What was confusing me was that Message managed to handle (Concat ('''Group-A''', '.', '''Mark''', '=''', Mark, '''')); but Count couldn't.


Regards to all.

Link to comment

Message works because it is only displaying the concatenated string. In fact you don't need to use concat with message at all as the message command will do the contact automatically based on the values included. Message will even automatically convert numbers to strings, which after testing it appears Concat will do as well.


Str:='Easy As';

Message('ABC ',STR,' ',123,' ',STR,' Doe Ray Mi');




Str:='Easy As';

Crit:=Concat('ABC ',STR,' ',123,' ',STR,' Doe Ray Mi')




Count needs a criteria that happens to be a string. And none of the functions that require a criteria are very happy when you try to build those criteria inline. Use concat to create the total criteria string first and then use just the single variable with the function requiring the criteria.

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.

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