Script Speed

I have written a script which will do something like this:

Detach faces applied with material whose name ends with "_alpha" (material name) to new objects, and put those new objects inside a group called "Alpha_blending_mesh". 

The script is running perfectly fine and doing exactly what I intend it to do. But the problem is it is running fast only the first time....from the next time it is taking too long (specially for complex scenes with too many objects).....again if I restart max it is running fast for the first time. I am not sure what is happening once I run the script for the first time....which is making  it slow from the next attempt!! I have tried gc()....clearundobuffer()...nothing is working!! I have saved the files after I ran the script once....restarted max and ran it again...it again works fast for the first time....so the problem is not in the file...something is eating up the memory after the first run!! 

I have written this by following this forum but since it is my first script it might look very clumpsy and funny :P.....here is the script:

(

undo off

(

 

 

-- delete previous groups named "Alpha_blending_mesh"

objgroup = #()

for o in helpers do

(

if o.name == "Alpha_blending_mesh" then

(

append objgroup o

)

)

 

(

if objgroup.count != 0 then

 

(

for i = 1 to objgroup.count do

(

ExplodeGroup $Alpha_blending_mesh

)

)

 

)

-- delete previous groups named "Alpha_blending_mesh"

 

 

 

 

--will merge all vertices with threshold 0.001 if the obj is not inside a group

fn weldverts obj =

(

result = isGroupMember obj

if result == false do

(

$.weldThreshold = 0.001

polyop.weldVertsByThreshold obj #All

)

)

  --will merge all vertices with threshold 0.001 if the obj is not inside a group 

 

 

 

 

 

-- Collect objects from scene in working list

workingObject = #()

 

for o in Geometry do

(

if classof o != bonegeometry do

(

append workingObject o

)

)

-- Collect objects from scene in working list

 

 

 

fn Singlemat obj =

(

mat = obj.material

TextureFileName = "notexture"

if (classof obj != bonegeometry) and (mat != undefined) and classof mat.diffuseMap == Bitmaptexture do

(

stringSS = mat.name

stringcount = stringSS.count

if stringcount > 6 then

(

TextureName = substring stringSS (stringcount - 5) ((stringcount - 5) + 6) 

)

 

if TextureName == "_alpha" do

(

objname = obj.name

stringTT = objname as string

stringTTcount = stringTT.count

if stringTTcount > 6 then

(

ObjnameTT = substring stringTT (stringTTcount - 5) ((stringTTcount - 5) + 6)

)

if ObjnameTT != "_alpha" do

(

obj.name = objname +"_alpha" 

)

 

)

 

)

 

)

 

fn detachFBI obj = 

(

objname = obj.name

ids = obj.material.materialIDList 

 

for id in ids do

(

obj.selectbymaterial id 

_faceSel = polyOp.getFaceSelection obj

 

polyOp.detachFaces obj _faceSel delete:true asNode:true name: (objname +"_tempdelface")

)

 

select $*_tempdelface*

$.name = objname

)

 

-- Run though all objects in array and detach them

for o in workingObject do

(mat = o.material

if (mat != undefined) and (classof mat == Multimaterial) do 

(

select o

detachFBI o

delete o

)

)

-- Run though all objects in array and detach them

 

 

 

 

--assigning single material to all object (removing unused multimaterials)

for o in geometry where isKindOf o.material multimaterial and (classof o != bonegeometry) do 

(

-- Get face material ID from face 1

local id = getFaceMatID o.Mesh 1

-- Assign that material

o.material = o.material[id]

)

--assigning single material to all object (removing unused multimaterials)

 

 

 

 

-- Run though all objects and check for "_alpha" in diffuse map, rename objets as *"_alpha"

for g in geometry do

(

select g

Singlemat g

)

-- Run though all objects and check for "_alpha" in diffuse map, rename objets as *"_alpha"

 

 

 

--group as "Alpha_blending_mesh"

clearselection()

select $*_alpha

 

if $ != undefined do

(

group selection name:"Alpha_blending_mesh"

)

--group as "Alpha_blending_mesh"

 

 

 

--attaching same named objects and welding vertices by 0.001 thresold 

 

newworking = #()

 

for o in geometry do

(

if classof o == editable_poly and classof o != bonegeometry do

(

append newworking o

)

)

 

i = 1

 

while i <= newworking.count do

(

b = newworking[i]

j = i + 1

while j<= newworking.count do

(

if (newworking[j].name == b.name) then

(

b.attach (newworking[j]) b

deleteItem newworking j

select b

weldverts b

)

else

(

j = j +1

)

)

 

i = i + 1

)

--attaching same named objects and welding vertices by 0.001 thresold 

 

 

--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"

groupName = "Alpha_blending_mesh"

grp = getNodeByName groupName

if isValidNode grp and isGroupHead grp do

(

select $Alpha_blending_mesh

)

toolmode.commandmode = #move

setCommandPanelTaskMode mode:#modify

--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"

)

 

 

)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

I not tried the script. Put

I not tried the script.
Put locals weldbythresh, detachF and getMatID inside "on btn pressed do" event.

barigazy

barigazy's picture

Try this code

I add some stuff in your code.Need to optimize more but not have
time right now.

(
	if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode mode:#create
	undo off
	(
		-- delete previous groups named "Alpha_blending_mesh"
		local objgroup = #()
		local workingObject = #()
		local newworking = #()
		for o in helpers where o.name == "Alpha_blending_mesh" do append objgroup o
		if objgroup.count != 0 do for i = 1 to objgroup.count do ExplodeGroup $Alpha_blending_mesh
		-- delete previous groups named "Alpha_blending_mesh"
		--will merge all vertices with threshold 0.001 if the obj is not inside a group
		fn weldverts obj =
		(
			local result = isGroupMember obj
			if result == false do
			(
				$.weldThreshold = 0.001
				polyop.weldVertsByThreshold obj #All
			)
		)
		  --will merge all vertices with threshold 0.001 if the obj is not inside a group 
		-- Collect objects from scene in working list
		for o in Geometry where not isKindOf o bonegeometry do append workingObject o
 
		-- Collect objects from scene in working list
		fn Singlemat obj =
		(
			local mat = obj.material
			local TextureFileName = "notexture"
			if (classof obj != bonegeometry) and (mat != undefined) and classof mat.diffuseMap == Bitmaptexture do
			(
				local stringSS = mat.name
				local stringcount = stringSS.count
				if stringcount > 6 do (TextureName = substring stringSS (stringcount - 5) ((stringcount - 5) + 6))
				if TextureName == "_alpha" do
				(
					local objname = obj.name
					local stringTT = objname as string
					local stringTTcount = stringTT.count
					if stringTTcount > 6 then (ObjnameTT = substring stringTT (stringTTcount - 5) ((stringTTcount - 5) + 6))
					if ObjnameTT != "_alpha" do (obj.name = objname +"_alpha")
				)
			)
		)
		fn detachFBI obj = 
		(
			local objname = obj.name
			local ids = obj.material.materialIDList
			local detach = polyOp.detachFaces
			for id in ids do
			(
				obj.selectbymaterial id 
				_faceSel = obj.selectedfaces as bitarray
				detach obj _faceSel delete:true asNode:true name: (objname +"_tempdelface")
			)
			select $*_tempdelface*
			$.name = objname
		)
		-- Run though all objects in array and detach them
		for o in workingObject where (o.material != undefined) and (classof mat == Multimaterial) do (detachFBI o ; delete o)
		-- Run though all objects in array and detach them
		--assigning single material to all object (removing unused multimaterials)
		for o in geometry where isKindOf o.material multimaterial and (classof o != bonegeometry) do 
		(
			-- Get face material ID from face 1
			local id = getFaceMatID o.Mesh 1
			-- Assign that material
			o.material = o.material[id]
		)
		--assigning single material to all object (removing unused multimaterials)
		-- Run though all objects and check for "_alpha" in diffuse map, rename objets as *"_alpha"
		for g in geometry do (Singlemat g)
		-- Run though all objects and check for "_alpha" in diffuse map, rename objets as *"_alpha"
		--group as "Alpha_blending_mesh"
		clearselection()
		select $*_alpha
		if $ != undefined do (	group selection name:"Alpha_blending_mesh")
		--group as "Alpha_blending_mesh"
		--attaching same named objects and welding vertices by 0.001 thresold 
 
		for o in geometry where  classof o == editable_poly and classof o != bonegeometry do append newworking o
		i = 1
		while i <= newworking.count do
		(
			b = newworking[i]
			j = i + 1
			while j<= newworking.count do
			(
				if not (newworking[j].name == b.name) then (j = j +1) else
				(
					b.attach (newworking[j]) b
					deleteItem newworking j
					select b
					weldverts b
				)
			)
			i = i + 1
		)
		--attaching same named objects and welding vertices by 0.001 thresold 
		--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"
		groupName = "Alpha_blending_mesh"
		grp = getNodeByName groupName
		if isValidNode grp and isGroupHead grp do (select $Alpha_blending_mesh)
		toolmode.commandmode = #move
		setCommandPanelTaskMode mode:#modify
		--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"
		free objgroup ; free workingObject ; free newworking
	)
)

barigazy

Goonda's picture

Its working fast now....but

Its working fast now....but something with the material assignment gone wrong.....lets see if I can debug that!! Thanks a lot!!

Only one question....do we always need to mention "local" for local variables....I thought it takes local automatically...unless we mention it as "global"??

barigazy's picture

To better undertand local and

To better undertand local and global variables read this
http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=fil...

barigazy

kimarotta's picture

I tried to optimize a bit by

I tried to optimize, I deleting the actions selection ... over the script of Barigazy ...

(
	if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode mode:#create
	undo off
	(
		--- Variables
		local objgroup = #()
		local workingObject = #()
		local newworking = #()
 
		--- Functions
		fn weldverts obj =
		(
			local result = isGroupMember obj
			if result == false do
			(
				obj.weldThreshold = 0.001
				polyop.weldVertsByThreshold obj #All
			)
		)
		fn Singlemat obj =
		(
			local mat = obj.material
			local TextureFileName = "notexture"
			if (classof obj != bonegeometry) and (mat != undefined) and classof mat.diffuseMap == Bitmaptexture do
			(
				local stringSS = mat.name
				local stringcount = stringSS.count
				if stringcount > 6 do (TextureName = substring stringSS (stringcount - 5) ((stringcount - 5) + 6))
				if TextureName == "_alpha" do
				(
					local objname = obj.name
					local stringTT = objname as string
					local stringTTcount = stringTT.count
					if stringTTcount > 6 then (ObjnameTT = substring stringTT (stringTTcount - 5) ((stringTTcount - 5) + 6))
					if ObjnameTT != "_alpha" do (obj.name = objname +"_alpha")
				)
			)
		)
		fn detachFBI obj = 
		(
			local objname = obj.name
			local ids = obj.material.materialIDList
			local detach = polyOp.detachFaces
			for id in ids do
			(
				obj.selectbymaterial id 
				_faceSel = obj.selectedfaces as bitarray
				detach obj _faceSel delete:true asNode:true name: (objname +"_tempdelface")
			)
			tempDelFaces = for o in objects where matchPattern (o.name) pattern:"*_alpha" collect o
			tempDelFaces.name = objname
		)
 
		--- Script
		for o in helpers where o.name == "Alpha_blending_mesh" do append objgroup o
		if objgroup.count != 0 do for i = 1 to objgroup.count do ExplodeGroup $Alpha_blending_mesh
		for o in Geometry where not isKindOf o bonegeometry do append workingObject o
 		for o in workingObject where (o.material != undefined) and (classof mat == Multimaterial) do (detachFBI o ; delete o)
		for o in geometry where isKindOf o.material multimaterial and (classof o != bonegeometry) do 
		(
			local id = getFaceMatID o.Mesh 1
			o.material = o.material[id]
		)
 
		for g in geometry do (Singlemat g)
 
		alphaObjs = for o in objects where matchPattern (o.name) pattern:"*_alpha" collect o
		if alphaObjs.count != 0 do (	group alphaObjs name:"Alpha_blending_mesh")
 
		for o in geometry where  classof o == editable_poly and classof o != bonegeometry do append newworking o
		i = 1
		while i <= newworking.count do
		(
			b = newworking[i]
			j = i + 1
			while j<= newworking.count do
			(
				if not (newworking[j].name == b.name) then (j = j +1) else
				(
					b.attach (newworking[j]) b
					deleteItem newworking j
					weldverts b
				)
			)
			i = i + 1
		)
 
		groupName = "Alpha_blending_mesh"
		grp = getNodeByName groupName
		if isValidNode grp and isGroupHead grp do (select $Alpha_blending_mesh)
		toolmode.commandmode = #move
		setCommandPanelTaskMode mode:#modify
		free objgroup ; free workingObject ; free newworking
	)
)

kimarotta.com.br
3d Artist  

Goonda's picture

I don't know what is the

I don't know what is the problem, both barigazy and kimarotto's script is ruining my material assignments in multitextured objects.....but I got the point from your scripts, on how to make it fast....so i added the "local" before the variables and freed the arrays in my old script....it is now working fine and fast!!

(	
	if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode mode:#create
	undo off
	(
		local objgroup = #()
		local workingObject = #()
		local newworking = #()
 
		-- delete previous groups named "Alpha_blending_mesh"
		for o in helpers do
		(
			if o.name == "Alpha_blending_mesh" then
			(
				append objgroup o
			)
		)
 
		(
			if objgroup.count != 0 then
 
			(
				for i = 1 to objgroup.count do
				(
					ExplodeGroup $Alpha_blending_mesh
				)
			)
 
		)
		-- delete previous groups named "Alpha_blending_mesh"
 
 
		--will merge all vertices with threshold 0.001 if the obj is not inside a group
		fn weldverts obj =
		(
			result = isGroupMember obj
			if result == false do
			(
				$.weldThreshold = 0.001
				polyop.weldVertsByThreshold obj #All
			)
		)
	   --will merge all vertices with threshold 0.001 if the obj is not inside a group 
 
 
 
		-- Collect objects from scene in working list
 
 
		for o in Geometry do
		(
			if classof o != bonegeometry do
			(
				append workingObject o
			)
		)
		-- Collect objects from scene in working list
 
 
 
		fn Singlemat obj =
		(
			local mat = obj.material
			local TextureFileName = "notexture"
			if (classof obj != bonegeometry) and (mat != undefined) and classof mat.diffuseMap == Bitmaptexture do
			(
				local stringSS = mat.name
				local stringcount = stringSS.count
				if stringcount > 6 then
				(
				local TextureName = substring stringSS (stringcount - 5) ((stringcount - 5) + 6) 
				)
 
				if TextureName == "_alpha" do
				(
					local objname = obj.name
					local stringTT = objname as string
					local stringTTcount = stringTT.count
					if stringTTcount > 6 then
					(
						local ObjnameTT = substring stringTT (stringTTcount - 5) ((stringTTcount - 5) + 6)
					)
					if ObjnameTT != "_alpha" do
					(
						obj.name = objname +"_alpha" 
					)
 
				)
 
			)
 
		)
 
		fn detachFBI obj = 
		(
			local objname = obj.name
			local ids = obj.material.materialIDList 
 
			for id in ids do
			(
				obj.selectbymaterial id 
				_faceSel = polyOp.getFaceSelection obj
 
				polyOp.detachFaces obj _faceSel delete:true asNode:true name: (objname +"_tempdelface")
			)
 
			select $*_tempdelface*
			$.name = objname
		)
 
		-- Run though all objects in array and detach them
		for o in workingObject do
		(	local mat = o.material
			if (mat != undefined) and (classof mat == Multimaterial) do 
			(
				select o
				detachFBI o
				delete o
			)
		)
		-- Run though all objects in array and detach them
 
 
 
 
		--assigning single material to all object (removing unused multimaterials)
		for o in geometry where isKindOf o.material multimaterial and (classof o != bonegeometry) do 
		(
			local id = getFaceMatID o.Mesh 1
			o.material = o.material[id]
		)
		--assigning single material to all object (removing unused multimaterials)
 
 
 
 
		-- Run through all objects and check for "_alpha" in material name, rename objets as *"_alpha"
		for g in geometry do
		(
			select g
			Singlemat g
		)
		-- Run through all objects and check for "_alpha" in  material name, rename objets as *"_alpha"
 
 
 
		--group as "Alpha_blending_mesh"
		clearselection()
		select $*_alpha
		if $ != undefined do
			(
			group selection name:"Alpha_blending_mesh"
			)
		--group as "Alpha_blending_mesh"
 
 
 
		--attaching same named objects and welding vertices by 0.001 thresold 
		for o in geometry do
		(	
			if classof o == editable_poly and classof o != bonegeometry do
				(
					append newworking o
				)
		)
 
		i = 1
 
		while i <= newworking.count do
		(
			b = newworking[i]
			j = i + 1
			while j<= newworking.count do
			(
				if (newworking[j].name == b.name) then
				(
					b.attach (newworking[j]) b
					deleteItem newworking j
					select b
					weldverts b
				)
				else
				(
					j = j +1
				)
			)
 
			i = i + 1
		)
		--attaching same named objects and welding vertices by 0.001 thresold 
 
 
		--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"
		groupName = "Alpha_blending_mesh"
		grp = getNodeByName groupName
		if isValidNode grp and isGroupHead grp do
		(
			select $Alpha_blending_mesh
		)
		toolmode.commandmode = #move
		setCommandPanelTaskMode mode:#modify
		--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"
	)
 
	free objgroup ; free workingObject ; free newworking; gc()
 
)
barigazy's picture

try this

try(destroyDialog ::testRoll)catch()
rollout testRoll "Test"
(	
	local weldbythresh = polyop.weldVertsByThreshold
	local detachF = polyOp.detachFaces
	local getMatID = getFaceMatID
	fn weldverts obj thresh:0.001 = --will merge all vertices with threshold 0.001 if the obj is not inside a group
	(
		if not isGroupMember obj do
		(
			obj.weldThreshold = thresh
			weldbythresh obj #All
		)
	)
	fn detachFBI obj = 
	(
		local objname = obj.name
		local ids = obj.material.materialIDList 
		for id in ids do
		(
			obj.selectbymaterial id 
			_faceSel = obj.selectedfaces as bitarray
			detachF obj _faceSel delete:true asNode:true name:(objname +"_tempdelface")
		)
		for o in geometry where matchPattern o.name pattern:"*_tempdelface*" do o.name = objname
	)	
	fn Singlemat obj =
	(
		local mat = obj.material
		local TextureFileName = "notexture"
		if (isKindOf o bonegeometry) and (mat != undefined) and isKindOf mat.diffuseMap Bitmaptexture do
		(
			local stringSS = mat.name
			local stringcount = stringSS.count
			local TextureName = if stringcount > 6 do substring stringSS (stringcount - 5) ((stringcount - 5) + 6)
			if TextureName == "_alpha" do
			(
				stringTT = obj.name
				stringTTcount = stringTT.count
				ObjnameTT = if stringTTcount > 6 do substring stringTT (stringTTcount - 5) ((stringTTcount - 5) + 6)
				if ObjnameTT != "_alpha" do obj.name = objname +"_alpha"
			)
 
		)
 
	)
	button btn "Do The Job!" pos:[5,5] width:100 height:18
	on btn pressed do
	(
		if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode mode:#create
		undo off
		(
			-- delete previous groups named "Alpha_blending_mesh"
			local objgroup = for o in helpers where o.name == "Alpha_blending_mesh" collect o
	 		if objgroup.count != 0 do (for i = 1 to objgroup.count do ExplodeGroup i)
	 		-- Collect objects from scene in working list
	 		local workingObject = for o in Geometry where isKindOf o bonegeometry collect o
			if workingObject.count != 0 do
			(
				-- Run though all objects in array and detach them
				for o in workingObject where o.material != null and isKindOf o.material Multimaterial do (detachFBI o ; delete o)
			)
			--assigning single material to all object (removing unused multimaterials)
			for o in geometry where isKindOf o.material multimaterial and (isKindOf o bonegeometry) do o.material = o.material[(geteMatID o.Mesh 1)]
			-- Run through all objects and check for "_alpha" in material name, rename objets as *"_alpha"
			for g in geometry do Singlemat g
			--group as "Alpha_blending_mesh"
			clearselection()
			local alphaArr = $*_alpha as array
			if alphaArr.count != 0 do (group selection name:"Alpha_blending_mesh" ; free alphaArr)
				--attaching same named objects and welding vertices by 0.001 thresold 
			local newworking = for o in geometry where isKindOf o editable_poly and isKindOf o bonegeometry collect o
			i = 1
	 		while i <= newworking.count do
			(
				b = newworking[i]
				j = i + 1
				while j<= newworking.count do
				(
					if not (newworking[j].name == b.name) then (j = j +1) else
					(
						b.attach (newworking[j]) b
						deleteItem newworking j
						weldverts b
					)
				)
 
				i = i + 1
			)
			--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"
			local grp = getNodeByName "Alpha_blending_mesh"
			if grp != undefined and isGroupHead grp do select grp
			toolmode.commandmode = #move
			setCommandPanelTaskMode mode:#modify
			--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"
		)
	 	free objgroup ; free workingObject ; free newworking; gc()
	)
)
createDialog testRoll 110 28 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

Goonda's picture

No...its not working.....!!

No...its not working.....!!

kimarotta's picture

see

see

AttachmentSize
capturar.jpg 10.6 KB

kimarotta.com.br
3d Artist  

Goonda's picture

Now looking fine :)

(	
	undo off
	(
 
 
		-- delete previous groups named "Alpha_blending_mesh"
		objgroup = #()
		for o in helpers do
		(
			if o.name == "Alpha_blending_mesh" then
			(
				append objgroup o
			)
		)
 
		(
			if objgroup.count != 0 then
 
			(
				for i = 1 to objgroup.count do
				(
					ExplodeGroup $Alpha_blending_mesh
				)
			)
 
		)
		-- delete previous groups named "Alpha_blending_mesh"
 
 
 
 
		--will merge all vertices with threshold 0.001 if the obj is not inside a group
		fn weldverts obj =
		(
			result = isGroupMember obj
			if result == false do
			(
				$.weldThreshold = 0.001
				polyop.weldVertsByThreshold obj #All
			)
		)
	   --will merge all vertices with threshold 0.001 if the obj is not inside a group 
 
 
 
 
 
		-- Collect objects from scene in working list
		workingObject = #()
 
		for o in Geometry do
		(
			if classof o != bonegeometry do
			(
				append workingObject o
			)
		)
		-- Collect objects from scene in working list
 
 
 
		fn Singlemat obj =
		(
			mat = obj.material
			TextureFileName = "notexture"
			if (classof obj != bonegeometry) and (mat != undefined) and classof mat.diffuseMap == Bitmaptexture do
			(
				stringSS = mat.name
				stringcount = stringSS.count
				if stringcount > 6 then
				(
				TextureName = substring stringSS (stringcount - 5) ((stringcount - 5) + 6) 
				)
 
				if TextureName == "_alpha" do
				(
					objname = obj.name
					stringTT = objname as string
					stringTTcount = stringTT.count
					if stringTTcount > 6 then
					(
						ObjnameTT = substring stringTT (stringTTcount - 5) ((stringTTcount - 5) + 6)
					)
					if ObjnameTT != "_alpha" do
					(
						obj.name = objname +"_alpha" 
					)
 
				)
 
			)
 
		)
 
		fn detachFBI obj = 
		(
			objname = obj.name
			ids = obj.material.materialIDList 
 
			for id in ids do
			(
				obj.selectbymaterial id 
				_faceSel = polyOp.getFaceSelection obj
 
				polyOp.detachFaces obj _faceSel delete:true asNode:true name: (objname +"_tempdelface")
			)
 
			select $*_tempdelface*
			$.name = objname
		)
 
		-- Run though all objects in array and detach them
		for o in workingObject do
		(	mat = o.material
			if (mat != undefined) and (classof mat == Multimaterial) do 
			(
				select o
				detachFBI o
				delete o
			)
		)
		-- Run though all objects in array and detach them
 
 
 
 
		--assigning single material to all object (removing unused multimaterials)
		for o in geometry where isKindOf o.material multimaterial and (classof o != bonegeometry) do 
		(
			-- Get face material ID from face 1
			local id = getFaceMatID o.Mesh 1
			-- Assign that material
			o.material = o.material[id]
		)
		--assigning single material to all object (removing unused multimaterials)
 
 
 
 
		-- Run though all objects and check for "_alpha" in diffuse map, rename objets as *"_alpha"
		for g in geometry do
		(
			select g
			Singlemat g
		)
		-- Run though all objects and check for "_alpha" in diffuse map, rename objets as *"_alpha"
 
 
 
		--group as "Alpha_blending_mesh"
		clearselection()
		select $*_alpha
 
		if $ != undefined do
			(
			group selection name:"Alpha_blending_mesh"
			)
		--group as "Alpha_blending_mesh"
 
 
 
		--attaching same named objects and welding vertices by 0.001 thresold 
 
		newworking = #()
 
		for o in geometry do
		(	
			if classof o == editable_poly and classof o != bonegeometry do
				(
					append newworking o
				)
		)
 
		i = 1
 
		while i <= newworking.count do
		(
			b = newworking[i]
			j = i + 1
			while j<= newworking.count do
			(
				if (newworking[j].name == b.name) then
				(
					b.attach (newworking[j]) b
					deleteItem newworking j
					select b
					weldverts b
				)
				else
				(
					j = j +1
				)
			)
 
			i = i + 1
		)
		--attaching same named objects and welding vertices by 0.001 thresold 
 
 
		--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"
		groupName = "Alpha_blending_mesh"
		grp = getNodeByName groupName
		if isValidNode grp and isGroupHead grp do
		(
			select $Alpha_blending_mesh
		)
		toolmode.commandmode = #move
		setCommandPanelTaskMode mode:#modify
		--set final selection to group "Alpha_blending mesh, tool to 'move' mode, panel to 'modify' mode"
	)
 
 
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.