Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Script to batch import Bitmaps and create material?

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
Anonymous
6495 Views, 15 Replies

Script to batch import Bitmaps and create material?

Anonymous
Not applicable

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 

0 Likes

Script to batch import Bitmaps and create material?

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 

Tags (3)
15 REPLIES 15
Message 2 of 16
drew.avis
in reply to: Anonymous

drew.avis
Autodesk
Autodesk

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"


Drew Avis
Content Experience Designer

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"


Drew Avis
Content Experience Designer
Message 3 of 16
Anonymous
in reply to: drew.avis

Anonymous
Not applicable

Cheers @drew.avis thanks for responding so quickly 

 

The script nearly works, just need a few tweaks, would you be able to:

  • Strip the ".gif" from filename? As otherwise I'd need to name my objects "[object_name].gif" for the script to work i.e. mybox.gif rather than mybox
  • Put an If..Then inside the second loop to check the selected object name against the filename? Because atm its assigning the last gif in the directory as the material to all the objects in the selection.

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 

 

0 Likes

Cheers @drew.avis thanks for responding so quickly 

 

The script nearly works, just need a few tweaks, would you be able to:

  • Strip the ".gif" from filename? As otherwise I'd need to name my objects "[object_name].gif" for the script to work i.e. mybox.gif rather than mybox
  • Put an If..Then inside the second loop to check the selected object name against the filename? Because atm its assigning the last gif in the directory as the material to all the objects in the selection.

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 

 

Message 4 of 16
drew.avis
in reply to: Anonymous

drew.avis
Autodesk
Autodesk
Accepted solution

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
Content Experience Designer

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
Content Experience Designer
Message 5 of 16
Anonymous
in reply to: drew.avis

Anonymous
Not applicable

@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

0 Likes

@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

Message 6 of 16
drew.avis
in reply to: Anonymous

drew.avis
Autodesk
Autodesk

@Anonymous Glad it helped.  Keep learning MAXScript, it creates a lot of possibilities!

 

Drew



Drew Avis
Content Experience Designer
0 Likes

@Anonymous Glad it helped.  Keep learning MAXScript, it creates a lot of possibilities!

 

Drew



Drew Avis
Content Experience Designer
Message 7 of 16
pproestos
in reply to: drew.avis

pproestos
Collaborator
Collaborator

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
)
)

Message 8 of 16
Anonymous
in reply to: pproestos

Anonymous
Not applicable
Hi Petros, unfortunately your question is beyond my knowledge, I’m a beginner at max coding. Sorry I couldn’t help. Hopefully someone else can answer.
Cheers

Hi Petros, unfortunately your question is beyond my knowledge, I’m a beginner at max coding. Sorry I couldn’t help. Hopefully someone else can answer.
Cheers
Message 9 of 16
udhayprakash111
in reply to: Anonymous

udhayprakash111
Explorer
Explorer

(
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.

0 Likes

(
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.

Message 10 of 16

udhayprakash111
Explorer
Explorer

See for screen shot

thth.jpg

See for screen shot

thth.jpg

Message 11 of 16
Milos.V
in reply to: udhayprakash111

Milos.V
Contributor
Contributor

I am trying to use the original script to 

  1. create standard (legacy) material with name based on texture or object name (both are the same name)
  2. assign png texture to diffuse slot (texture is the same name as object name)
  3. assign new material to the object
  4. there are over 1000 objects in the scene, doing this manually would be horrific.

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"

 

MilosV_0-1627463902458.png

 

0 Likes

I am trying to use the original script to 

  1. create standard (legacy) material with name based on texture or object name (both are the same name)
  2. assign png texture to diffuse slot (texture is the same name as object name)
  3. assign new material to the object
  4. there are over 1000 objects in the scene, doing this manually would be horrific.

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"

 

MilosV_0-1627463902458.png

 

Message 12 of 16
qw_zzz
in reply to: udhayprakash111

qw_zzz
Community Visitor
Community Visitor
Hi, thanks for the script great help!
is it possible to modify to use multi-sub while changing the material name based off the filename of the texture?
0 Likes

Hi, thanks for the script great help!
is it possible to modify to use multi-sub while changing the material name based off the filename of the texture?
Message 13 of 16
Anonymous
in reply to: udhayprakash111

Anonymous
Not applicable
Great script, works like a charm.
0 Likes

Great script, works like a charm.
Message 14 of 16
redarmygameplay
in reply to: drew.avis

redarmygameplay
Explorer
Explorer
Can you make this script for physical materials.. and load textures to corresponding slots? I mean to say defuse textures to diffuse map and normal textures to normal map slot something like that.
0 Likes

Can you make this script for physical materials.. and load textures to corresponding slots? I mean to say defuse textures to diffuse map and normal textures to normal map slot something like that.
Message 15 of 16
mdmowry
in reply to: Anonymous

mdmowry
Observer
Observer

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. 

 

1.jpg

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
)
)

 

0 Likes

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. 

 

1.jpg

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
)
)

 

Message 16 of 16
danZL2KU
in reply to: Anonymous

danZL2KU
Participant
Participant

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.

 

0 Likes

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.

Post to forums  

Autodesk Design & Make Report