0
$\begingroup$

How to copy selected object's property and set it as a suffix of an object's name? I have 3 objects in the scene, named a,b,c. Each one of them have a custom property named id with a corresponding value 10, 20, 30. What I want to achieve is to have that custom property pasted into their names as a suffix. Basically something like this:

a?id=10
b?id=20
c?id=30

three objects - a, b, c with custom properties id=10, id=20, id=30

Could you please suggest the simplest way? I was thinking about having some sort of a python script, that would allow me to do this for all of the selected objects in the scene.

$\endgroup$
1
$\begingroup$

Try this

import bpy
for ob in [*bpy.data.objects]:
    if not ob.select_get(): continue
    if "id" not in ob: continue
    suf = "?id=%s" % ob["id"]
    ob.name += suf
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you! It worked! But I noticed that some of the objects get named twice. Do you possibly know why it happens? I did a test, and it happens when I have a copied object with a name "a.001", then an object "a" gets named "a?id=10?id=10". $\endgroup$ – zal3wa Sep 7 at 9:48
  • $\begingroup$ Mmmm, try this. $\endgroup$ – scurest Sep 7 at 10:14
  • $\begingroup$ Works like a charm! Thank you, thank you, thank you! $\endgroup$ – zal3wa Sep 7 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.