1. #1
    Senior Member Follow User Gallery
    Join Date
    Jul 2014
    Posts
    111

    Question Get current sub tool by index

    I'm currently writing a script to switch off all but the currently selected sub tools.

    So far so good - only I can't figure out how to do that by index instead of by name
    Here's what I have so far:

    [CODE]
    // Switched off all but current sub tools
    [IButton, "Switch off", "Switch off all but selected sub tools",

    // create variable equal to number of sub tools
    [VarDef, len, [SubToolGetCount]]

    // get active index of tool
    [VarDef, idx, [SubToolGetActiveIndex]]

    // loop over array
    [VarSet,i,0]
    [Loop,len,

    // Not sure if you have to select as you go
    // but i'm not sure how to get the subtool name
    [SubToolSelect,[Val,i]]

    [VarSet,subtoolName,[IGetTitle,Tool:Subtool:Item Info]]

    [If, i == idx
    , // Then...
    [Note, idx] // idx is correct

    // Try to switch off
    //[IModSet,Tool:SubTool:subtoolName,1] // doesn't work ???

    // this works by name ie "head" "heart" "eyeball"
    // [IModSet,Tool:SubTool:Heart,1]

    , // Else...
    // Do nothing

    ] // end if
    [VarInc, i] // i++
    ] // end loop

    ] // end button

    [/CODE]





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

    Default

    Here's how to get the name of the subtool and use it to get the visibility:

    [IButton,TurnAllOff,,
    [VarSet,idx,[SubToolGetActiveIndex]]
    [Loop,[SubToolGetCount],
    [SubToolSelect,[Val,n]]
    [VarSet,subtoolName,[IGetTitle,Tool:ItemInfo]]
    [VarSet,subtoolName,[StrExtract,subtoolName,0,[StrLength,subtoolName]-2]]
    [If,(n != idx),
    [If,[IModGet,[StrMerge,"Tool:Sub Tool:",subtoolName]]>= 16,
    //visible so turn off
    [IModSet,[StrMerge,"Tool:Sub Tool:",subtoolName],1]
    ]
    ]
    ,n]
    [SubToolSelect,idx]
    ]

    [IButton,TurnAllOn,,
    [VarSet,idx,[SubToolGetActiveIndex]]
    [Loop,[SubToolGetCount],
    [SubToolSelect,[Val,n]]
    [VarSet,subtoolName,[IGetTitle,Tool:ItemInfo]]
    [VarSet,subtoolName,[StrExtract,subtoolName,0,[StrLength,subtoolName]-2]]
    [If,(n != idx),
    [If,[IModGet,[StrMerge,"Tool:Sub Tool:",subtoolName]]< 16,
    //invisible so turn on
    [IModSet,[StrMerge,"Tool:Sub Tool:",subtoolName],16]
    ]
    ]
    ,n]
    [SubToolSelect,idx]
    ]


    It is possible to use the subtool number (not ID) but that's a little more complicated so I'll post how to do that tomorrow.

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

    Default

    OK, here is a way to use the subtool number. I say number rather than index (or ID) because I'm referring to the number in the subtool list and this changes depending on the position of the scrollbar. If you loop through all the subtools in order using SubToolSelect then as soon as the first 8 are dealt with the selected subtool will always be number 7 (at the bottom of the list). So you can use this code:

    //for all subtools, selected using [SubToolSelect]

    [IButton,TurnAllOffByNumber,"Turn off all subtools except selected",
    [VarSet,idx,[SubToolGetActiveIndex]]
    [Loop,[SubToolGetCount],
    [SubToolSelect,[Val,n]]
    [If,[Val,n] < 7,
    [VarSet,stID,[Val,n]]
    ,
    [VarSet,stID,7]
    ]
    [If,(n != idx),
    [If,[IModGet,[StrMerge,"Tool:Sub Tool ",stID]]>=16,
    //visible so turn off
    [IModSet,[StrMerge,"Tool:Sub Tool ",stID],1]
    ]
    ]
    ,n]
    [SubToolSelect,idx]
    ]

    //If you needed to check the selected subtool only you need to set its position, so that you could use the correct path. You can do it by moving the scrollbar so that the selected subtool is top of the list. Its number is then 0:

    [IButton,GetSelected,"Get visibility of selected subtool",
    [VarSet,idx,[SubToolGetActiveIndex]]
    [ISet,Tool:Sub Tool:SubTool ScrollBar,0,([SubToolGetCount]-(idx+1))]
    [If,[IModGet,"Tool:Sub Tool 0"]>=16,
    [Note,"Selected subtool is VISIBLE",,1]
    ,
    [Note,"Selected subtool is HIDDEN",,1]
    ]
    ]




    HTH,

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
  •