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

    Looping through selection tags [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 359 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 02/05/2016 at 01:34, xxxxxxxx wrote:

      Hi everyone,

      I am currently getting obj files of many objects. Sadly if I am importing them into cinema 4d, I am getting one polygon object with lots of selection tags. Each selection tag represents one piece of the model and I need them separated into single objects. So I thought I could write a python script and loop through all the selection tags and then separate them.

      I found this thread here, which is actually doing, what I want to do, but building the parts into my own script doesn't really work and I am not sure, wich parts I need and which not. As for example I don't need to compare the names, but only the type

      https://developers.maxon.net/forum/topic/8936/11866_turning-selection-tags-into-separate-objects

      That's what I have so far. I now it is not very much 😢

      import c4d
      from c4d import gui
      #Welcome to the world of Python

      def main() :
          mydoc = c4d.documents.GetActiveDocument()
          myobj = doc.GetActiveObject()
          
          t = myobj.GetFirstTag()
          while t:
              if t.GetType() == c4d.Tpolygonselection:
                  tagselection = t.GetBaseSelect()
                  c4d.CallCommand(14046)
              t = t.GetNext()
          c4d.EventAdd()

      if __name__=='__main__':
          main()

      Currently it is only separating the whole object but not the polygons in the single selection tags. But I think it is going through all the selection tags, as I am currently testing it with a cube, which has 6 selection tags and I am getting 6 copies.

      So why is it not making the new objects from the selection tag? Has anyone an idea? I thought the GetBaseSelect() would activate the polygon selection in the selection tag, wouldn't it?

      Would be great if someone could give me some hints into the right direction.

      Anna

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

        On 03/05/2016 at 01:25, xxxxxxxx wrote:

        Hello,

        you loop through all the tags and you call the "Split" command. But you don't tell the "Split" command what to do.

        The "Split" command works with the current selection of the object. You don't set this selection, you just access the selection stored in the selection tag (and this does nothing).

        So you have to access the selection stored in the selection tag and copy that selection onto the object. You can then access the selection of the PolygonObject with GetPolygonS(). Now you can copy the selections. You find an example in this thread: "Select polygons from Selection Tag"

        best wishes,
        Sebastian

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

          On 09/05/2016 at 02:48, xxxxxxxx wrote:

          Hi Sebastian,

          thanks a lot for your reply and the explanations. It's now making sense and I am understanding how it is working.

          Thank you very much for your help

          Anna

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