Get MM pair with script?



  • Re: Set MM pair list with a script?

    Hi! I'm trying to get the current MM pair so I can display related words in SpaceCenter.

    I found something close to what I'm looking for in this post (thanks @tal !) :

    and I was able to get the current selection from the pair list using:

    documentController.pairList.getSelection()
    

    This will work most of the time, except if I edit the pair manually and the pair is not in the list. Is there a method to getCurrentPair() or something? I wasn't able to find it. Thanks so much!

    Here's what I've got so far:

    def getMetricsMachineController():
        # Iterate through ALL OBJECTS IN PYTHON!
        import gc
        for obj in gc.get_objects():
            if hasattr(obj, "__class__"):
                # Does this one have a familiar name? Cool. Assume that we have what we are looking for.
                if obj.__class__.__name__ == "MetricsMachineController":
                    return obj
    
    # Get the current font.
    font = CurrentFont()
    
    # Get the MM main controller.
    metricsMachineController = getMetricsMachineController()
    
    # Get the document controller for the current font.
    documentController = metricsMachineController._openControllers[font.naked()] # private attribute!
    
    selection = documentController.pairList.getSelection()
    print (selection[0])
    

    (Thanks @jackson for inspiring me to actually dig into this tonight)



  • Try this:

    documentController.editView.get()
    

    That may (or may not work). The scripting API that will be in version 1.1 will handle all of this for you. I'm getting close to releasing that.



  • @tal This works, thank you so much! I just tried using the scripting API and the new metricsMachine.GetCurrentPair() works perfectly, thank you! I'm very excited about the scripting API, such a great addition to MetricsMachine.