Notifications
Clear all

[Closed] How can i write the maxscript?

Closed!ZZZZZZZZZZZZZZZZZZ

17 Replies

not entirely clear what you’re asking for…

Do you basically want a list of all objects that use a certain material / material with a certain texture map (presumably diffuse map, bitmap), but only if that material / map is used more than once in the scene?

1 Reply
(@sunboy69)
Joined: 10 months ago

Posts: 0

Yes you speak right very much! that’s the meaning!!
I want to find out the same diffuse,specular and bump map which some objs use it on the different material(multi/sub-obj)
The list contains:
Some different objs(use the same texture)—material(or multi/sub-obj material) on the some objs—repeated diffuse,specular and bump map.Bucause i just use the three type of maps!
Maybe i can use the texture to find out which materials use it,and the texutre is changeless!
When i find out,i can delete other materials,and use the only one on some objs!

Hi sunboy69!

Are you trying to find duplicated materials? if so, how would you know if it is duplicate? by having the same name? I know you#’re working with multi sub object materials, can you use the clean multi material utility?

There are many difficulties and pitfalls working with muklti materials that can make material scripts quite complex.

Regards,

Josh.

1 Reply
(@sunboy69)
Joined: 10 months ago

Posts: 0

ah!!Thanks for your advice j-man.

you could loop to all objects and get there materials or submaterials
if they got submaterials loop throu the submaterials
then you can access each materials maps
<Standard>.diffuseMap TextureMap
<Standard>.specularMap TextureMap
<Standard>.opacityMap TextureMap
<Standard>.bumpMap TextureMap

now you can make an array with the objects and there corresponding texturemaps and compare those

only an idea

Am i right to say that this is the procedure that is possible for you to take to solve your problem?

  1. Reading all material info that’s been used inside the scene
  2. Keep a record array of each and every map that’s been used in every slot. And recall the function in order to dive into the multilayer submaterial etc.
  3. Find out the item with equal or more than 2 counts, meaning they are duplicated.
  4. Display them.

Regards,
Sean

Yes, maybe you’re right!

I have a script that recurses through all the materials in the scene. Looking for blend materials


rollout ViewRoll "Set blend mask"
(
	radioButtons RBtnState Labels:#("on","off") default:2
	button btnS "selected Objects" across:3
	button btnM "material slot"
	button btnA "Everything"
	
	Local myState = false
	
	fn FindBlend m =
	(
		myState = (RBtnState.State == 1)
		c = (classOf m)
		case c of
		(
			Multimaterial: (for SubMat in m.materialList do FindBlend SubMat )
			Blend:( m.maskEnabled = myState )
			compositematerial:(for SubMat in m.materialList do FindBlend SubMat )
			DoubleSided:( FindBlend m.material1 ; FindBlend m.material2 )
			Lightscape_Mtl:( FindBlend m.baseMaterial)
			Shellac:( FindBlend m.shellacMtl1 ; FindBlend m.shellacMtl2 )
			Shell_Material:( FindBlend m.originalMaterial ; FindBlend m.bakedMaterial )
			TopBottom:(FindBlend m.topMaterial ; FindBlend m.bottomMaterial)
		)
	)
	
	on btnM pressed do
	(
		m = meditMaterials[activeMeditSlot]
		FindBlend m 
	)
	
	on btnS pressed do 
	(
		objList = (getCurrentSelection())
		for obj in objList do FindBlend obj.material
	)
		
	on btnA pressed do 
	(
		if scenematerials.count == 0 then
		(
			for obj in geometry do FindBlend obj.material	 
		)
		else 
		(
			for m in scenematerials do FindBlend m
		)
	)
)

if DS != undefined do closerolloutfloater DS
DS = NewRolloutFloater "" 300 100

addRollout ViewRoll DS

The trick here is in the the recursive function call … a function that calls itself … as it loops into the material

1 Reply
(@sunboy69)
Joined: 10 months ago

Posts: 0

Hi Kenzor! I’m very honoured that you help me to find the script,thanks!! but i’m mixed-up:
(1)The script i used in max8,9 is failing, it did’t have any reflection.
(2)The script looks like to use for blend materials, can it work accurately on Standard or multi/sub-obj material?
I’m not sure if it worked accurately for you!

Hi,

maybe the problem is in the way you’re detaching objects. If i detach objects i don’t get a repeated material.
What is your proceedure?

Josh.

1 Reply
(@sunboy69)
Joined: 10 months ago

Posts: 0

Eh“`Maybe this wasn’t important now

Well I have a script that finds shared maps, but if you have several maps pointing to same bitmap texture then it wont detect it, building such detection shouldn’t be too hard.

global findSharedMaps
try(DestroyDialog findSharedMaps)catch()

rollout findSharedMaps "Find Shared Maps" width:400 (
	-- Shared
	local foundMaps = #() 
	local foundParents = #() 

	-- Functions	
	fn gSubMaps map root = (
		if map != undefined then (
			local index = findItem foundMaps map
			if (index == 0) then (
				append foundMaps map
				append foundParents #(root)
			) else if findItem foundParents[index] root == 0 then (
				append foundParents[index] root
			)						
			showTextureMap root map false
			for i in 1 to getNumSubTexmaps map do gSubMaps (getSubTexmap map i) root
		)
	)

	fn gSubMatsMaps mat = (
		if mat != undefined then (			
			for i in 1 to getNumSubMtls mat do gSubMatsMaps (getSubMtl mat i)
			for i in 1 to getNumSubTexmaps mat do gSubMaps (getSubTexmap mat i) mat
		)
	)

	-- UI items
	button BUTTON_find "Find shared maps!"
	listbox LISTBOX_found "" height:20

	-- Events
	on BUTTON_find pressed do (
		foundMaps = #()
		foundParents = #()
		for i in meditMaterials where superClassOf i == Material do gSubMatsMaps i
		for i in sceneMaterials where superClassOf i == Material do gSubMatsMaps i
		local list = #()
		for i in 1 to foundMaps.count where foundParents[i].count > 1 do (
			local item = foundMaps[i].name + " : "
			for j in foundParents[i] do item = item + j.name + ", "
			append list item
		)
		format "list %
" list
		LISTBOX_found.items = list
	)
)

CreateDialog findSharedMaps
1 Reply
(@sunboy69)
Joined: 10 months ago

Posts: 0

Oh dear Bercon,You’re ingenious,the script was useful a certain extent, but there’re any issue i’m not understand:
(1)When i run the script,it would delete many texture on objs(contain repeated or not), notice: the maps on my objs were only diffuse map!
(2)There’re some repeated materials and textures that did’t display in the script list, and it showed incomplete…

I did’t know why?I hope you can help me to explain please. ^o^
However i must to thank you “Bercon”.
Thanks!!

Its the other way around. On the left you have the name of the map. And entries after it are the materials that use that map.

And my script shouldn’t do anything to the scene, it just lists the maps that are used in more than one material.

1 Reply
(@sunboy69)
Joined: 10 months ago

Posts: 0

If so ,but in my scene, there weren’t some maps named “Map #5”,“Map#7”,”Map#10…and so on, i didn’t know why?

And is it have an effect on multi/sub-obj ?

Page 1 / 2