<aside> <img src="/icons/list-indent_gray.svg" alt="/icons/list-indent_gray.svg" width="40px" />

目次:

</aside>

<aside>

ザックリしたまとめまので、動作保証がありません。山岸

</aside>

メニュー登録の方法1


  1. 環境変数、ADSK_3DSMAX_STARTUPSCRIPTS_ADDON_DIR にスクリプトディレクトリのパスを通して起動

  2. scriptsフォルダに、メニュー登録用のpythonを実行する maxscriptを配置

    ※ スタートアップでPythonを直接実行する機能が現在ないため(多分)

    ※ GUIのライブラリがQtになってからは、PySideでメニュー構築が分かりやすい。

    typ_init_menu.ms

    if not IsNetServer() then (
        python.ExecuteFile "typ_init.py"
        python.ExecuteFile "typ_init_menu.py"
    )
    
  3. scripts / python ディレクトリにPythonを配置しておくと、maxscriptで実行ができる。

    typ_init_menu.py

    """TYP Max Integrate
     
    Version:
        * Name : Template
        * Updated : v1.0.0 2022/06/09 Tatsuya YAMAGISHI
        * Created : v1.0.0 2022/06/09 Tatsuya YAMAGISHI
        * Coding : Python 3.7.9 & PySide2
        * Author : Tatsuya Yamagishi <[email protected]>
    
    Release Note:
        * v1.0.0 2022/06/09
            * New
    """
    
    import os
    from pprint import pprint
    import sys
    
    try:
        from PySide2 import QtCore, QtGui, QtWidgets
    except:
        from Qt import QtCore, QtGui, QtWidgets
    
    import typ13.tylibs as tylibs
    import typ_maxlibs
    
    typ.logger.info('TYP | Init Menu')
    
    #------------------------#
    # Methods
    #------------------------#
    def get_main_window():
        """Get the 3DS MAX main window.
        
        Returns:
            PySide2.QtWidgets.QMainWindow: 'QMainWindow' 3DS MAX main window.
    
        Reference:
            * <https://russell-vfx.com/blog/2020/8/20/main-window>
        """
        for w in QtWidgets.QApplication.topLevelWidgets():
            if w.inherits('QMainWindow') and w.metaObject().className() == 'QmaxApplicationWindow':
                return w
            
        raise RuntimeError('Count not find QmaxApplicationWindow instance.')
    
    def get_menu_from_menubar(menubar, menu_name):
        """
    
        メニューバーからメニューを名前で取得
    
        """
        menus = menubar.findChildren(QtWidgets.QMenu)
        for menu in menus:
            if menu.title() == menu_name:
                return menu
            
        return None
       
    #------------------------#
    # Init Menu Bar
    #------------------------#
    main_window = get_main_window()
    main_menubar = main_window.menuBar()
    menu_name = 'TYP'
    typ_menu = get_menu_from_menubar(main_menubar, menu_name)
    
    if typ_menu is None:
        typ_menu = QtWidgets.QMenu(main_menubar)
        typ_menu.setTitle(menu_name)
        main_menubar.addAction(typ_menu.menuAction())
    
    if typ.debug():
        typ.logger.debug(main_menubar)
        typ.logger.debug(typ_menu)
        pprint(main_menubar.actions())
    
    #------------------------#
    # Add Menu
    #------------------------#
    typ.logger.info('TYP | Integration TYP Menu > Main MenuBar')
    action = QtWidgets.QAction('HogeHoge', main_menubar)
    action.triggered.connect(hogehoge)
    typ_menu.addAction(action)
    

メニューの削除の方法