ZBrushCentral

Store result of IGetTitle in mem block

Hi guys.
I try to store in mem block currently active subtool name.
But when i try to read variable from mem block its empty.
What am i doing wrong.

The main goal of this script is to toggle visibility of one subtool without any switching to this subtool or any mouse or ui button manipulations.

Here is a scripts(one to store subtool name and one to toggle its visibility later):

KEY_TOOLVISSTORE.TXT

[IButton,???,"store tool visibility state",
[IShowActions,0]
[IConfig,2019]

[IFreeze,
[If,[MemGetSize,VOID_StoreRestoreVisUD_MemBlock],                                              // if UD exist do nothing

    // store tool  visibility state
    [VarSet,activeSubT,[IGetTitle, Tool:Current Tool]]                                          //set variable name for current subtool name
    [MVarSet,VOID_StoreRestoreVisUD_MemBlock,0,activeSubT]
    [Note,activeSubT,,2]
    [Note,"exsist",,0.2]
            
,
    [MVarDef,VOID_StoreRestoreVisUD_MemBlock,1,0]                                                // esle create UD first run
        // store tool  visibility state
        [MVarSet,VOID_StoreRestoreVisUD_MemBlock,0,[IGetTitle, Tool:Current Tool]]
        [Note,activeSubT,,2]
        
        [Note,"stored",,0.2]
]
]
]

KEY_TOOLVISRESTORE.TXT

    [RoutineDef, ShowSubT,
    [VarSet,activeSubT,[IGetTitle, Tool:Current Tool]] //set variable name for current subtool name
    [IModSet,[StrMerge,"Tool:SubTool:",#activeSubT],17] //show current tool
    ]
    [RoutineDef, HideSubT,
    [VarSet,activeSubT,[IGetTitle, Tool:Current Tool]] //set variable name for current subtool name
    [IModSet,[StrMerge,"Tool:SubTool:",#activeSubT],1] //hide current tool
    ]


    [IButton,???,"restore tool visibility state",


    [IFreeze,
    [If,[MemGetSize,VOID_StoreRestoreVisUD_MemBlock],                                              // if UD exist do nothing

        // restore tool  visibility state
        [VarSet,activeSubT,[MVarGet,VOID_StoreRestoreVisUD_MemBlock,0]]
        [Note,activeSubT,,2]
        
        [VarSet,CheckState,[IModget,[StrMerge,"Tool:SubTool:",#activeSubT]]]
        [If, [Var,#CheckState] >=16,//if the subtool is visible
                    [RoutineCall,HideSubT] //call the routine that will hide subtool
                 , //if the subtool is hidden 
                   [RoutineCall,ShowSubT] //call routine that will show subtool
        ]
        [Note,"restored",,0.2]

    ,
        [Note,"no name",,0.2]                                                                 // if UD do not exist in dyn mem
    ]
    ]
    ]

hi @Prostrelov

so basically I made a short macro to show you how it work with mem block to write/read strings :

[IButton, "???", "Store the current material name into a memblock.",

	// 1. IGetTitle to store the data in variable named "material".
	[VarSet, subtool, [IGetTitle,"Tool:Subtool:ItemInfo"]]

	// 2. Trim the end period and null terminated character.
	[VarSet, subtool, [StrExtract, subtool, 0, [StrLength, subtool]-2]]

	// 3. Create a memblock
	[MemCreate, mem_block, [StrLength, subtool]] 

	// 4. write the string at 0 offset
	[MemWriteString, mem_block, subtool, 0]

	// 5. Reference and assign string to hold the data in the memblock
	[VarSet, text, ""]
	
	// 6. Read the mem block at 0 offset
	[MemReadString, mem_block, text,0]

	// 7. then show the data
	[Note, text]

	// 8. Delete the mem block to cleanup
	[MemDelete, mem_block]
,,1]

Hope this helps,
Nicolas

I dunno why but at first attempt to use MemWriteString MemReadString it doesn’t works out. So i tried it from work and everything works greate. Thanks anyway.
Here is the code:

KEY_TOOLVISSTORE.TXT

[IButton,???,"store tool visibility state",

[IFreeze,
[If,[MemGetSize,VOID_StoreRestoreVisUD_MemBlock],                                              // if UD exist do nothing

	[VarDef, activeSubT, ""]
	[VarSet,activeSubT,[IGetTitle, Tool:Current Tool]]                                          //set variable name for current subtool name
	[MemWriteString, VOID_StoreRestoreVisUD_MemBlock, activeSubT,0]
	
    [Note,"stored",,0.2]
        
,
	[MemCreate, VOID_StoreRestoreVisUD_MemBlock, 256, 0]
	[VarDef, activeSubT, ""]
	
	[VarSet,activeSubT,[IGetTitle, Tool:Current Tool]]                                          //set variable name for current subtool name
	[MemWriteString, VOID_StoreRestoreVisUD_MemBlock, activeSubT,0]
    
    [Note,"stored",,0.2]
]
]
]

KEY_TOOLVISRESTORE.TXT

[RoutineDef, ShowSubT,
	[IModSet,[StrMerge,"Tool:SubTool:",#activeSubT],17] //show current tool
]
[RoutineDef, HideSubT,
	[IModSet,[StrMerge,"Tool:SubTool:",#activeSubT],1] //hide current tool
]


[IButton,???,"restore tool visibility state",


[IFreeze,
[If,[MemGetSize,VOID_StoreRestoreVisUD_MemBlock],                                              // if UD exist do nothing

		[VarSet, activeSubT, ""]
		[MemReadString, VOID_StoreRestoreVisUD_MemBlock, activeSubT]
		
        [VarSet,CheckState,[IModget,[StrMerge,"Tool:SubTool:",#activeSubT]]]
        [If, [Var,#CheckState] >=16,//if the subtool is visible
                    [RoutineCall,HideSubT] //call the routine that will hide subtool
                 , //if the subtool is hidden 
                   [RoutineCall,ShowSubT] //call routine that will show subtool
        ]
,
        [Note,"no name previously stored",,0.2]                                                                 // if UD do not exist in dyn mem
]
]
]

The only problem is that each time you use script above Zbrush switch to saved tool first.
Is it possible to toggle tool visibility without switching to it (do not make it active for a moment) ?