Proper Parenting for ETO forms in Rhino6 (Python)?

Two questions:

  1. Given MainWindowForDocument doesn’t exist in Rhino6, what is the most cross-platform-friendly way to parent my ETO forms? This is what I’m doing at the bottom of all my ETO forms’ code currently. And it seems to work on Windows for Rhino 6, 7, and 8, but I don’t have a Mac to test it on.
if __name__ == '__main__':        
    dialog = MyDialog()
    if rs.ExeVersion() > 6:
        parent = Rhino.UI.RhinoEtoApp.MainWindowForDocument(sc.doc)
    else:
        parent = Rhino.UI.RhinoEtoApp.MainWindow
    Rhino.UI.EtoExtensions.ShowSemiModal(dialog, sc.doc, parent)

I just want to know if there is a better way to do this…especially for Rhino6.

  1. The new ETO documentation uses both sc.doc and __rhino_doc__ as an argument for MainWindowForDocument in the various examples and I wondered if there was any difference between the two or is that two ways to reference the same object?

(Also, I noticed none of the new ETO documentation uses the if __name__=="__main__": Is it better to not use that or does it make no difference?)

Any thoughts, @CallumSykes?

Hey @webdunce,

Rhino.UI.RhinoEtoApp.MainWindow is fine on Windows because on Windows when you open a new file it is a separate process. On Mac it is the same process so this value changes when you switch between the two Rhino windows, which can cause issues depending on how it’s used. I’m not familiar with python scripting for Rhino 6 Mac so I’ll leave that up to someone else who might know :slight_smile: (Maybe @clement ?)

I don’t believe so, they should be the same. As sc.doc has been around for longer in python I’ve opted for that. __rhino_doc__ is new for C#, I asked for it when writing these docs as I couldn’t find a way to receive the current doc safely without using RhinoDoc.ActiveDoc which I wanted to discourage.

This (as far as I remember) is relevant when you create a script and you want to prevent code execution in case you import the file in other files. As these are single scripts and nowhere is importing them I opted not to use this as it is unnecessary.

2 Likes