Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Admin
    • Login

    Object, correct incremental naming [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 477 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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 Nullobject

      otype = "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)

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 30/01/2016 at 09:12, xxxxxxxx wrote:

              Thanks for the tipps! the checknames parameter sounds promising

              1 Reply Last reply Reply Quote 0
              • First post
                Last post