Object, correct incremental naming [SOLVED]
-
On 27/01/2016 at 02:53, xxxxxxxx wrote:
Hello everyone
I'm stuck with a little Problem and it would be very great if someone could help me out on this.
If you press a button in my plugin it creates a null-object with the name (for example) CAMERA.1. If you press it again it creates CAMERA.2, CAMERA.3 and so on. This works fine as long one does not delete one of the objects. Then the last incremental number doesn't match anymore.
If you create Objects in Cinema 4D, for example Null.1, Null.2, Null.3, Null.4 and you delete Null.2, Cinema will create the object with the missing name Null.2
I'm kind of a python beginner, and i would be very happy for any kind of logical approaches.
here is the part of the function for renaming the created Nullobjectotype = "CAMERA"
master = doc.SearchObject(Pluginname)
parent = doc.SearchObject("Null")
parent.InsertUnder(master)ObjCount = master.GetChildren()
OTypCount = 0
for i in ObjCount:
if i.GetDown() and i.GetType() == 5140:
if i.GetDown().GetType() == ID:OTypCount = OTypCount + 1
name = str(otype)+"."+ str(OTypCount)
parent.SetName(name) -
On 29/01/2016 at 10:04, xxxxxxxx wrote:
Hello,
I guess you could simply create new names in a loop and check with SearchObject() if that name is already in use or not. If not, you can use this name for your new object.
Best wishes,
Sebastian -
On 29/01/2016 at 12:22, xxxxxxxx wrote:
I think it would be better to use
BaseDocument.InsertObject(...) instead of GeListNode.InsertUnder(...).There's a parameter 'checknames' to check for duplicate names and append the right increment.
Peter
-
On 29/01/2016 at 17:37, xxxxxxxx wrote:
Originally posted by xxxxxxxx
I think it would be better to use
BaseDocument.InsertObject(...) instead of GeListNode.InsertUnder(...).There's a parameter 'checknames' to check for duplicate names and append the right increment.
Peter
Nice Catch! Didn't know about that one, either.
-
On 30/01/2016 at 09:12, xxxxxxxx wrote:
Thanks for the tipps! the checknames parameter sounds promising