ZBrushCentral

Question: ZScript wait for big Texture import

Hello,

i have following zscript:

//RECORDED ZSCRIPT 2022
[IButton,???,"Press to play this ZScript. ZScript can be aborted at anytime by pressing the ëescí key.",
[IReset,,2022]
[FileNameSetNext,"C:\models\example.obj"][IPress,Tool:Import]
[CanvasStroke,(ZObjStrokeV02n238=H40EV]
[IPress,Transform: Edit]
[FileNameSetNext,"C:\models\example.png"][IPress,Texture:Import]
[IPress,Texture:example]
[IPress,Texture:Flpv]
[IPress,Tool:Texture Map:TextureMap]
[IPress,Material:SkinShade4]
[FileNameSetNext,"C:\models\example.zpr"][IPress,File:Save As]
]/*End of ZScript*/

The problem is, zbrush saves the project even though the texture hasn’t been imported yet. How can I wait for the import to finish and then save?

Hi,

Welcome to ZBC! :slight_smile:

You can probably make this work by using a loop with a delay. Try this:

    //RECORDED ZSCRIPT 2022
    [IButton,???,"Press to play this ZScript. ZScript can be aborted at anytime by pressing the ëescí key.",
    [IReset,,2022]
    [FileNameSetNext,"C:\models\example.obj"][IPress,Tool:Import]
[CanvasClick,document:width/2,document:height/4,document:width/2,document:height/2]
    [IPress,Transform: Edit]
    [VarSet,TxrNo,[IGetMax,Texture:Item Info]]//find out how many texture in palette
    [FileNameSetNext,"C:\models\example.png"][IPress,Texture:Import]
    [Loop,10000,
       [If, [IGetMax,Texture:Item Info] > TxrNo, //check if texture loaded
          [LoopExit]
       ]
       [Delay,0.1]
    ]
    [ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]//select last loaded texture
    [IPress,Texture:Flpv]
    [IPress,Tool:Texture Map:TextureMap]
    [IPress,Material:SkinShade4]
    [FileNameSetNext,"C:\models\example.zpr"][IPress,File:Save As]
    ]/*End of ZScript*/

I’ve made a couple of changes so that the name of the texture map is not important to it being selected.

HTH,
Marcus

Hi Marcus,

thank you very much for your repsonse, but unfortunately it still not work.

I use this script:

//RECORDED ZSCRIPT 2022
[IButton,???,"Press to play this ZScript. ZScript can be aborted at anytime by pressing the ëescí key.",
[IReset,,2022]
[FileNameSetNext,"C:\example\12221_Cat_v1_l3.obj"][IPress,Tool:Import]
[CanvasClick,document:width/2,document:height/4,document:width/2,document:height/2]
    [IPress,Transform: Edit]
    [VarSet,TxrNo,[IGetMax,Texture:Item Info]]//find out how many texture in palette
    [FileNameSetNext,"C:\example\Cat_diffuse.jpg"][IPress,Texture:Import]
    [Loop,10000,
       [If, [IGetMax,Texture:Item Info] > TxrNo, //check if texture loaded
          [LoopExit]
       ]
       [Delay,0.1]
    ]
    [ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]//select last loaded texture
    [IPress,Texture:Flpv]
    [IPress,Tool:Texture Map:TextureMap]
    [IPress,Material:SkinShade4]
[FileNameSetNext,"C:\example\Cat.zpr"][IPress,File:Save As]
]/*End of ZScript*/

But object is still not textured.:

Ah, OK, I didn’t realize what you wanted. That needs a little extra code. Try this:

//RECORDED ZSCRIPT 2022
[IButton,???,"Press to play this ZScript. ZScript can be aborted at anytime by pressing the ëescí key.",
[IReset,,2022]
[FileNameSetNext,"C:\example\12221_Cat_v1_l3.obj"][IPress,Tool:Import]
[CanvasClick,document:width/2,document:height/4,document:width/2,document:height/2]
    [IPress,Transform: Edit]
    [VarSet,TxrNo,[IGetMax,Texture:Item Info]]//find out how many texture in palette
    [FileNameSetNext,"C:\example\Cat_diffuse.jpg"][IPress,Texture:Import]
    [Loop,10000,
       [If, [IGetMax,Texture:Item Info] > TxrNo, //check if texture loaded
          [LoopExit]
       ]
       [Delay,0.1]
    ]
    [ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]//select last loaded texture
   [VarSet,newTxr,[IGetTitle,Texture:Current Texture]]
   [IPress,Texture:Flpv]
   [Delay,0.2]
   [IPress,Tool:Texture Map:TextureMap]
   [IPress,[StrMerge,"PopUp:",[Var,newTxr]]]
   [IPress,Material:SkinShade4]
[FileNameSetNext,"C:\example\Cat.zpr"][IPress,File:Save As]
]/*End of ZScript*/

Marcus

1 Like

I think i have found the “Bug”.

If i open ZBrush and execute Script. Then the texture is not apply to model.
But if i execute the same script second time, then the texture if apply.

Is this a ZBrush bug? Here the Video: Video

Do you have a idea? This command works only if i execute script twice. If i open zbrush and execute script … it not works

This is one of those things that can be infuriating about zscript. Try this version. I’ve stripped things down a bit. This works OK for me.

//RECORDED ZSCRIPT 2022
[IButton,???,"Press to play this ZScript. ZScript can be aborted at anytime by pressing the ëescí key.",
[FileNameSetNext,"C:\example\12221_Cat_v1_l3.obj"][IPress,Tool:Import]
[CanvasClick,document:width/2,document:height/4,document:width/2,document:height/2]
    [IPress,Transform: Edit]
    [VarSet,TxrNo,[IGetMax,Texture:Item Info]]//find out how many texture in palette
    [FileNameSetNext,"C:\example\Cat_diffuse.jpg"][IPress,Texture:Import]
   [ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]//select last loaded texture
   [VarSet,newTxr,[IGetTitle,Texture:Current Texture]]
   [IPress,Texture:Flpv]  
   [IPress,Tool:Texture Map:TextureMap]
   [IClick,[StrMerge,"PopUp:",[Var,newTxr]]]
   [IPress,Material:SkinShade4]
[FileNameSetNext,"C:\example\Cat.zpr"][IPress,File:Save As]
]/*End of ZScript*/
1 Like

Thank you it works now! Only because you remove [IReset,,2022] ?

Great! No, I don’t think it was [IReset], though I didn’t actually test that. I removed that because I doubted you needed it. I think probably using [IClick] instead of [IPress] for the popup did it. ZScript is full of quirks like that! (Sometimes it involves infuriating trial and error…)

-Marcus