Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to get a MoGraph Selection using a Python Effector...

    Cinema 4D SDK
    sdk
    1
    1
    337
    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.
    • N
      noseman
      last edited by

      Thanks to the help of @m_adam I have the simplest code that allows you to get the MoGraph Selection data from a MoGraph Generator with a MoGraph Selection.
      In the attached project, I have a Matrix Object with a MoGraph Selection Tag and the Python effector that prints the selection data to the console.
      This implementation requires you drag the Selection Tag into the "Selection" link (Effector Tab->Selection).
      Because the method is based on the Tag Name, make sure the Selection Tag has a nice unique name to avoid any confusion.
      The code is fully Commented for your convenience (or inconvenience for that matter)...

      import c4d
      from c4d import gui
      
      from c4d.modules import mograph as mo
      
      
      def main():
          moData = mo.GeGetMoData(op) #Get MoGraph Data
      
          moSelTagName = op[c4d.ID_MG_BASEEFFECTOR_SELECTION] #Get the MoGraph Selection Tag Name from the Effector's "Selection" Link
      
          # Retrieve the first tag attached to the generator (the Matrix) matching the name
      
          moSelTag = None # initialize the "moSelTag" Variable
      
          for tag in gen.GetTags(): # Go through All tags on the MoGraph Generator...
              # "gen" is a Global Variable holding the MoGraph Generator (e.g. the cloner object which executes the Python Effector)
      
              if not tag.IsInstanceOf(c4d.Tmgselection): # if the tag is NOT a MoGraph Selection, try the next tag
                  continue
      
              # if the previous is FALSE, then the Tag is a MoGraph Selection
              if tag.GetName() == moSelTagName: # Does the Tag found above have the same name as the Linked Selection Tag?
                  moSelTag = tag # If the above is true, then set the Variable to that Tag and Break the Original Loop to continue down
                  break
      
          if moSelTag: # If after all of the above we have a valid tag in the Variable, then do the following:
              sel = mo.GeGetMoDataSelection(moSelTag) #Get the Mograph Selection from the Tag
              selData = sel.GetAll(moData.GetCount()) #Get the Data from the Mograph Selection
              print(selData) # Print the Data
      
      
      # Execute main()
      if __name__=='__main__':
          main()
      

      Get Mograph Selection data 01A.c4d

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