How to get a MoGraph Selection using a Python Effector...
-
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()