Hi,
I have 200 bitmaps (.gif) I need to import each as its own material.
Does anyone have a batch script to do this?
I'd like the script to loop over the files in my directory and:
- create a standard material
- assign the gif (i.e. Wall-stone.gif) to the diffuse slot
- name the material with the gif filename i.e Wall-stone
A bonus would be if you also had a script to batch apply materials to objects i.e. I select a number of objects in my view then the script:
- loops over the objects and gets the object name i.e. Wall-stone, Wall-timber etc
- finds the material of the same name
- assigns the material to the object i.e. Wall-stone material to Wall-stone object
- 'Show shaded material in viewport' for all
I'm on Max 2016
thanks
Solved! Go to Solution.
Hi,
I have 200 bitmaps (.gif) I need to import each as its own material.
Does anyone have a batch script to do this?
I'd like the script to loop over the files in my directory and:
- create a standard material
- assign the gif (i.e. Wall-stone.gif) to the diffuse slot
- name the material with the gif filename i.e Wall-stone
A bonus would be if you also had a script to batch apply materials to objects i.e. I select a number of objects in my view then the script:
- loops over the objects and gets the object name i.e. Wall-stone, Wall-timber etc
- finds the material of the same name
- assigns the material to the object i.e. Wall-stone material to Wall-stone object
- 'Show shaded material in viewport' for all
I'm on Max 2016
thanks
Solved! Go to Solution.
Solved by drew.avis. Go to Solution.
Hi there, is something like this what you're looking for?
-- load gifs and create standard materials fn load_gifs_make_materials dir = ( files = getFiles dir for file in files do ( bm = openBitMap file bmt = bitmapTexture() bmt.bitmap = bm sm = StandardMaterial() sm.diffuseMap = bmt filename = filenameFromPath file sm.name = filename f = "'" + filename + "'" print f for n in $*f do ( print n n.material = sm showTextureMap n.material on ) ) ) load_gifs_make_materials @"C:[mypath]\*.gif"
Hi there, is something like this what you're looking for?
-- load gifs and create standard materials fn load_gifs_make_materials dir = ( files = getFiles dir for file in files do ( bm = openBitMap file bmt = bitmapTexture() bmt.bitmap = bm sm = StandardMaterial() sm.diffuseMap = bmt filename = filenameFromPath file sm.name = filename f = "'" + filename + "'" print f for n in $*f do ( print n n.material = sm showTextureMap n.material on ) ) ) load_gifs_make_materials @"C:[mypath]\*.gif"
Cheers @drew.avis thanks for responding so quickly
The script nearly works, just need a few tweaks, would you be able to:
I tried to do these but I'm a novice and I couldn't get it to work
Lastly why don't the new materials appear in the Material Editor? Is it possible to have them displayed there in a 10 x 10 grid?
thanks
Cheers @drew.avis thanks for responding so quickly
The script nearly works, just need a few tweaks, would you be able to:
I tried to do these but I'm a novice and I couldn't get it to work
Lastly why don't the new materials appear in the Material Editor? Is it possible to have them displayed there in a 10 x 10 grid?
thanks
Hi there, I tweaked the script a bit:
fn load_gifs_make_materials dir = ( files = getFiles dir x = 0 y = 0 sme_view = sme.GetView 1 -- get first view for file in files do ( bm = openBitMap file bmt = bitmapTexture() bmt.bitmap = bm sm = StandardMaterial() sm.diffuseMap = bmt filename = getFilenameFile file sm.name = filename print filename n = getNodeByName filename print n n.material = sm showTextureMap n.material on sme_view.CreateNode n.material [x,y] x = x + 100 if x > 1000 then ( x = 0; y = y + 100) ) ) load_gifs_make_materials @"c:[mypath]\*.gif"
Note that you don't need to have anything selected, the getNodeByName just finds the node with the same name and processes it.
Not sure about how the nodes will get laid out in the material editor, you can play with that bit to get it to do what you want.
Drew
Hi there, I tweaked the script a bit:
fn load_gifs_make_materials dir = ( files = getFiles dir x = 0 y = 0 sme_view = sme.GetView 1 -- get first view for file in files do ( bm = openBitMap file bmt = bitmapTexture() bmt.bitmap = bm sm = StandardMaterial() sm.diffuseMap = bmt filename = getFilenameFile file sm.name = filename print filename n = getNodeByName filename print n n.material = sm showTextureMap n.material on sme_view.CreateNode n.material [x,y] x = x + 100 if x > 1000 then ( x = 0; y = y + 100) ) ) load_gifs_make_materials @"c:[mypath]\*.gif"
Note that you don't need to have anything selected, the getNodeByName just finds the node with the same name and processes it.
Not sure about how the nodes will get laid out in the material editor, you can play with that bit to get it to do what you want.
Drew
@drew.avis you are an absolute legend! Thank you!
It works flawlessly, but also taught me a ton about MaxScripting - I've now re-written the script to create objects on the fly and assign the bitmaps. Thank you so much. Awesome.
cheers
@drew.avis you are an absolute legend! Thank you!
It works flawlessly, but also taught me a ton about MaxScripting - I've now re-written the script to create objects on the fly and assign the bitmaps. Thank you so much. Awesome.
cheers
@Anonymous Glad it helped. Keep learning MAXScript, it creates a lot of possibilities!
Drew
@Anonymous Glad it helped. Keep learning MAXScript, it creates a lot of possibilities!
Drew
Hello guys, I found this useful script but I dont know how to modify it.
So I run the script, I click on "diffuse" and select some png bitmaps.
Then I click on "masks" and I select same png bitmaps once again.
Then in Material Editor I see on sample slots that Standard Materials
are created with the same png as diffuse and opacity map.
My question is how to :
-Replace Standard material with Arnold Standard Surface material.
-Assign all png and their copies as "Base Color" and "Opacity"
to this Arnold Standard Surface material
-Especially to the png assigned to "Opacity" enable the:
Bitmap parameters->RGB Channel Ouput->Alpha as grey
And of course if I have 1000 pngs to convert, how
to insert them into a material library automatically?
Really thanks for any help.
Cheers.
Petros.
(
function getImages = ()
local DiffuseArr = #()
local MaskArr = #()
local MaterialArr = #()
rollout rollMaterials "Make Materials"
(
button btnDiffuse "get diffuse" width:150
button btnOpacity "get masks" width:150
button btnCreateMaterial "create materials in editor" width:150 tooltip:"create the materials in the editor, max 24"
on btnDiffuse pressed do
(
DiffuseArr = getImages()
btnDiffuse.text = "diffuse (" + DiffuseArr.count as string + ")"
)
on btnOpacity pressed do
(
MaskArr = getImages()
btnOpacity.text ="masks (" + MaskArr.count as string + ")"
)
on btnCreateMaterial pressed do
(
for i=1 to DiffuseArr.count do
(
mat = standard diffuseMap:(Bitmaptexture fileName:DiffuseArr[i]) name:(getFilenameFile DiffuseArr[i])
if MaskArr[i] != undefined do mat.opacityMap = (Bitmaptexture fileName:MaskArr[i])
if i < 25 do meditMaterials[i] = mat
)
)
on btnCreateLibrary pressed do
(
for i=1 to DiffuseArr.count do
(
lib = materialLibrary()
mat = standard diffuseMap:(Bitmaptexture fileName:DiffuseArr[i]) name:(getFilenameFile DiffuseArr[i])
if MaskArr[i] != undefined do mat.opacityMap = (Bitmaptexture fileName:MaskArr[i])
append lib mat
)
fileSaveAsMatLib()
)
)
createDialog rollMaterials style:#(#style_toolwindow,#style_sysmenu)
function getImages =
(
theDialog = dotNetObject "System.Windows.Forms.OpenFileDialog" --create a OpenFileDialog
theDialog.title = "Select Diffuse" --set the title
theDialog.Multiselect = true --allow multiple files to be selected
theDialog.Filter = "JPG (*.jpg)|*.jpg|All Files (*.*)|*.*" --specify the filter
theDialog.FilterIndex = 1 --set the filter drop-down list to All Files
result = theDialog.showDialog() --display the dialog, get result into variable
result.ToString() --when closed, convert the result to string
result.Equals result.OK --returns TRUE if OK was pressed, FALSE otherwise
result.Equals result.Cancel --returns TRUE if Cancel was pressed, FALSE otherwise
return theDialog.fileNames --the selected filenames will be returned as an array
)
)
Hello guys, I found this useful script but I dont know how to modify it.
So I run the script, I click on "diffuse" and select some png bitmaps.
Then I click on "masks" and I select same png bitmaps once again.
Then in Material Editor I see on sample slots that Standard Materials
are created with the same png as diffuse and opacity map.
My question is how to :
-Replace Standard material with Arnold Standard Surface material.
-Assign all png and their copies as "Base Color" and "Opacity"
to this Arnold Standard Surface material
-Especially to the png assigned to "Opacity" enable the:
Bitmap parameters->RGB Channel Ouput->Alpha as grey
And of course if I have 1000 pngs to convert, how
to insert them into a material library automatically?
Really thanks for any help.
Cheers.
Petros.
(
function getImages = ()
local DiffuseArr = #()
local MaskArr = #()
local MaterialArr = #()
rollout rollMaterials "Make Materials"
(
button btnDiffuse "get diffuse" width:150
button btnOpacity "get masks" width:150
button btnCreateMaterial "create materials in editor" width:150 tooltip:"create the materials in the editor, max 24"
on btnDiffuse pressed do
(
DiffuseArr = getImages()
btnDiffuse.text = "diffuse (" + DiffuseArr.count as string + ")"
)
on btnOpacity pressed do
(
MaskArr = getImages()
btnOpacity.text ="masks (" + MaskArr.count as string + ")"
)
on btnCreateMaterial pressed do
(
for i=1 to DiffuseArr.count do
(
mat = standard diffuseMap:(Bitmaptexture fileName:DiffuseArr[i]) name:(getFilenameFile DiffuseArr[i])
if MaskArr[i] != undefined do mat.opacityMap = (Bitmaptexture fileName:MaskArr[i])
if i < 25 do meditMaterials[i] = mat
)
)
on btnCreateLibrary pressed do
(
for i=1 to DiffuseArr.count do
(
lib = materialLibrary()
mat = standard diffuseMap:(Bitmaptexture fileName:DiffuseArr[i]) name:(getFilenameFile DiffuseArr[i])
if MaskArr[i] != undefined do mat.opacityMap = (Bitmaptexture fileName:MaskArr[i])
append lib mat
)
fileSaveAsMatLib()
)
)
createDialog rollMaterials style:#(#style_toolwindow,#style_sysmenu)
function getImages =
(
theDialog = dotNetObject "System.Windows.Forms.OpenFileDialog" --create a OpenFileDialog
theDialog.title = "Select Diffuse" --set the title
theDialog.Multiselect = true --allow multiple files to be selected
theDialog.Filter = "JPG (*.jpg)|*.jpg|All Files (*.*)|*.*" --specify the filter
theDialog.FilterIndex = 1 --set the filter drop-down list to All Files
result = theDialog.showDialog() --display the dialog, get result into variable
result.ToString() --when closed, convert the result to string
result.Equals result.OK --returns TRUE if OK was pressed, FALSE otherwise
result.Equals result.Cancel --returns TRUE if Cancel was pressed, FALSE otherwise
return theDialog.fileNames --the selected filenames will be returned as an array
)
)
(
function getImages = ()
local DiffuseArr = #()
local BumpArr = #()
local DisplaceArr = #()
local MaterialArr = #()
rollout rollMaterials "Make Materials" width:200 height:175
(
Group "Maps"
(
button btnDiffuse "Browse Diffuse Maps" width:175 align:#center
button btnDisplace "Browse Displacment Maps" width:175 align:#center
)
button btnCreateMaterial "create materials in editor" width:175 align:#center
button btnCreateMateriallibrary "create materials in Mat Library" width:175 align:#center
on btnDiffuse pressed do
(
DiffuseArr = getImages()
btnDiffuse.text = "Diffuse - " + DiffuseArr.count as string + " Files"
)
on btnDisplace pressed do
(
DisplaceArr = getImages()
btnDiffuse.text = "Diffuse - " + DisplaceArr.count as string + " Files"
)
on btnCreateMaterial pressed do
(
for i=1 to DiffuseArr.count do
(
meditMaterials[i] = VRayMtl texmap_diffuse:(Bitmaptexture fileName:DiffuseArr[i])
)
)
on btnCreateMateriallibrary pressed do
(
for i=1 to DiffuseArr.count do
(
mat = VRayMtl texmap_diffuse:(Bitmaptexture fileName:DiffuseArr[i]) texmap_displacement:(Bitmaptexture fileName:DisplaceArr[i]) name:(getFilenameFile DiffuseArr[i])
append currentMaterialLibrary mat
)
)
)
createDialog rollMaterials style:#(#style_toolwindow,#style_sysmenu)
function getImages =
(
theDialog = dotNetObject "System.Windows.Forms.OpenFileDialog" --create a OpenFileDialog
theDialog.title = "Select Diffuse" --set the title
theDialog.Multiselect = true --allow multiple files to be selected
theDialog.Filter = "JPG (*.jpg)|*.jpg|All Files (*.*)|*.*" --specify the filter
theDialog.FilterIndex = 1 --set the filter drop-down list to All Files
result = theDialog.showDialog() --display the dialog, get result into variable
result.ToString() --when closed, convert the result to string
result.Equals result.OK --returns TRUE if OK was pressed, FALSE otherwise
result.Equals result.Cancel --returns TRUE if Cancel was pressed, FALSE otherwise
return theDialog.fileNames --the selected filenames will be returned as an array
)
)
This code is altered to suit vray. In order to suit Arnold please use macrorecorder to create steps for creating Arnold material from that code one can easily tweak its parameter to suit your needs. Hope this helps.
(
function getImages = ()
local DiffuseArr = #()
local BumpArr = #()
local DisplaceArr = #()
local MaterialArr = #()
rollout rollMaterials "Make Materials" width:200 height:175
(
Group "Maps"
(
button btnDiffuse "Browse Diffuse Maps" width:175 align:#center
button btnDisplace "Browse Displacment Maps" width:175 align:#center
)
button btnCreateMaterial "create materials in editor" width:175 align:#center
button btnCreateMateriallibrary "create materials in Mat Library" width:175 align:#center
on btnDiffuse pressed do
(
DiffuseArr = getImages()
btnDiffuse.text = "Diffuse - " + DiffuseArr.count as string + " Files"
)
on btnDisplace pressed do
(
DisplaceArr = getImages()
btnDiffuse.text = "Diffuse - " + DisplaceArr.count as string + " Files"
)
on btnCreateMaterial pressed do
(
for i=1 to DiffuseArr.count do
(
meditMaterials[i] = VRayMtl texmap_diffuse:(Bitmaptexture fileName:DiffuseArr[i])
)
)
on btnCreateMateriallibrary pressed do
(
for i=1 to DiffuseArr.count do
(
mat = VRayMtl texmap_diffuse:(Bitmaptexture fileName:DiffuseArr[i]) texmap_displacement:(Bitmaptexture fileName:DisplaceArr[i]) name:(getFilenameFile DiffuseArr[i])
append currentMaterialLibrary mat
)
)
)
createDialog rollMaterials style:#(#style_toolwindow,#style_sysmenu)
function getImages =
(
theDialog = dotNetObject "System.Windows.Forms.OpenFileDialog" --create a OpenFileDialog
theDialog.title = "Select Diffuse" --set the title
theDialog.Multiselect = true --allow multiple files to be selected
theDialog.Filter = "JPG (*.jpg)|*.jpg|All Files (*.*)|*.*" --specify the filter
theDialog.FilterIndex = 1 --set the filter drop-down list to All Files
result = theDialog.showDialog() --display the dialog, get result into variable
result.ToString() --when closed, convert the result to string
result.Equals result.OK --returns TRUE if OK was pressed, FALSE otherwise
result.Equals result.Cancel --returns TRUE if Cancel was pressed, FALSE otherwise
return theDialog.fileNames --the selected filenames will be returned as an array
)
)
This code is altered to suit vray. In order to suit Arnold please use macrorecorder to create steps for creating Arnold material from that code one can easily tweak its parameter to suit your needs. Hope this helps.
See for screen shot
See for screen shot
I am trying to use the original script to
When I try and use the original script I get below error. I modified it as per below:
fn load_gifs_make_materials dir = (
files = getFiles dir
x = 0
y = 0
sme_view = sme.GetView 1 -- get first view
for file in files do (
bm = openBitMap file
bmt = bitmapTexture()
bmt.bitmap = bm
sm = StandardMaterial()
sm.diffuseMap = bmt
filename = getFilenameFile file
sm.name = filename
print filename
n = getNodeByName filename
print n
n.material = sm
showTextureMap n.material on
sme_view.CreateNode n.material [x,y]
x = x + 100
if x > 1000 then ( x = 0; y = y + 100)
)
)
load_gifs_make_materials @"D:\Temp Projects\*.png"
I am trying to use the original script to
When I try and use the original script I get below error. I modified it as per below:
fn load_gifs_make_materials dir = (
files = getFiles dir
x = 0
y = 0
sme_view = sme.GetView 1 -- get first view
for file in files do (
bm = openBitMap file
bmt = bitmapTexture()
bmt.bitmap = bm
sm = StandardMaterial()
sm.diffuseMap = bmt
filename = getFilenameFile file
sm.name = filename
print filename
n = getNodeByName filename
print n
n.material = sm
showTextureMap n.material on
sme_view.CreateNode n.material [x,y]
x = x + 100
if x > 1000 then ( x = 0; y = y + 100)
)
)
load_gifs_make_materials @"D:\Temp Projects\*.png"
I modified the script by @udhayprakash111 to include a few extra things like adding the materials (unlimited!) directly to the current SME view. All of them currently show up at the 0,0 point of the view - sort manually as needed.
SCRIPT here:
(
function getImages = ()
local DiffuseArr = #()
local MaskArr = #()
local MaterialArr = #()
rollout rollMaterials "Make Materials"
(
button btnDiffuse "get diffuse" width:200
button btnClrDiffuse "clear diffuse" width:200
button btnOpacity "get masks" width:200
button btnClrOpacity "clear masks" width:200
button btnCreateMaterial "create mats in editor (24)" width:200 tooltip:"create the materials in the editor, max 24"
button btnCreateSMEmats "create mats in SME (UNLIM)" width:200 tooltip:"create the materials in SME"
on btnDiffuse pressed do
(
DiffuseArr = getImages()
btnDiffuse.text = "diffuse (" + DiffuseArr.count as string + ")"
)
on btnOpacity pressed do
(
MaskArr = getImages()
btnOpacity.text ="masks (" + MaskArr.count as string + ")"
)
on btnClrDiffuse pressed do
(
DiffuseArr = ()
btnDiffuse.text = "get diffuse"
)
on btnClrOpacity pressed do
(
MaskArr = ()
btnOpacity.text ="get masks"
)
on btnCreateMaterial pressed do
(
for i=1 to DiffuseArr.count do
(
mat = standard diffuseMap:(Bitmaptexture fileName:DiffuseArr[i]) name:(getFilenameFile DiffuseArr[i])
if MaskArr[i] != undefined do mat.opacityMap = (Bitmaptexture fileName:MaskArr[i])
if i < 25 do meditMaterials[i] = mat
)
)
on btnCreateSMEmats pressed do
(
sme.Open()
NewView = sme.getView(sme.activeView)
for i=1 to DiffuseArr.count do
(
mat = standard diffuseMap:(Bitmaptexture fileName:DiffuseArr[i]) name:(getFilenameFile DiffuseArr[i])
if MaskArr[i] != undefined do mat.opacityMap = (Bitmaptexture fileName:MaskArr[i])
NewView.CreateNode mat[0,0]
)
)
)
createDialog rollMaterials width:250 style:#(#style_toolwindow,#style_sysmenu)
function getImages =
(
theDialog = dotNetObject "System.Windows.Forms.OpenFileDialog" --create a OpenFileDialog
theDialog.title = "Select Diffuse" --set the title
theDialog.Multiselect = true --allow multiple files to be selected
theDialog.Filter = "JPG (*.jpg)|*.jpg|All Files (*.*)|*.*" --specify the filter
theDialog.FilterIndex = 1 --set the filter drop-down list to All Files
result = theDialog.showDialog() --display the dialog, get result into variable
result.ToString() --when closed, convert the result to string
result.Equals result.OK --returns TRUE if OK was pressed, FALSE otherwise
result.Equals result.Cancel --returns TRUE if Cancel was pressed, FALSE otherwise
return theDialog.fileNames --the selected filenames will be returned as an array
)
)
I modified the script by @udhayprakash111 to include a few extra things like adding the materials (unlimited!) directly to the current SME view. All of them currently show up at the 0,0 point of the view - sort manually as needed.
SCRIPT here:
(
function getImages = ()
local DiffuseArr = #()
local MaskArr = #()
local MaterialArr = #()
rollout rollMaterials "Make Materials"
(
button btnDiffuse "get diffuse" width:200
button btnClrDiffuse "clear diffuse" width:200
button btnOpacity "get masks" width:200
button btnClrOpacity "clear masks" width:200
button btnCreateMaterial "create mats in editor (24)" width:200 tooltip:"create the materials in the editor, max 24"
button btnCreateSMEmats "create mats in SME (UNLIM)" width:200 tooltip:"create the materials in SME"
on btnDiffuse pressed do
(
DiffuseArr = getImages()
btnDiffuse.text = "diffuse (" + DiffuseArr.count as string + ")"
)
on btnOpacity pressed do
(
MaskArr = getImages()
btnOpacity.text ="masks (" + MaskArr.count as string + ")"
)
on btnClrDiffuse pressed do
(
DiffuseArr = ()
btnDiffuse.text = "get diffuse"
)
on btnClrOpacity pressed do
(
MaskArr = ()
btnOpacity.text ="get masks"
)
on btnCreateMaterial pressed do
(
for i=1 to DiffuseArr.count do
(
mat = standard diffuseMap:(Bitmaptexture fileName:DiffuseArr[i]) name:(getFilenameFile DiffuseArr[i])
if MaskArr[i] != undefined do mat.opacityMap = (Bitmaptexture fileName:MaskArr[i])
if i < 25 do meditMaterials[i] = mat
)
)
on btnCreateSMEmats pressed do
(
sme.Open()
NewView = sme.getView(sme.activeView)
for i=1 to DiffuseArr.count do
(
mat = standard diffuseMap:(Bitmaptexture fileName:DiffuseArr[i]) name:(getFilenameFile DiffuseArr[i])
if MaskArr[i] != undefined do mat.opacityMap = (Bitmaptexture fileName:MaskArr[i])
NewView.CreateNode mat[0,0]
)
)
)
createDialog rollMaterials width:250 style:#(#style_toolwindow,#style_sysmenu)
function getImages =
(
theDialog = dotNetObject "System.Windows.Forms.OpenFileDialog" --create a OpenFileDialog
theDialog.title = "Select Diffuse" --set the title
theDialog.Multiselect = true --allow multiple files to be selected
theDialog.Filter = "JPG (*.jpg)|*.jpg|All Files (*.*)|*.*" --specify the filter
theDialog.FilterIndex = 1 --set the filter drop-down list to All Files
result = theDialog.showDialog() --display the dialog, get result into variable
result.ToString() --when closed, convert the result to string
result.Equals result.OK --returns TRUE if OK was pressed, FALSE otherwise
result.Equals result.Cancel --returns TRUE if Cancel was pressed, FALSE otherwise
return theDialog.fileNames --the selected filenames will be returned as an array
)
)
Hi
I have tried to follow this bit but have no knowledge of scripting.
I am trying to do part of this. I already have my materials in a library. I have a scene full of objects with matching names to those materials in the library.
I am looking for a script which will look for a match between the objects in my scene (name) and the materials in my library (name) and if a match is found then apply those materials.
This would enable me to apply thousands of materials at one click.
Thanks.
Hi
I have tried to follow this bit but have no knowledge of scripting.
I am trying to do part of this. I already have my materials in a library. I have a scene full of objects with matching names to those materials in the library.
I am looking for a script which will look for a match between the objects in my scene (name) and the materials in my library (name) and if a match is found then apply those materials.
This would enable me to apply thousands of materials at one click.
Thanks.
Can't find what you're looking for? Ask the community or share your knowledge.