Xatrix
12-10-2006, 10:43 PM
Hello gentlemen,
I'm here to ask for a little help as I'm not any professional or even amateur MaxScripter. A while ago I've been helped by Galagast who was kind enough to write me a script I needed. There's no problems with it, it works like a charm, except that it won't work for 3dsmax R3 / 3.1 . I'm part of the group of enthusiasts who like to make 3D racing tracks for racing simulations and we're obliged to use R3 because there are certain plugins made for it which are not available for higher versions of 3dsmax.
Below is the script which works fine in all max versions starting from 5. The error I get when I run the script in Max R3 is "-- Unable to convert: 120 to type: String". This message is in a small popup window. I close it and nothing happens. And ideally, the menu/rollout should apper with a couple of options. Anybody of you guys can figure out what language structures are used in this script which are not understood by Max R3? Is it possible to make some small changes to make it compatible with R3? Or at least make it a R3-only script?
I would really appreciate the help. I've posted a few times here, either via my brother or myself, and was always helped, which is why I keep coming back :)
And just a quick description of the script: it splits the objects by their material IDs and hence creates smaller objects, naming them by the texture file name (without extension) they have assigned. I know there is a "MaterialID Object Splitter v0.2" plugin for 3dsmax R3, but it doesn't name the objects after their texture file name and we need this option a lot.
Best Regards,
Oleg
rollout detachByID "Detach by ID" width:120 height:135
(
local name_type = true
local ran_color = true
local the_name = "Element_"
local the_mats = #()
local id_list = #()
radiobuttons name_rd "" pos:[10,15] width:60 height:32 labels:#("Material", "Prefix") default:1 columns:1
edittext name_edt "" pos:[10,50] width:100 height:15 visible:false text:the_name
checkbox del_bot "Delete Original" pos:[5,75] width:110 height:15 checked:true
checkbox rancolor_chk "RandomWireColors" pos:[5,90] width:110 height:15 checked:true
button detach_bot "DETACH" pos:[5,110] width:110 height:21
GroupBox name_grp "Naming: " pos:[5,0] width:110 height:70
label name_lbl "- Texture Name -" pos:[10,50] width:100 height:15 visible:true
on detach_bot pressed do
undo "Detach by ID" on
(
obj = undefined
the_sel = selection as array
if the_sel != undefined do
(
for obj in the_sel where superclassof obj == GeometryClass do
(
id_list = #() -- empty the id_list array
the_mats = #() -- empty the the_mats array
try(convertToPoly obj)catch() -- convert the object to polygon
the_orig = obj --store the current object here
the_polyobj = copy the_orig --copy the original object
the_facecount = getnumfaces the_polyobj --get the face count
-- the ff will collect matrial ids
for i in 1 to the_facecount do
(
the_faceid = the_polyobj.getfacematerial i
if not (finditem id_list the_faceid) != 0 then append id_list the_faceid
) --thus store them in an array [id_list]
-- the ff will collect material names
try (
if obj.material != undefined then -- if the object has a material...
(
if classof obj.material == multimaterial then -- check if it is a multimaterial
(
for i in id_list do -- loop through the collected id list
(
the_objmat = obj.material[i] -- objects material is stored in here
try
(
the_mapfile = the_objmat.diffusemap.bitmap.filename --get the diffuse bitmap filename
the_filename = getfilenamefile the_mapfile + "-" -- get the filename
append the_mats (uniquename the_filename ) --collect the names
)
catch (append the_mats obj.name; format "%'s multimaterial[%] has no diffuse bitmap\n" obj.name i)
)
)
else
(
if classof obj.material == standard do
(
the_objmat = obj.material
try
(
the_mapfile = the_objmat.diffusemap.bitmap.filename
the_filename = getfilenamefile the_mapfile + "-"
append the_mats (uniquename the_filename)
)
catch (append the_mats obj.name; format "%'s has no diffuse bitmap\n" obj.name)
)
)
)
else (append the_mats obj.name; format "% has no material\n" obj.name)
)
catch (append the_mats obj.name; format "unknown error occured on %\n" obj.name)
-- thus store them in [the_mats]
-- the ff will loop through the collected ids, select faces using the face ids...
-- then detach those faces, and also use the collected names by index to name it
the_index = 0
for i in id_list do
(
the_index += 1 --increment the index
the_polyobj.selectbymaterial i --select the faces using the material ids collected
the_faces = getfaceselection the_polyobj
-- this will set what naming convention is used
if name_type then (the_name = uniquename the_mats[the_index])
else (the_name = (uniquename the_name))
polyOp.detachFaces the_polyobj the_faces asnode:true name:the_name --detach
if ran_color then (getnodebyname the_name).wirecolor = random black white
)
the_index = 0
if del_bot.checked do delete the_orig
delete the_polyobj
)
)
)
on name_edt entered txt do (the_name = txt)
on rancolor_chk changed val do (ran_color = val)
on name_rd changed val do
(
case val of
(
1:
(
name_edt.visible = false
name_lbl.visible = true
name_type = true
)
2:
(
name_edt.visible = true
name_lbl.visible = false
name_type = false
)
)
)
)
createdialog detachByID
-- script request by Eye of Hawk (CGTalk)
-- author: Galagast 05/05/24
I'm here to ask for a little help as I'm not any professional or even amateur MaxScripter. A while ago I've been helped by Galagast who was kind enough to write me a script I needed. There's no problems with it, it works like a charm, except that it won't work for 3dsmax R3 / 3.1 . I'm part of the group of enthusiasts who like to make 3D racing tracks for racing simulations and we're obliged to use R3 because there are certain plugins made for it which are not available for higher versions of 3dsmax.
Below is the script which works fine in all max versions starting from 5. The error I get when I run the script in Max R3 is "-- Unable to convert: 120 to type: String". This message is in a small popup window. I close it and nothing happens. And ideally, the menu/rollout should apper with a couple of options. Anybody of you guys can figure out what language structures are used in this script which are not understood by Max R3? Is it possible to make some small changes to make it compatible with R3? Or at least make it a R3-only script?
I would really appreciate the help. I've posted a few times here, either via my brother or myself, and was always helped, which is why I keep coming back :)
And just a quick description of the script: it splits the objects by their material IDs and hence creates smaller objects, naming them by the texture file name (without extension) they have assigned. I know there is a "MaterialID Object Splitter v0.2" plugin for 3dsmax R3, but it doesn't name the objects after their texture file name and we need this option a lot.
Best Regards,
Oleg
rollout detachByID "Detach by ID" width:120 height:135
(
local name_type = true
local ran_color = true
local the_name = "Element_"
local the_mats = #()
local id_list = #()
radiobuttons name_rd "" pos:[10,15] width:60 height:32 labels:#("Material", "Prefix") default:1 columns:1
edittext name_edt "" pos:[10,50] width:100 height:15 visible:false text:the_name
checkbox del_bot "Delete Original" pos:[5,75] width:110 height:15 checked:true
checkbox rancolor_chk "RandomWireColors" pos:[5,90] width:110 height:15 checked:true
button detach_bot "DETACH" pos:[5,110] width:110 height:21
GroupBox name_grp "Naming: " pos:[5,0] width:110 height:70
label name_lbl "- Texture Name -" pos:[10,50] width:100 height:15 visible:true
on detach_bot pressed do
undo "Detach by ID" on
(
obj = undefined
the_sel = selection as array
if the_sel != undefined do
(
for obj in the_sel where superclassof obj == GeometryClass do
(
id_list = #() -- empty the id_list array
the_mats = #() -- empty the the_mats array
try(convertToPoly obj)catch() -- convert the object to polygon
the_orig = obj --store the current object here
the_polyobj = copy the_orig --copy the original object
the_facecount = getnumfaces the_polyobj --get the face count
-- the ff will collect matrial ids
for i in 1 to the_facecount do
(
the_faceid = the_polyobj.getfacematerial i
if not (finditem id_list the_faceid) != 0 then append id_list the_faceid
) --thus store them in an array [id_list]
-- the ff will collect material names
try (
if obj.material != undefined then -- if the object has a material...
(
if classof obj.material == multimaterial then -- check if it is a multimaterial
(
for i in id_list do -- loop through the collected id list
(
the_objmat = obj.material[i] -- objects material is stored in here
try
(
the_mapfile = the_objmat.diffusemap.bitmap.filename --get the diffuse bitmap filename
the_filename = getfilenamefile the_mapfile + "-" -- get the filename
append the_mats (uniquename the_filename ) --collect the names
)
catch (append the_mats obj.name; format "%'s multimaterial[%] has no diffuse bitmap\n" obj.name i)
)
)
else
(
if classof obj.material == standard do
(
the_objmat = obj.material
try
(
the_mapfile = the_objmat.diffusemap.bitmap.filename
the_filename = getfilenamefile the_mapfile + "-"
append the_mats (uniquename the_filename)
)
catch (append the_mats obj.name; format "%'s has no diffuse bitmap\n" obj.name)
)
)
)
else (append the_mats obj.name; format "% has no material\n" obj.name)
)
catch (append the_mats obj.name; format "unknown error occured on %\n" obj.name)
-- thus store them in [the_mats]
-- the ff will loop through the collected ids, select faces using the face ids...
-- then detach those faces, and also use the collected names by index to name it
the_index = 0
for i in id_list do
(
the_index += 1 --increment the index
the_polyobj.selectbymaterial i --select the faces using the material ids collected
the_faces = getfaceselection the_polyobj
-- this will set what naming convention is used
if name_type then (the_name = uniquename the_mats[the_index])
else (the_name = (uniquename the_name))
polyOp.detachFaces the_polyobj the_faces asnode:true name:the_name --detach
if ran_color then (getnodebyname the_name).wirecolor = random black white
)
the_index = 0
if del_bot.checked do delete the_orig
delete the_polyobj
)
)
)
on name_edt entered txt do (the_name = txt)
on rancolor_chk changed val do (ran_color = val)
on name_rd changed val do
(
case val of
(
1:
(
name_edt.visible = false
name_lbl.visible = true
name_type = true
)
2:
(
name_edt.visible = true
name_lbl.visible = false
name_type = false
)
)
)
)
createdialog detachByID
-- script request by Eye of Hawk (CGTalk)
-- author: Galagast 05/05/24
