1
$\begingroup$

I know there isn't natively in Blender a way to Smart UV Project multiple objects to their own UV Maps without doing it manually for every object but I bet it's possible using a script. However I couldn't find it anywhere and can't really code it myself. Could anyone help with the right script? I've come up with something like this but it unwraps everything into one UV Map. I know that's because of the fact that Smart UV Project works for all selected objects, not only for active object but that's all I was able to think of.

import bpy

selection = bpy.context.selected_objects

for o in selection:
    bpy.context.view_layer.objects.active = o
    bpy.ops.uv.smart_project()
$\endgroup$
2
  • 1
    $\begingroup$ Deselect all outside loop (after setting selection) bpy.ops.object.select_all(action='DESELECT') in loop toggle the objects selection o.select_set(True) at start, False at end. $\endgroup$
    – batFINGER
    Commented Mar 17, 2020 at 12:03
  • $\begingroup$ Thank you! It works. :) $\endgroup$
    – cc03d.com
    Commented Mar 17, 2020 at 15:03

2 Answers 2

2
$\begingroup$

Here's the working code, thanks to batFINGER:

import bpy

selection = bpy.context.selected_objects
bpy.ops.object.select_all(action='DESELECT')

for o in selection:
    o.select_set(True)
    bpy.context.view_layer.objects.active = o
    bpy.ops.uv.smart_project()
    o.select_set(False)
$\endgroup$
0
$\begingroup$

That's nothing, it's because you entered the edit mode with all of your objects selected.Go to object mode and selected one object and go back to edit mode, you can see every object has unwrapped individually.

$\endgroup$
4
  • $\begingroup$ Well, I think you didn't understand me correctly. I need to unwrap about 100 objects the fastest way possible - smart UV project will work fine in my situation. I don't want to select one object at a time, Smart UV Project and then do it 99 times more. I need a script that does it for me. I've tried using my script both in object mode and in edit mode. That's not the case - the script works the same way, it packs all of the selected models in one UV Map and I need the script to UV unwrap all models to their own UV maps. $\endgroup$
    – cc03d.com
    Commented Mar 17, 2020 at 10:18
  • $\begingroup$ yes, it happens check again. Blender can take in multiple objects into editmode at once, your situation here is that you have selected ALL objects at ONCE and entered edit mode. You are wanting each object to be unwrapped at once into their own uv maps and that happens but since you selected all of them and went to edit mode all the uv maps show up on the editor. Run your script again with all objects selected and then this time deselect all(Alt+a) and click on one object, enter edit mode and you can see it has unwrapped individually onto its own uv map and this has happened to all others. $\endgroup$
    – Lester
    Commented Mar 19, 2020 at 16:38
  • $\begingroup$ Please read my comment one more time. Then try to do it yourself your way and you'll see that it doesn't work as you think it does. Thank you for your effort but my problem has already been solved above, using a script. $\endgroup$
    – cc03d.com
    Commented Mar 20, 2020 at 16:34
  • $\begingroup$ yes your script works, i said there is no problem in the script. so what exactly is your problem/. $\endgroup$
    – Lester
    Commented Mar 23, 2020 at 10:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .