1. #1
    New Member Follow User Gallery
    Join Date
    Jul 2009
    Location
    France
    Age
    39
    Posts
    21

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

    Thanks for your help!

  2. #2

  3. #3
    New Member Follow User Gallery
    Join Date
    Jul 2009
    Location
    France
    Age
    39
    Posts
    21

    Default

    Thanks Doug. I didn't knew that "Filenames" could be used for Subtool purposes. I'll dig it that way.

  4. #4

  5. #5
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    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

  6. #6
    New Member Follow User Gallery
    Join Date
    Jul 2009
    Location
    France
    Age
    39
    Posts
    21

    Default

    Thank you Marcus!

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

    I'll try to merge this with my code.

    Thanks again.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •