ZBrushCentral

Find by name

Hey everyone.

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

Something like :

[VarDef, NameToFind, “Cube”]
[IButton, “Test”, “”, [If, [IGetTitle, Tool:Subtool:ItemInfo] == NameToFind, [MessageOK, “OK”], [MessageOK, “Not OK”]]]

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

Thanks for your help!

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/#Filenames

Thanks Doug. I didn’t knew that “Filenames” could be used for Subtool purposes. I’ll dig it that way.

You might have to read some more :wink: http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/#Tools_and_SubTools

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


[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"]
   ]
    
 ]

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/customizing-zbrush/zscripting/command-reference/#Strings

Thank you Marcus!

Sorry for those noob questions. This is the really first time that I script/code anything, I’m learning from scratch. :smiley:

I’ll try to merge this with my code.

Thanks again.