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
    • Login

    A Question on GetActiveObject? [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 286 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 07/11/2015 at 12:39, xxxxxxxx wrote:

      Hi Guys,
      A Question on GetActiveObject?
      I use GetActiveObject to Select active object, that is in the Object List.
      Now when i use doc.GetActiveObject it dont work right.
      It separate them and not group them.
      This What *Console* Said:
      AssertionError: Found next objects. Please add them separately.

      So I wanted It to generate with the selected object use choose and go under or become a child.

      Code:
          def Generator_TAXILINE(self) :

      doc = c4d.documents.GetActiveDocument()

      #--| Generate and SET NAMES |--#
              #Generate Sweep
              taxi_sweep_Name = c4d.BaseObject(c4d.Osweep)
              taxi_sweep_Name.SetName("TaxiLine")

      #User Custom TEMP     
              TEMP_Name = self.linkBox.GetLink()
              TEMP_Name.SetName("TAXILINE_TEMP")

      #Select User Custom Path
              selectedobject = doc.GetActiveObject() # <----| this Problem 
              selectedobject.SetName("User-Custom-Path")
              
              #Insert Objects To LIST!   
              doc.InsertObject(taxi_sweep_Name)
              doc.InsertObject(TEMP_Name)
              doc.InsertObject(selectedobject)

      # Objects Order!    
              parent = doc.SearchObject("TaxiLine")
              child_Temp = doc.SearchObject("User-Custom-Path")
              child_Temp.InsertUnder(parent)
              
              parent = doc.SearchObject("TaxiLine")
              child_Temp = doc.SearchObject("TAXILINE_TEMP")
              child_Temp.InsertUnder(parent)
              c4d.EventAdd()
              return True

      #--|C.O.M.M.A.N.D.S|-------------------------------------------------------#
          def Command (self, id, msg) :
              if (id == GEN_BUTTON) :
                  self.Generator_TAXILINE()
      #-------------------------------------------------------------------------------------------------#
      This what is happen when excute with doc.GetActiveObject() :

      But If i use selectedobject = c4d.BaseObject(c4d.Osplinecircle) , IT WORKS FINE:

      Help or Tip,
      Cheers,
      Ashton,
      sorry for my English guys.

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

        On 07/11/2015 at 14:02, xxxxxxxx wrote:

        In your code sample, you first select an object out of the existing tree:
        selectedobject = doc.GetActiveObject()
        and then you try to insert that somewhere else:
        doc.InsertObject(selectedobject)

        I suppose C4D doesn't like that much. You should cut that object from the tree first, to isolate it. Then you can insert it somewhere else.

        In your second sample,
        selectedobject = c4d.BaseObject(c4d.Osplinecircle)
        you create a new object, which naturally is not connected in the tree already, and insert that. This is uncritical, and therefore works.

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

          On 07/11/2015 at 15:58, xxxxxxxx wrote:

          thanks man 
          IT  WORKS BRO!
          CODE:
              def User_Custom_Path(self) :
                  doc = c4d.documents.GetActiveDocument()
                  selectedobject = doc.GetActiveObject() 
                  selectedobject.SetName("User-Custom-Path")

          def Generator_TAXILINE(self) :

          doc = c4d.documents.GetActiveDocument()

          self.User_Custom_Path()

          c4d.CallCommand(12298, 12298) # Model
                  #--| Generate and SET NAMES |--#
                  #Generate Sweep
                  taxi_sweep_Name = self.linkBox2.GetLink().GetClone(c4d.COPYFLAGS_0)
                  taxi_sweep_Name.SetName("TaxiLine")
                  #User Custom TEMP     
                  TEMP_Name = self.linkBox.GetLink().GetClone(c4d.COPYFLAGS_0)
                  TEMP_Name.SetName("TAXILINE_TEMP")

          #Insert Objects To LIST!   
                  doc.InsertObject(taxi_sweep_Name)
                  doc.InsertObject(TEMP_Name)
                  #doc.InsertObject(selectedobject)

          # Objects Oder!    
                  parent = doc.SearchObject("TaxiLine")

          child_Temp = doc.SearchObject("User-Custom-Path")
                  child_Temp.InsertUnder(parent)

          child_Temp2 = doc.SearchObject("TAXILINE_TEMP")
                  child_Temp2.InsertUnder(parent)

          c4d.EventAdd()
                  return True 
          #----------------------------------------------------------------------------------------#
           Thanks Cairyn
          Cheers,
          Ashton

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