View Full Version : Detach by material ID question..

11 November 2005, 10:10 PM
Its looking like the only way to do this is through the edit poly modifier, but i'm having some problems, no errors are being thrown, but i can't appear to get it to work. code below:

-- Detach by material script
-- Mainly to help keep us sane from Sketchup imports.

sel = selection as array
--for each selected object
emod = Edit_Poly()

for obj in sel do
--if it has a multi sub attached
if (obj.material != undefined) do
if (obj.material.numsubs != undefined) do
--add edit poly modifier
-- Can be REALLY SLOW.
addmodifier obj (emod)

--for each sub material of the edit poly modifier
for subindex in 1 to obj.material.numsubs do
emod.selectByMaterialID = subindex

--detach & rename detached object for 'OrigionalName-material name'
newname = + "_" + obj.material[subindex].name
emod.detachtoobject newname

--Todo: attach material
--Todo: copy over any uvw's or vraydisplacementmods

If anyone has any ideas, i'd be much appreciative.. I've also tried sticking into SubObjectLevel = 4 before getting to the submaterial loop, but that appears to break out of the script altogether

11 November 2005, 01:51 AM
im using max 6... but im not sure if I recall this correctly... that you cant use poly or mesh functions at modifier level... it would always look for the baseobject level.. so if you have a sphere with an edit_poly mod above, it wont work unless you collapse the sphere to an editable poly... my memory might be playing with me though :D

I made something similar back then... my workaround was to make a copy of the object first, then collapse it...
Here's ( a link to the thread, just look for my last post below...

hope this helps:)

11 November 2005, 10:19 PM
awesome, thanks.. now i just need to make a fix mangled normals script, and i'll be golden.

CGTalk Moderation
11 November 2005, 10:19 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.