WhoCanDo Posted January 23, 2018 Share Posted January 23, 2018 Hi, 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. Regards Quote Link to comment
twk Posted January 23, 2018 Share Posted January 23, 2018 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)) Quote Link to comment
WhoCanDo Posted January 23, 2018 Author Share Posted January 23, 2018 Thanks twk, Unfortunately, I'm not into Python yet, and the count is part of a 660 line macro in VS so I can't just fit this into what I have. Any other great ideas Quote Link to comment
twk Posted January 23, 2018 Share Posted January 23, 2018 You could convert that 660 line macro in VS to python .. (jokes) When I used to use vectorscript, the VectorLab website was an invaluable resource. Here are two functions by @orso b. schmidthat helped me string together criteria(s): http://www.vectorlab.info/index.php?title=Txt-Braket http://www.vectorlab.info/index.php?title=Txt-Apostrophe Quote Link to comment
twk Posted January 23, 2018 Share Posted January 23, 2018 (edited) 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 ) { Orso *********************************************** } { wraps a string in '' } FUNCTION T_Apo(str: STRING): STRING; BEGIN T_Apo := Concat(Chr(39), str, Chr(39)); END; 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 January 23, 2018 by twk Quote Link to comment
WhoCanDo Posted January 23, 2018 Author Share Posted January 23, 2018 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 Quote Link to comment
Pat Stanford Posted January 23, 2018 Share Posted January 23, 2018 Try making the entire criteria into a single string and then use that string. VS does not like a mix of text and variables as a criteria. Quote Link to comment
Vectorworks, Inc Employee klinzey Posted January 23, 2018 Vectorworks, Inc Employee Share Posted January 23, 2018 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); Quote Link to comment
WhoCanDo Posted January 23, 2018 Author Share Posted January 23, 2018 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. Quote Link to comment
Pat Stanford Posted January 24, 2018 Share Posted January 24, 2018 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'); Or Str:='Easy As'; Crit:=Concat('ABC ',STR,' ',123,' ',STR,' Doe Ray Mi') Message(Crit); Count(Crit) 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. Quote Link to comment
Recommended Posts
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.