Selecting Faces by diffusemap

I am trying to write a script which will check all the objects(geometry) in a scene individually....and detach the faces having a material with diffuse texture name ending with "_alpha".....then naming and grouping the newly created object (the easiest part). I am able to do this for single material objects.....but the problem starts when multi-subobject materials are there. I am not able to select the faces with specific mat id having a diffuse texture name ending with "_alpha".

the only working part of my script is:

if classof mat.diffuseMap == Bitmaptexture then
(
stringSS = getFileNameFile mat.diffusemap.bitmap.filename
stringcount = stringSS.count
start = stringcount - 5
end = start + 6
TextureName = substring stringSS start end
if TextureName == "_alpha" then
(
objname = $.name
$.name = objname +"_alpha"

)

)

....need help :(

Comments

Comment viewing options

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

try this...update

try this...

 fn getMtlMaps mtl = 
	(
		if classof mtl == multimaterial  then
		(	
			for m = 1 to mtl.numsubs where (mtl[m] != undefined) do 
			(
				if classof mtl[m].diffusemap == Bitmaptexture do append mapArr (getFileNameFile mtl[m].diffusemap.bitmap.filename)
			)
		) else ( if classof mtl.diffusemap == Bitmaptexture do append mapArr (getFileNameFile mtl.diffusemap.bitmap.filename))
	)
 
mapArr = #()
textName = #()
getMtlMaps $.material 
 
for i in mapArr do
	(
		stringcount = i.count
		if stringcount >= 6 then appendifunique textName (substring i (stringcount - 5) (stringcount + 1))
	)
 
 if finditem textname "_alpha" != 0 do $.name = $.name + "_alpha"

kimarotta.com.br
3d Artist  

Goonda's picture

Hi kimarotto....thanks a

Hi kimarotto....thanks a lot.....now it is more clear to me.....and the script is working great. But there is a problem, it is naming the whole object as a "*_alpha"....I was looking for something which can detach the faces based on the the mat_id of the material whose diffuse map name ends with "_alpha". Actually I am trying to detach those faces to a separate object, and then name it....not the same object.

I am not able to select those faces by that particular mat_id...because I am not able to detect that exact id.

kimarotta's picture

try this...mapArr =

...

kimarotta.com.br
3d Artist  

kimarotta's picture

hi...this case has a

hi...

this case has a parenthesis wrong in the first "if" for a look ...
I used it and it worked...

mat = $.material
 
if classof mat.diffuseMap == Bitmaptexture then
(
stringSS = getFilenameFile mat.diffusemap.filename
stringcount = stringSS.count
start = stringcount - 5
end = start + 6
TextureName = substring stringSS start end
) --- end if
if TextureName == "_alpha" then
(
objname = $.name
$.name = objname +"_alpha"
)
---) remove parenthesis
---"Box001_alpha"
---01 - Default:VRayMtl
---"_alpha"

kimarotta.com.br
3d Artist  

Goonda's picture

Try this one: ( mat =

Try this one:

(
mat = $.material
TextureFileName = "notexture"
if classof mat.diffuseMap == Bitmaptexture then
(
stringSS = getFileNameFile mat.diffusemap.bitmap.filename
stringcount = stringSS.count
start = stringcount - 5
end = start + 6
TextureName = substring stringSS start end
if TextureName == "_alpha" then
(
objname = $.name
$.name = objname +"_alpha"

)

)

)

....this is just a part of the script.....it will return undefined....but I want to know how can I write the remaining part which handles multi-subobject material!!

Comment viewing options

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