Python: add number to end of value

Hi All,

I have a really simple problem. I want to add a number 1 to the end of a value. So if I return a mesh name MeshName, I can append a number to the end of it so the value becomes MeshName1.

I can do this if I convert it to a string like so


mesh = objectList[0].meshes[0]
newmesh = str(mesh)+str(1)
print newmesh

However a string isn’t usable for what I’m trying to do. For example, a string doesn’t work in the following context:

objectList[0].replaceMesh(str(mesh))

But it works fine when it’s not a string:

objectList[0].replaceMesh(mesh)

Does anyone have any ideas?

I’m guessing the problem is the following:

Mesh is an object. What you get with str() is the string representation of your mesh object. String representation happens to be what the developer programms it to be. It can be objects name, it can be something that describes the object, or it can be some other textual information about the object. (In some rare cases it can be a textual representation which is needed to construct an identical object.)

I have a bit hard to test the idea, but what you should be doing in this case, is to change the name attribute of your mesh object. Something like

mesh.name = mesh.name + "1"

If you want to make some clones of your mesh structure, or delete meshes, then use the mesh object itself, like you wrote in your last example.

Why do you need to do that?

You should tell us, because we can probably explain why it’s completely unnecessary.

Thanks for the replies.

I’m putting together a basic LOD system with two degrees of detail. MeshName is the low detail mesh and MeshName1 is the high detail mesh.

MeshName is placed throughout the scene, then when the camera detects it is near it, it replaces it with MeshName1.