Martin Tye Posted October 6, 2017 Share Posted October 6, 2017 Hi, Here is a snippet from a script I have been using for some time but, with the advent of VW2018 it has stopped working. It seems that the variable string 'sides' is no longer passed to the Class type selector in SelectObj (it only works if the actual selector is set to (C= 'sides') directly). Procedure CustTool; VAR LineType:STRING; PROCEDURE Poly (line: STRING); BEGIN lineType:= line; SelectObj((C=lineType) AND (V=TRUE)); END; BEGIN Poly('sides'); END; Run(CustTool); Has anyone else come across this /can anybody shed any light on it please? Quote Link to comment
MullinRJ Posted October 6, 2017 Share Posted October 6, 2017 Hello Martin, Your problem lies in your choice of variable names. In this case it is "lineType". The compiler must have it tagged with another meaning in criteria statements, although I did not find it listed as a KeyWord. Change it to "lineTypes", or "lineTyp", or "line_Type" and your script will work in VW 2018. That said, your script could be written as a one-line VectorScript: SelectObj( (C = 'sides') AND V ); Unless you intend to expand your script where it needs more lines and/or variables, this one line does the same thing as the 12 lines in your script. Also note that you are using variable and procedure names that are already pre-defined VS commands, like "line" and "Poly". Although this usually works as you intend, it can sometimes cause you problems in more complicated scripts and it should be avoided. Been there, done that, spent hours trying to figure out why a script that compiles doesn't run. Raymond 1 Quote Link to comment
JBenghiat Posted October 6, 2017 Share Posted October 6, 2017 To add, criteria and variables can be tricky, especially with strings. The Criteria type is actually a string, but the vs compiler will parse a function’s arguments, when it accepts Criteria, and tries to convert it into a string. When a variable is involved, as you may imagine, this can be imprecise. The safest option is to define a variable for the entire Criteria string, and use Concat() to build the Criteria first: critStr = Concat(... SelectObj(critStr); You also usually need to add to critStr the single quote marks that would be around the class name. To escape the quote mark, repeat it two times (plus one to end the string): Concat(‘(C=‘’’, linetype, ’’’) ... 1 Quote Link to comment
Pat Stanford Posted October 6, 2017 Share Posted October 6, 2017 I will add my usual rant here about multiple single quotes and readability. The multiple quotes suggested by Joshua certainly work, but try and figure out what they mean 6 months, 6 weeks or even 6 hours from now and you are likely in for a fun time. My eyes are bad enough that even with my glasses I can't easily tell the difference between two concatenated single quotes ( '' ) and a single double quote ( " ). I like to use the ASCII equivalent of the single quote mark ( CHR(39) ) to make sure there is no chance of confusion. It makes it read less well, but is much more clear and subject to less confusion. Message('This is an ',chr(39),'example',chr(39),' of how to put a single quote mark ( ',Chr(39),' ) into a VS string'); 1 Quote Link to comment
Martin Tye Posted October 6, 2017 Author Share Posted October 6, 2017 And there speaks the voice of experience x 3, to the power of three! Thank you so much for those insights - I shall be taking lessons and elements from all three Masters: • I had since figured out the chr(39) usage from one of Pat's recent posts and I do prefer this over the multiple quote marks, that certainly do get confusing. • I have switched to JB's concat criteria which are working nicely. • I shall be avoiding the use of vs reserved words, per RM's suggestion (but I need to repeat the procedure for various variables so [I think] I need those lines to enable this). Gents, thank you again. I will put these into practice and see how things look then but here do seem to be some other things happening, since working in the 2018 environment (on Mac). Obviously, these are irritating but, perhaps provide a 'test' and a way of improving / refining the coding over time. Whilst on, this is actually my first ever post on this forum but, having had to learn vs 'the hard way', as a non programmer, I found the forum totally invaluable and there is no way I would have been able to develop the tools that I have needed to, without it. I have literally trawled it for information and solutions. It is an amazing resource and I owe a big thanks to all of its key contributors! Quote Link to comment
Pat Stanford Posted October 8, 2017 Share Posted October 8, 2017 Welcome. Feel free to ask questions. We are happy to share what we know. Quote Link to comment
Martin Tye Posted October 20, 2017 Author Share Posted October 20, 2017 After a lot of effort trying to trace exactly where the problem(s) were, it seems to have come down to poor choice of variable names, per Raymond's initial response. (The concat criteria were not necessary to make the script run, though may be a better / more robust method for selection). SP1 certainly seems to have helped to resolve some of the issues. I now have noticed another issue - it seems that when Ungroup is used, any record data pertaining to the group is no longer transfered to the ungrouped items, as it did previously. I'm not sure if this is a setting or a change in the way the program works - I may create a new post for this, in case it is not very visible within this string - but has anyone noticed this or can shed any light on it please? Quote Link to comment
MullinRJ Posted October 21, 2017 Share Posted October 21, 2017 Martin, I am seeing the same behavior in VW 2017 and VW 2018 when ungrouping. If there is a record attached to a GROUP, I get a dialog asking if I want to attach the GROUP's record to the objects inside the group. Do you get this dialog when you ungroup? Did you ever click the "Always do the selected action" box? If you did and then pressed NO, that would explain why you don't get this dialog and your objects never get the GROUP's records when you ungroup. To reset this setting, go to VW Preferences under the Session tab and click the "Reset Saved Settings..." button. Pick how much you want to reset and click OK. HTH, Raymond Quote Link to comment
Martin Tye Posted October 23, 2017 Author Share Posted October 23, 2017 Hi Raymond Many thanks for your most full and complete post - which is exactly what was happening. I have now reset the saved settings (and then selected always Yes) and this is all working fine now. I think you saw this from Pat's post that I had set up as a new subject. Thanks both for super-quick and ultra precise help and analysis!!! Quote Link to comment
MullinRJ Posted October 23, 2017 Share Posted October 23, 2017 Martin, You are very welcome. Raymond 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.