Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography


Featured Threads
  Speedmodeling 2011 - Holidays Edition
(117 replies)
  Maxforums Kiva Group
(57 replies)
  The Life of a Sea Turtle - Tutorial by mrgrotey
(121 replies)
  So what are you working on? =)
(2627 replies)
  Want free webspace?
(20 replies)
  spam alert!!!
(3920 replies)
  Maxforums member photo gallery index
(113 replies)
  Maxforums Member Tutorials
(86 replies)
  three cheers to maxforums...
(185 replies)
  The Grotorial Index Page
(57 replies)
  101 Things you didnt know in Max...
(185 replies)
  A Face tutorial from MDB101 :D
(95 replies)
  Free textures thread
(77 replies)
  Maxforums.org Members Gallery
(486 replies)
  SON OF POST YOURSELF
(626 replies)
  Dub's Maxscript Tutorial Index
(119 replies)
  The Best Art of Maxforums [56k warning]
(109 replies)


 
First page  Go to the previous page   [01]  [02]  Go to the next page  Last page
 
Detach and name by material ID?
show user profile  carrrottt09
Hello all,
Once again I come seeking your collective wisdom.

I have a scene with hundreds of objects... Each object has up to 100 material IDs... I need to detach each object by material ID (as clones so as to still have a copy off the entire model)

Needless to say this becomes quite time consuming. I am hoping there is a way to detach an object into/by its material IDs selections and use the material ID names as the names for the newly detached objects.

I'm sure there's a way to do this with maxscript... but it's a bit over my head.


Thanks,
KB
read 463 times
3/9/2010 5:06:08 PM (last edit: 3/9/2010 5:06:08 PM)
show user profile  rob@dynamic
*waits for Dub to come up with another master script*


3D Portfolio
Blog
Facebook
Twitter
Flickr






read 457 times
3/9/2010 5:11:43 PM (last edit: 3/9/2010 5:11:43 PM)
show user profile  Garp
If I understood you correctly, this should do the trick:

for obj in selection do
(
maxID = amax(for i=1 to getNumFaces obj.mesh collect getFaceMatID obj.mesh i)
for i=1 to maxID do
(
temp_arr = for j=1 to getNumFaces obj.mesh where (getFaceMatID obj.mesh j) == i collect j
if temp_arr.count != 0 do
(
aMesh = meshop.detachFaces obj.mesh temp_arr delete:false asMesh:true
eMesh = editable_mesh()
eMesh.transform = obj.transform
eMesh.mesh = aMesh
update eMesh
eMesh.name = obj.name + "_ID_" + (formattedPrint i format:"03d")
)
)
)





read 429 times
3/9/2010 7:29:33 PM (last edit: 3/9/2010 7:35:02 PM)
show user profile  carrrottt09
Garp-
Very, very close to what I was trying for.
The script you gave me did everything except adjust the name to what I'm looking for and keep the original material.

Here's a bit more (hopefully I'm not beating a dead horse)

I would like to be able to split the object into parts defined by the material IDs. At the same time I would like to rename the pieces that have been detached with the name from the material ID assigned to them. I also need to keep the original copy of the geometry.



For example:
I have an object (magical object) with 8 polys and 3 material IDs (1,2, 3). The multi-subobject material has submaterials for IDs 1, 2, 3; named red, green, blue (each submaterial has a name, r, g, b)
I want to split "magical object" into pieces by material IDs. I would end up with 4 objects total. The three: red, green, blue, and an original copy of "magical object" each retaining their original material.

I am currently doing this by using the material Ids to select a set of polys, then using "detach->detach as clone" and renaming each one to the material ID name.

I hope that clarified it a bit and didn't make it more confusing....
read 419 times
3/9/2010 7:55:45 PM (last edit: 3/9/2010 7:55:45 PM)
show user profile  Garp
for obj in selection do
(
maxID = amax(for i=1 to getNumFaces obj.mesh collect getFaceMatID obj.mesh i)
for i=1 to maxID do
(
temp_arr = for j=1 to getNumFaces obj.mesh where (getFaceMatID obj.mesh j) == i collect j
if temp_arr.count != 0 do
(
aMesh = meshop.detachFaces obj.mesh temp_arr delete:false asMesh:true
eMesh = editable_mesh()
eMesh.transform = obj.transform
eMesh.mesh = aMesh
update eMesh
try eMesh.name = obj.material.names[i] catch()
eMesh.material = obj.material
)
)
)

I'd advise for something like
try eMesh.name = obj.name + "_" + obj.material.names[i] catch()
Otherwise you migh end up with a lot of objects with the same name (if your original objects are using the same multi material or have sub materials with the same name).

Edit: the original objects should be left intact. You get something different?

Edit2: the try/catch is just there in case the number of sub materials doesn't match the number of mat IDs on the object (then they're named Object01, Object02, etc.)




read 407 times
3/9/2010 8:38:08 PM (last edit: 3/9/2010 8:51:51 PM)
show user profile  carrrottt09
Garp!
Thanks so much. This appears to do exactly what I want...
But..... If my multi-sub-obj has a missing slot - e.g it has everything but a material in id 35 (and there are 50 material ids). It seems to run into an error (I think that's what's causing it?).

Here's the error:
-- Error occurred in i loop
-- Frame:
-- i: 345
-- called in obj loop
-- Frame:
-- maxID: undefined
-- obj: $Celiac Low poly
** system exception **

Can you explain what is going on here/offer a fix/both?

edit: the materials are being preserved.
edit2:The original object is being preserved.
read 400 times
3/9/2010 8:52:28 PM (last edit: 3/9/2010 9:05:06 PM)
show user profile  Garp
It's not a missing sub material. The error is maxID undefined. At this point only the mat IDs in use on the object - not in the multi material - are concerned.
It looks like you have an object with no mat ID assigned to its polygons (but I'm not sure it's possible) or an object without mesh, hence no polygon and no mat ID (now that's possible).
Check that 'Celiac Low poly' object. Does it have a mesh?

In the meantime, replace
for i=1 to maxID do
by
if maxID != undefined do for i=1 to maxID do





read 388 times
3/9/2010 9:11:00 PM (last edit: 3/9/2010 9:11:00 PM)
show user profile  carrrottt09
Garp-
The object i was using did indeed have a mesh - it is an editable poly. I collapsed it down to an editable mesh, converted it to an editable poly and put a turbosmooth on top.

I tried it on another object - same error (both with and without the change you offered in the last reply)
I merged both objects into the scene - could that do it? I'll continue to try and troubleshoot.

Edit:
I just tried it out in the scene in which I built the objects. Still getting the error:

- Error occurred in i loop
-- Frame:
-- i: 330
-- called in obj loop
-- Frame:
-- maxID: undefined
-- obj: $Celiac Low poly
** system exception **

It seems to work if I create a small object and run it. Can it be an object size issue? I'm running this on an object with 65K polys and around 45 material IDS
read 378 times
3/9/2010 9:45:30 PM (last edit: 3/9/2010 9:51:59 PM)
show user profile  Garp
I've tried to reproduce the problem by running the script on random objects merged from old scenes. So far no luck (meaning no error).
Since I've had my milk, I need to go to bed now <|o)
Tomorrow...





read 374 times
3/9/2010 9:56:34 PM (last edit: 3/9/2010 9:57:31 PM)
show user profile  carrrottt09
Garp,
Thanks. I'm getting the same error still. Also of note: after I get that error - the next time I click on anything in max - it crashes and says that it has run out of memory.
I appreciate you sticking with me and trying to find a solution.


Just to double check: This is the modified script:

for obj in selection do
(
maxID = amax(for i=1 to getNumFaces obj.mesh collect getFaceMatID obj.mesh i)
if maxID != undefined do for i=1 to maxID do
(
temp_arr = for j=1 to getNumFaces obj.mesh where (getFaceMatID obj.mesh j) == i collect j
if temp_arr.count != 0 do
(
aMesh = meshop.detachFaces obj.mesh temp_arr delete:false asMesh:true
eMesh = editable_mesh()
eMesh.transform = obj.transform
eMesh.mesh = aMesh
update eMesh
try eMesh.name = obj.material.names[i] catch()
eMesh.material = obj.material
)
)
)

read 367 times
3/9/2010 10:11:34 PM (last edit: 3/9/2010 10:11:34 PM)
show user profile  Garp
Slightly different approach:

disableSceneRedraw()
undo off
(
for obj in selection do
(
maxID = 0
for f=1 to obj.mesh.numFaces do maxID = amax maxID (getFaceMatID obj.mesh f)
if maxID!=0 do for i=1 to maxID do
(
newObj = convertTo (copy obj) editable_poly
newObj.selectByMaterial i
faceSel = -(polyop.getFaceSelection newObj)
polyop.deleteFaces newObj faceSel
if newObj.numFaces==0 then delete newObj else
try newObj.name = obj.name + "_" + obj.material.names[i] catch()
gc()
)
)
)
enableSceneRedraw()

I suspect the previous script occasioned a huge memory leak.
Here I've tried to minimize memory use.
Still it's guaranteed to be slow. Especially if you have objects with large polycounts and max has to reallocate more memory. And if this fails, you get a system exception :(





read 339 times
3/10/2010 10:24:45 AM (last edit: 3/10/2010 10:24:45 AM)
show user profile  carrrottt09
Garp-
This worked on some of my smaller objects... but caused the system to crash on larger ones.
If you have any other ideas I'm totally open and willing to try them. If you also wouldn't mind giving some details on what each line is doing. I am having a hard time grasping what exactly is going on. I realize I'm asking a lot and I appreciate all of your help.
Thanks
read 323 times
3/10/2010 4:16:27 PM (last edit: 3/10/2010 4:16:27 PM)
show user profile  Nik Clark
Would allowing maxscript more memory fix the problem?


Click here to send me an emailClick here to visit my websiteClick here to visit my photo gallery on Flickr

read 311 times
3/10/2010 5:14:58 PM (last edit: 3/10/2010 5:14:58 PM)
show user profile  carrrottt09
Any suggestions on the size I should go to?
Tried doubling it to 15... Maybe I'll try a bit more.
read 305 times
3/10/2010 5:32:32 PM (last edit: 3/10/2010 5:52:19 PM)
show user profile  Dave


GaryDave

read 299 times
3/10/2010 5:35:40 PM (last edit: 3/10/2010 5:35:57 PM)
 
First page  Go to the previous page   [01]  [02]  Go to the next page  Last page
 
#Maxforums IRC
Open chat window


Support Maxforums.org