PDA

View Full Version : How to remove many(!) material IDs at once?


wiz4rd
08-16-2009, 09:12 PM
Hi guys,
got a little question here: how can I remove the material IDs of a huge amount of objects at once?

As some of you might have noticed, the new Lighting Challenge #20 (http://forums.cgsociety.org/showthread.php?f=185&t=796537) is online. At the moment I'm preparing a .blend file from the original OBJ file. So far, I've seperated all the objects, and arranged everything in several layers.
So far so good, but now every object shows 16 mat IDs, no matter which material is actually being used. If there weren't so many objects, I could go through them one at a time and remove the IDs -- thinking about it, I should have done this before hitting [P] --> seperate all loose parts ... :banghead:

Anyway, now I've got about 300 objects, and need to clean up this material ID mess. Any ideas on that?

Would be really appreciated.

Bao2
08-16-2009, 10:54 PM
Time to search for a script perhaps.

I would select all the objects and ctr j to join them.
Then select all the faces and apply a material or what you want to do if it is not apply a material to all the faces.
Now p to separate and choose "all loose parts"

wiz4rd
08-17-2009, 12:21 AM
Yeah, sometimes being able to script at least a little would be great. :D

This thing already took a few hours to get as far as I am right now
Joining all the meshes again would lead me right back to where I started from: well over 500 meshes in one object[1], each of which to be seperated and sorted again... BTDTGT.

Ah well, too late to fix the problem right now.
Need to get some sleep.

Thanks anyway.


[1] BTW, does anybody know why the OBJ importer doesn't separate the individual meshes according to materials anymore?

ScotchTapeWorm3D
08-17-2009, 05:50 AM
Try this.

Open a new scene, and import the OBJ. In the Dialogue box that opens, under "Separate objects by OBJ:" Select "Object" and "Material".

You will have 46 Objects all separated by Material.

There will be some cleanup to do, but it shouldn't take too long. For example, your going to want to remove doubles on all the objects. You might want to separate and combine a few things. (I got my object count down to 29. All the TVs are one object. The cash register along with the keyboard, and monitor are combined to be one object. All the boxes are one object. you get the idea. You can separate it further if you want to.) Fix the pivot points Also, the exit sign was created with Ngons, so you'll want to fix that.

I hope that helps!

hvanderwegen
08-17-2009, 06:41 AM
I concur with ScotchTapeWorm3D: I had no material problems when I imported said scene by 'material'. You will have to do a bit of a cleanup - e.g. objects that share the same material, such as the hair, boxes and tv's need to be separated manually, but that does not take too long.

And remember, only use those objects you intend to show in your render. Get rid of everything else (or use layers to hide those unseen objects).

wiz4rd
08-17-2009, 11:26 AM
Apparently, I only had to disable the "keep vert order" button. DOH!
Now it imports just fine. Well, except for the "X" in "EXIT". All the other letter get their f-gons and look pretty happy with it.

Thanks for making me look at the importer settings more closely. Otherwise I would've probably started all over again :D

wiz4rd
08-17-2009, 07:34 PM
well, I only solved the import problem.

The original question remains. Is it possible to delete the material IDs of multiple objects at once? Or is going through every object individually the only way to get rid of these IDs?

I mean, it is possible to replace every material with another one (shift+f4 - ../Material - RMB to select the materials to be replaced - LMB to select the material which replaces the others - Rkey - done!) Now that every mat ID shows the same material, one would expect that when saving now, the redundant IDs would go away, just like materials which aren't used anymore.

I hope, I'm making sense.

ScotchTapeWorm3D
08-17-2009, 08:25 PM
I don't know why you would need to delete the materials anymore. Everything has it's own correct material, (for the most part) just change the name to something reasonable, and do what you need to do to the material.

Bao2
08-17-2009, 08:40 PM
See if this helps:

MaterialWorks script:

Features




Search for a material in all objects and replaces it with another material.
Reduce the effect to all/visible/selected objects.
Rename materials in a list of all materials - no need to go the the object.
Show who is using the material.
Calculate the sum of surface areas using material.
Assign material to selected faces or objects.
Download link to the script:
http://cid-c04b5ffe6df805d6.skydrive.live.com/self.aspx/Public/material_works.py


It was found here:
http://wiki.blender.org/index.php/Extensions:Py/Scripts/Catalog

Bao2
08-17-2009, 09:29 PM
I tested the python script and works but is something difficult so I am going to give some instructions:

The link to the script is not to right click and download but is to click on it and you go to a page where you click the download button there and then the script is downloaded.

Now copy this script to the blender scripts directory (in Ubuntu it is /blender/.blender/scripts) and to be able to see the ".blender" hidden directory I must select choose View/Show Hidden Files in nautilus.

Well now launch Blender, load your .blend file and go to a script window and in the Scripts menu you have the Materials and there is the Material Works script. Select it and choose the material you want to be replaced and choose the material you want instead. Click replace button and it is. Esc to terminate the script

wiz4rd
08-18-2009, 10:31 AM
I don't know why you would need to delete the materials anymore. Everything has it's own correct material, (for the most part) just change the name to something reasonable, and do what you need to do to the material.
Right, I don't need to anymore for this scene. I was just asking out ouf curiosity if it's possible at all.
Like in a scene with 500 objects, lots of materials per object, and you want to replace every material with the default material. Wouldn't it make more sense when not only the old materials get replaced, but, since there's just one material per object now, every ID gets deleted?

@Bao: I'll have a look at the script.

sundialsvc4
08-18-2009, 01:09 PM
This does call for a script, and it might be a very small one.

When I am dealing with complex objects, I usually parent them to a series of empties and/or place them into meaningful groups. So a single "thing," like a cash register with all of its keys, appears to Blender as several "objects," each with one or more "meshes." It's just much easier to keep track of things that way.

I also make very aggressive use of the "linked files" feature in organizing my projects. No matter what computer application I'm dealing with, "big files" make me nervous.

FishB8
08-18-2009, 11:27 PM
Right, I don't need to anymore for this scene. I was just asking out ouf curiosity if it's possible at all.
Like in a scene with 500 objects, lots of materials per object, and you want to replace every material with the default material. Wouldn't it make more sense when not only the old materials get replaced, but, since there's just one material per object now, every ID gets deleted?

That's one of the major faults with the internal design of blender. Most of the time you can't perform an operation on multiple objects. You have to write a script to iterate over a set and apply the action to each individual element.

This is one of the reasons for the overhaul of the core in the 2.5 development. The new core will allow you to select more than one object and have an operator apply to the whole set at once.

sebastian-koenig
08-19-2009, 06:58 AM
Like in a scene with 500 objects, lots of materials per object, and you want to replace every material with the default material. Wouldn't it make more sense when not only the old materials get replaced, but, since there's just one material per object now, every ID gets deleted?
while it is still true what you say, just for the sake of completeness i want to mention that you can override every material in the renderlayers panel. if you want to render everything with the default grey material, just fill in it's name in the field in renderlayers panel. you can also choose a custom light group.
http://img.skitch.com/20090819-t9icrdnqr8ni1k5ibprk3ky9de.preview.jpg (http://skitch.com/sebastiankoenig/b55ik/override-material)

still it would be nice if we could perform actions on muliple objects.
cheers!
sebastian

wiz4rd
08-19-2009, 10:23 AM
@sebastian: what you mention here would be very useful for rendering an AO pass, for example. But as you said yourself, it only overrides the other material settings.
Just a thought, an "apply" button like in the modifiers tab would be interesting if it wouldn't only replace materials B, C, D, etc. with material A (that's something you can do already with SHIFT+F4) but if it would actually reset everything, materialwise. Oh well...

@Fish: In theory the script would have to have 2 For-loops. The first (outer) one cycles through every selected object; the second (inner) one goes through every material ID and deletes it, finally sets a default material. Sounds simple enough for someone with rudimentary programming skills, which , sadly, I don't have...

CGTalk Moderation
08-19-2009, 10:23 AM
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.