Home Technical Talk

Zscript problem with [IModGet]

greentooth
Offline / Send Message
floon greentooth
Hey polycounters!

I’m currently working on a Zbrush script to speed up my pipeline to Substance, but ran into an anomaly I can’t wrap my head around.
Chances are this is a no-brainer, since I’m completely new to Zscript and not the biggest scripter in the first place. So please DO state the obvious.

The script is supposed to rename all visible subtool and cycles through all subtools checking their state using [IModGet]. When visible it renames them, other wise it doesn’t.
From my understanding [IModGet] returns a value smaller than 15 when invisible and a greater value if otherwise.
This works just fine, but after running the script a few times and changing visibility. Zbrush returns a value of 1 even for visible subtools and I can only fix that by hiding/unhiding all subtools, which seems to reset their state.
Does anyone of you know of this problem?
Maybe @nyx702 could help , you seem to be an Zscript archwizard :)

My code sofar (with out the CheckSystem routine):
<code>[VarDef,subTName,""] //defines variable as empty string<br>[RoutineCall, CheckSystem]<br>[VarDef, newName,""]&nbsp;&nbsp;&nbsp; <br><br>[IButton,"RenameAllVisible","Renames all visible subtools",<br>[VarSet,totalSubTools,[SubToolGetCount]]&nbsp; //the total number of subtools<br>[VarSet,activeSubT,[SubToolGetActiveIndex]]&nbsp; //record the active subtool<br><br>[VarSet, newName,[StrAsk, "Type text in here", "Please enter a file name"]]&nbsp; //new name<br>&nbsp;&nbsp;&nbsp; [If, [StrLength, newName] < 2, //check if the name is valid<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Note, "Name must at least have 2 characters",2]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Exit]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,<br>&nbsp;&nbsp;&nbsp; ]<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; [If,activeSubT==0,[SubToolSelect,1]] //this stops an error <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; [Loop,totalSubTools,<br>&nbsp;&nbsp;&nbsp; [SubToolSelect,[Val,n]] //selects the subtool by number<br>&nbsp;&nbsp;&nbsp; [VarSet,subTName,[IGetTitle,Tool:ItemInfo]]&nbsp; //gets the tool name<br>&nbsp;&nbsp;&nbsp; [VarSet,subTName,[StrExtract,subTName,0,[StrLength,subTName]-2]] //trims off period<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [If,[IModGet,[StrMerge,"Tool:Sub Tool:",#subTName]]>=16,&nbsp; //checks for state <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [FileExecute,dllPath,"PasteText",#newName]//renames current subtool<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [IPress,Tool:SubTool:Rename]&nbsp; //renames current subtool<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br>&nbsp;&nbsp;&nbsp; ,n]<br>]

(Props to marcus_civis of zbrushcentral at this point, it’s 80% his code)



Replies

  • nyx702
    Yea all the IMod stuff is crappy. You ready for this? 

    I'm pretty sure the issue is that you can't get info from IMod if the interface element is not visible. So you need to move the subtool list down to get that info if you have more than 8 subtools. There are multiple ways to do this involving the scroll bar but I think its easier to just select the 8th subtool. Try something like this (also bastardized from Marcus)


    [Loop,totalSubTools,[IUpdate]
       	[VarSet,isVis,0]
    	//if subtool is visible in the subtool menu, if not move to the bottom of the menu
    	   [If,pos < 8,
    		[VarSet,subToolPath,[StrMerge,"Tool:Sub Tool ",[Val,pos]]]	
    		,
    		[VarSet,subToolPath,"Tool:Sub Tool 7"]
    	    ]	
    		[If,[IModGet,#subToolPath]>=16,//if the subtool is visible
    			
    				//do the thing 
    		]			
         [If,[IsEnabled,Tool:SubTool:SelectDown],
    		  [IPress, Tool:SubTool:SelectDown]		   
    	    ,//else no select down so end of subtools & exit
    		   [LoopExit]
    	]//end if		
    ,pos]<br>

    Let me know if that doesn't work... 
  • floon
    Offline / Send Message
    floon greentooth
    Oh wow thank you!
    This is nothing I would have ever thought of.
    If I recall correctly this also happened with fewer (only ~5) stubtools though. I'll test it once I get home from work.
    I'll also upload a working script :)

    Thanks again, for taking the time!
  • nyx702
    Oh I just thought of something else. 
    [IModGet,[StrMerge,"Tool:Sub Tool:",#subTName<span>]</span>

    Could be checking as a string instead of the intended integer since you are using StrMrg. Trying setting the whole thing to a Var beforehand and using [Val, variable] to make sure its a number in the If statement. I didn't use Val in my example and it still works... but Val is good for error checking because it forces it to be an number. 
  • floon
    Offline / Send Message
    floon greentooth
    So i tried everything you suggested, this definitely made my code more future proof, yet the problem remains.
    Here is a gif to illustrate the behavior:



    Once I hide a subtool everything below is messed up, to a degree where even the state is displayed wrong, like so:



    Does that ring any bell with you?
    I uploaded  the working script (the main script & a checkbutton). If you can find some time, some brainpower would be much appreciated!
    https://drive.google.com/open?id=0B9kN79m1QbR7QmRTek5JbXJYVlE

    P.s:
    I even tried to save the state in a .zvr file before loading and reloading after, but with no luck :(.
  • nyx702
    So I spent awhile looking at this and testing some stuff... and I'm going to say calling the "PasteText" from the DLL is busted. I'm not surprised. If you replace that with any normal, non DLL command it works. I tried re-writing it from scratch with the same results you are seeing. That sucks because this is a pretty neat (hacky) way to rename things. You could try PMing Marcus and seeing if he knows about it. He has fixed things in the DLL for me before. 

    The only other way I know to rename things is by sending the active tool to the top of the stack and using [ToolSetPath,, newName]. You dont need to use the DLL for this either which makes everything simpler. 
  • floon
    Offline / Send Message
    floon greentooth
    Urgh that sucks, I feared that my code was not the problem here..

    Thank you so much though, for taking the time and get to the core of the problem!
    I will try to get a hold of Marcus and will post here if there are any news.

    As a last resort your idea sounds fine, but I’d hate to mix up the subtool order,..
  • nyx702
    I use two Routines to send the ST up, do the rename, then send it back down to where it was. If you were doing ALL subtools regardless of visibility if you send all of them to the top the order will remain the same once you loop over all of them.  

    [RoutineDef, ActiveUp,
    	[Loop,1000,
    	[If,[IsEnabled,Tool:SubTool:MoveUp],[IPress, Tool:SubTool:MoveUp],[LoopExit]]
    	,LoopNum]
    ]
    
    [RoutineDef, ActiveDown,
    	[Loop,LoopNum,
    	[IPress, Tool:SubTool:MoveDown]
    	]
    ]


  • floon
    Offline / Send Message
    floon greentooth
    That's a cool idea!
    I created a thread over at zbrushcentral, described the issue and will see if someone can make this work.
    But if nothing comes of it, I'll use your solution :)!
  • floon
    Offline / Send Message
    floon greentooth
    So Marcus took a look into it and reason was actually quite embarrassing,.. because it even was discribed that way in the documentation of the ZFileUtils.
    Having multiple subtools with the same name caused problems when rerun.
    Here is link to said post for the intressted reader/google user.
    http://www.zbrushcentral.com/showthread.php?206627-IModGet-problem&p=1207707#post1207707
    As a note to future me: "Read the fucking manual" :#

    Thanks again for taking the time and show me some tricks!
  • nyx702
    Oh! Well I totally missed that too so don't be too embarrassed.

    Using the IDs of the subtools seems like a better/faster way. I will have to integrate that in. SubtoolSelect and SubtoolGetActiveIndex are relatively new to the Zscript lexicon. Most of my script were written before ST indexes were a thing.   
Sign In or Register to comment.