I'm new to ZScripting, and I'm trying to find a way to see if a subtool was already created in the subtool list. I was wondering if there's a way to compare names by creating a kind of "string variable".
I've find some threads regarding, how to compare strings, but nothing really related to this, and to be honest it's a bit difficult to find the exact thing we want in this forum.
There's no direct way to test for equivalence between strings but you can do it easily enough using [StrLength] and [StrFind]. The code below shows you how. Note that it tests for an exact match (and it is case sensitive). So it will only find a subtool called 'Cube', not 'Cube_1' or cube'. If all you want to do is find if a subtool has 'Cube' in its name then you would just need to use [StrFind] and test to see if -1 is returned (which means that the string is not found).
[CODE]
[VarDef, NameToFind, "Cube"]
[IButton, "Test", "",
//get the selected subtool name
[VarSet,SubTName,[IGetTitle,Tool:Item Info]]
//trim off the period at the end
[VarSet,SubTName,[StrExtract,SubTName,0,[StrLength,SubTName]-2]]
//if the strings are the same length AND have the same characters
[If,([StrLength,SubTName]==[StrLength,NameToFind])&&
([StrFind,SubTName,NameToFind] == 0),
[MessageOK, "OK"]
,
[MessageOK, "Not OK"]
]
][/CODE]
If you are looking for a particular subtool then you will have to loop through all the subtools, testing as you go. There's a macro that you can look at to see how to do that here. And you can read about the String commands here: http://docs.pixologic.com/user-guide...rence/#Strings