ZBrushCentral

Question: hide and unhide subtool htrough zscript

I’m trying to make a script that hides and unhides multiple subtools at once, But sometimes it’s working and other times not here are my routines

	[RoutineDef,Hide,

		[VarSet,activeSubT,[IGetTitle, Tool:Current Tool]]
		[IModSet,[StrMerge,"Tool:SubTool:",#activeSubT],18]
	]

	[RoutineDef,Show,

		[VarSet,activeSubT,[IGetTitle, Tool:Current Tool]]
		[IModSet,[StrMerge,"Tool:SubTool:",#activeSubT],50]
	]

I’ve noticed that when I record a macro and hide unhide subtools the numbers 18/50 are sometimes 34/2 and sometimes 18/50 . I don’t know why these numbers vary, but I assume it’s due some subtools holding more information than other or something?

What would be a better code that will always do what I expect it to do?

Hi @sunray_muijsson_f
so i made a macro for you to check the code but it’s a loop so it check walk in the subtool list from the first to the last one, and invert the visibility, if the subtool is visible, then it will turn it to not visible.

here is the code :

[IButton, "???", "tooltip...",
    [Loop, [SubToolGetCount],
        [SubToolSelect, n]
        [VarSet, subtool, [IGetTitle, "Tool:Current Tool"]]
        [VarSet, result, [IModGet, [StrMerge,"tool:subtool:", subtool]]]
        [Note, result,,-1]
        [If, ([IModGet,[StrMerge,"tool:subtool:", subtool]]&32 == 32),
            [Note, [StrMerge, subtool, " > visible\n"],,-1]
            [IModSet, [StrMerge,"tool:subtool:", subtool], result-32]
            ,//else
            [Note, [StrMerge, subtool, " > not visible\n"],,-1]
            [IModSet, [StrMerge,"tool:subtool:", subtool], result+32]
        ]
    ,n]
    [Note, ]
,,1]

I thought it was better to make a script that cover on all subtool, but It’s easy to edit the code to make it works on a single subtool, tell me if you get in trouble i will provide more code :slight_smile:

Hope It helps!
Nicolas

2 Likes

Hey Nicolas Thanks for your reply altough I’m still getting some trouble witht he code it helped out a ton! The problem I’m getting is that it still ignores some subtool so I troubleshouted a bit.

if there subtools that have the same name as other subtool it doesn’t work. I decided to run a routine before hiding or showing the subtool. To rename the subtool to make sure it has a unique name.

it works but I’d prefer to not have to change all the names. Do you know if there is a way to avoid renaming the subtools?

then we got to not use IModGet/Set but [SubToolGetStatus] and [SubToolSetStatus] to get ride of the subtool name.

so it gives that :

[VarDef, OUTPUT, 1]


[RoutineDef, SubToolIsVisible,
	[VarSet, isVisible, 0]
	[VarSet, index,[SubToolGetActiveIndex]]
	[VarSet, subtool,[SubToolGetStatus, index]]
	[VarSet, folderIndex,[SubToolGetFolderIndex, index]]
	[If,(folderIndex > -1),
        //folder
		[VarSet,subtoolFolder,[SubToolGetStatus,folderIndex]]// for folder visibility
		[If,([Val,subtoolFolder]&0x2 == 0x2)&&([Val,subtool]&0x1 == 0x1),
			[VarSet,isVisible,1]
            [SubToolSetStatus, index, 0x2]
		]
		,//not a folder
		[If,([Val,subtool]&0x1 == 0x1),
			[VarSet,isVisible,1]
            [SubToolSetStatus, index, 0x0]
            ,//else
            [VarSet,isVisible,0]
            [SubToolSetStatus, index, 0x1]
		]	
	]
,isVisible]

[IButton, "???", "Toogle/Invert Subtools Visibility",
    [Loop, [SubToolGetCount],
        [SubToolSelect, n]
        [VarSet, subtoolTitle, [IGetTitle, "Tool:subtool:Current Tool"]]
        [VarSet, status, 0]
        [RoutineCall, SubToolIsVisible, status]
        [If, OUTPUT, [Note, [StrMerge, subtoolTitle, " > " , status, "\n"],,-1]]
    ,n]
    [If, OUTPUT, [Note, ]]
,,1]

Hope It helps!
Nicolas

1 Like

thanks a lot nicolas got it working!!