ZBrushCentral

Import texture & Front view switch

Hello all, I need some help in creating two scripts.

First script.

  • Ask user to import texture and displacement map
  • Flip UV’s vertically on texture map and apply to active subtool
  • Flip UV’s vertically on displacement map, make alpha and apply to displacement map active subtool

There are other things that I need to do but I am sure it is easy enough for me to figure out.

My approach was to get the total count for items in the texture library and select the last one to avoid same name textures. I was trying to use [IGetMax[Texture:BrushTxtr]] but it would not return any values.

I also used a method I found on the forums to directly apply the texture using the file path however I couldn’t flip the UV once it was already applied to the subtool. What can I do to be able to import textures, flip them and apply them to the subtool?

Second Script,

  • Set new document width and height
  • resize document
  • Lock onto the front view of the subtool. (Mesh is always facing in the same axis)
  • expose
  • fit to screen
  • add materials
  • export

Most of this is pretty simple and what I really find tricky is the beginning part where I have to get the front view of the mesh. Is this possible?

Thanks in Advance,
J

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/nuts-bolts/

You can use the button path “Texture:Item Info” for the slider at the top of the Texture palette. You can then use this to get the name of the last texture loaded, and apply it to a model:

//set texture to last loaded
[ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]
//get the name of the texture
[VarSet,txtrName,[IGetTitle,Texture:Item Info]]
//trim off period at the end
[VarSet,txtrName,[StrExtract,txtrName,0,[StrLength,txtrName]-2]]
//apply map to current model:
[IPress,Tool:Texture Map:TextureMap]
[IClick,[StrMerge,“PopUp:”,#txtrName]]

In order to set a model’s rotation so that it is facing forwards you would use the TransformSet command so that the values are XRot = 0, YRot = 0 and ZRot = 0.

Thanks Marcus! Brilliant as always, one more thing, Once I have centered the model and applied the transforms how do I script pressing the ok button after the render window pops up?

Which render window? Can you post the code you’re using for rendering?

I’m fairly sure I created a macro to BPR then export.
Yeah, here.

//ZBRUSH MACRO - Recorded in ZBrush version 4.7
[IButton,???,“BPR then export passes”,
[IShowActions,0]
[IConfig,4.7]
[IPress,Render:BPR RenderPass:Render Best Preview]
[IShowActions,0]
//select a save location - file name will be used as the suffix
[VarSet,fpath,[FileNameAsk,“Photoshop(.psd)|.psd||”,RenderPass.psd ,“Please Save File…”]]
//exit if dialog cancelled
[If,[StrLength,fpath]==0,[Exit]]
//extract the path and name only
[VarSet,fpath,[FileNameExtract,fpath,3]]
//set the file name for the shaded pass export
[FileNameSetNext,[StrMerge,#fpath,"_shaded.psd"]]
[If,([StrFind,“Width=”,[IGetInfo,2219]]>-1),[IPress,2219]]//shaded
//depth export
[FileNameSetNext,[StrMerge,#fpath,"_depth.psd"]]
[If,([StrFind,“Width=”,[IGetInfo,2220]]>-1),[IPress,2220]]//depth
//shadow export
[FileNameSetNext,[StrMerge,#fpath,"_shadow.psd"]]
[If,([StrFind,“Width=”,[IGetInfo,2221]]>-1),[IPress,2221]]//shadow
//AO export
[FileNameSetNext,[StrMerge,#fpath,"_ao.psd"]]
[If,([StrFind,“Width=”,[IGetInfo,2222]]>-1),[IPress,2222]]//AO
//mask export
[FileNameSetNext,[StrMerge,#fpath,"_alpha.psd"]]
[If,([StrFind,“Width=”,[IGetInfo,2223]]>-1),[IPress,2223]]//mask
//Sss export
[FileNameSetNext,[StrMerge,#fpath,"_sss.psd"]]
[If,([StrFind,“Width=”,[IGetInfo,2301]]>-1),[IPress,2301]]//Sss
//Floor export
[FileNameSetNext,[StrMerge,#fpath,"_floor.psd"]]
[If,([StrFind,“Width=”,[IGetInfo,2302]]>-1),[IPress,2302]]//Floor
]//end of macro
Lots of files in link below.

So what I needed is a macro that would duplicate the model, expose, assign certain materials and then export a jpg using [Document:Export]. What we are creating here are thumbnails of a character side by side gray and colored.

Here is the bit of code I’ve been using. It all works fine just at the end after you press export it takes you to a preview dialogue box and then you have to manually press ok or cancel I thought [IKeyPress,13] would work but it does not.

[TransformSet,(Document:Width*.5),(Document:Height*.5),0,100,100,100,0,0,0]
[IPress,Transform:Fit]
[IPress,Tool:SubTool:Duplicate]
[IPress,Transform:Xpose]
[IUnPress,Tool:Texture Map:Texture On]
[IPress,Material:MatCap Gray]
[IPress,Draw:M]
[IPress,Color:FillObject]
[IPress,Material:SkinShade4]
[IPress,Render:Best]
[fileNameSetNext,thumbnail]
[IPress,Document:Export]
[IKeyPress,13]

One other thing Marcus the bit of code you posted a few days ago works but occasionally for some reason it does not import the texture and instead loads up the last image in the texture library. I’ve tried to reproduce the error but cant tell for sure whats causing it. Could it be large texture files? 20+ mb? This is what Im using

[VarDef, fileName,[FileNameAsk,

“JPG(.jpg)|.jpg|
PNG(.png)|.png|
TIFF(.tif)|.tif|
PSD(.psd)|.psd|”, , “Please select a file to load…”]]
[FileNameSetNext, fileName]
[IPress,Texture:Import]

[ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]
[VarSet,txtrName,[IGetTitle,Texture:Item Info]]
[VarSet,txtrName,[StrExtract,txtrName,0,[StrLength,txtrName]-2]]
[IPress,Texture:FlpV]
[IPress,Tool:Texture Map:TextureMap]
[IClick,[StrMerge,“PopUp:”,txtrName]]

For the export: unfortunately I don’t think there’s a way around the dialog, other than by using a different file format than JPG.

For the script error: ZBrush is failing to load the file. This is probably because of a bad file path. I think I’d check that the variable is getting the full pathe, including teh extension. I see that you have four file types - the zscript FileNameAsk used to only cope with three types, so it might be that one extension is getting incorrectly imterpreted. You could use a [Note] to check the value of the fileName variable. (Though note that backslashes won’t show in the Note.)

Hey Marcus, One thing I noticed about the code below is that it will import the texture however, if I want to make a change and update the texture in photoshop, save it under the same filename and use this script again, it will import the updated texture, however it will load the first texture it finds with that name which is not the updated version, because the updated version sits last on the list. How would I work around this?

[IButton, “texture test”,
[VarSet, fileName,[FileNameAsk,“JPG(.jpg)|.jpg|PNG(.png)|.png|PSD(.psd)|.psd|”,“Import Texture”]]
[If, [StrLength,fileName],
[FileNameSetNext, fileName]
[IPress,Texture:Import]
[ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]
[VarSet,txtrName,[IGetTitle,Texture:Item Info]]
[VarSet,txtrName,[StrExtract,txtrName,0,[StrLength,txtrName]-2]]
[IPress,Texture:FlpV]
[IPress,Tool:Texture Map:TextureMap]
[IClick,[StrMerge,“PopUp:”,txtrName]]

]

]

Yes, you will have problems with texture maps with the same name. There’s no simple way to solve that one but, depending on what you are doing, you may be able to use a different approach.

A while ago I wrote a macro that will refresh the texture on the model. You can download it here (and as it’s a zscript text file you can look at the code):

http://www.zbrushcentral.com/showthread.php?94752-Useful-small-ZScripts-and-Macros-for-ZBrush-4-amp-4R3&p=960631&viewfull=1#post960631

This doesn’t flip the texture map, so you’d have to do that first in Phostoshop before saving, or flip the UVs in ZBrush.

ok thanks marcus! youve been a big help!