Python: Add Submenu The 2019 Stack Overflow Developer Survey Results Are InAdd uv_layer to mesh, add uv-coords, with pythonHow to create toggle buttons in blender GUI from dynamic list of items?How to add a driver via python?Add a group instance with pythonPython: add object, then change propertiesCopying blender log to a scriptadd parameters (Grid, Random…) with pythonAdd camera moving along curve in PythonHow can I get the id name of a submenu?How to add a new item to the Mesh submenu of the Add Menu in this script?

Should I use my personal or workplace e-mail when registering to external websites for work purpose?

Is flight data recorder erased after every flight?

Inflated grade on resume at previous job, might former employer tell new employer?

What do hard-Brexiteers want with respect to the Irish border?

Time travel alters history but people keep saying nothing's changed

What is the best strategy for white in this position?

How do you say "canon" as in "official for a story universe"?

What is the meaning of Triage in Cybersec world?

Should I write numbers in words or as numerals when there are multiple next to each other?

Can't find the latex code for the ⍎ (down tack jot) symbol

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

Spanish for "widget"

Why is my p-value correlated to difference between means in two sample tests?

Is domain driven design an anti-SQL pattern?

Could a US political party gain complete control over the government by removing checks & balances?

Why is it "Tumoren" and not "Tumore"?

Falsification in Math vs Science

Extreme, unacceptable situation and I can't attend work tomorrow morning

What is the use of option -o in the useradd command?

Is this food a bread or a loaf?

Idiomatic way to prevent slicing?

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

aging parents with no investments

Where does the "burst of radiance" from Holy Weapon originate?



Python: Add Submenu



The 2019 Stack Overflow Developer Survey Results Are InAdd uv_layer to mesh, add uv-coords, with pythonHow to create toggle buttons in blender GUI from dynamic list of items?How to add a driver via python?Add a group instance with pythonPython: add object, then change propertiesCopying blender log to a scriptadd parameters (Grid, Random…) with pythonAdd camera moving along curve in PythonHow can I get the id name of a submenu?How to add a new item to the Mesh submenu of the Add Menu in this script?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2












$begingroup$


I am creating a simple add-on in Blender. Initially I tested the code in Python console, then I wrapped it in an operator and added it to Object menu, it worked well:



class MyOperator(bpy.types.Operator):
bl_idname = 'object.MyOperator'
bl_label = 'MyOperator'
bl_options = 'REGISTER', 'UNDO'

def execute(self, context):
# ...affairs...
return 'FINISHED'


def task_func(self, context):
self.layout.operator(MyOperator.bl_idname)


def register():
bpy.utils.register_class(MyOperator)
bpy.types.VIEW3D_MT_object.append(task_func)


But now I need to add several operators and a submenu. I tried this example, and but it is not working:



class MyMenu(bpy.types.Menu):
bl_idname = 'object.MyMenu'
bl_label = 'MyMenu'

def draw(self, context):
layout = self.layout
layout.operator(MyMenu.bl_idname, text=MyMenu.bl_label)


def menu_func(self, context):
# None of these is working :(
self.layout.call_menu(name=MyMenu.bl_idname)
self.layout.menu(MyMenu.bl_idname)


def register():
bpy.utils.register_class(MyOperator)
bpy.types.VIEW3D_MT_object.append(menu_func)


So, what's the problem about? How can I solve it?










share|improve this question











$endgroup$


















    2












    $begingroup$


    I am creating a simple add-on in Blender. Initially I tested the code in Python console, then I wrapped it in an operator and added it to Object menu, it worked well:



    class MyOperator(bpy.types.Operator):
    bl_idname = 'object.MyOperator'
    bl_label = 'MyOperator'
    bl_options = 'REGISTER', 'UNDO'

    def execute(self, context):
    # ...affairs...
    return 'FINISHED'


    def task_func(self, context):
    self.layout.operator(MyOperator.bl_idname)


    def register():
    bpy.utils.register_class(MyOperator)
    bpy.types.VIEW3D_MT_object.append(task_func)


    But now I need to add several operators and a submenu. I tried this example, and but it is not working:



    class MyMenu(bpy.types.Menu):
    bl_idname = 'object.MyMenu'
    bl_label = 'MyMenu'

    def draw(self, context):
    layout = self.layout
    layout.operator(MyMenu.bl_idname, text=MyMenu.bl_label)


    def menu_func(self, context):
    # None of these is working :(
    self.layout.call_menu(name=MyMenu.bl_idname)
    self.layout.menu(MyMenu.bl_idname)


    def register():
    bpy.utils.register_class(MyOperator)
    bpy.types.VIEW3D_MT_object.append(menu_func)


    So, what's the problem about? How can I solve it?










    share|improve this question











    $endgroup$














      2












      2








      2





      $begingroup$


      I am creating a simple add-on in Blender. Initially I tested the code in Python console, then I wrapped it in an operator and added it to Object menu, it worked well:



      class MyOperator(bpy.types.Operator):
      bl_idname = 'object.MyOperator'
      bl_label = 'MyOperator'
      bl_options = 'REGISTER', 'UNDO'

      def execute(self, context):
      # ...affairs...
      return 'FINISHED'


      def task_func(self, context):
      self.layout.operator(MyOperator.bl_idname)


      def register():
      bpy.utils.register_class(MyOperator)
      bpy.types.VIEW3D_MT_object.append(task_func)


      But now I need to add several operators and a submenu. I tried this example, and but it is not working:



      class MyMenu(bpy.types.Menu):
      bl_idname = 'object.MyMenu'
      bl_label = 'MyMenu'

      def draw(self, context):
      layout = self.layout
      layout.operator(MyMenu.bl_idname, text=MyMenu.bl_label)


      def menu_func(self, context):
      # None of these is working :(
      self.layout.call_menu(name=MyMenu.bl_idname)
      self.layout.menu(MyMenu.bl_idname)


      def register():
      bpy.utils.register_class(MyOperator)
      bpy.types.VIEW3D_MT_object.append(menu_func)


      So, what's the problem about? How can I solve it?










      share|improve this question











      $endgroup$




      I am creating a simple add-on in Blender. Initially I tested the code in Python console, then I wrapped it in an operator and added it to Object menu, it worked well:



      class MyOperator(bpy.types.Operator):
      bl_idname = 'object.MyOperator'
      bl_label = 'MyOperator'
      bl_options = 'REGISTER', 'UNDO'

      def execute(self, context):
      # ...affairs...
      return 'FINISHED'


      def task_func(self, context):
      self.layout.operator(MyOperator.bl_idname)


      def register():
      bpy.utils.register_class(MyOperator)
      bpy.types.VIEW3D_MT_object.append(task_func)


      But now I need to add several operators and a submenu. I tried this example, and but it is not working:



      class MyMenu(bpy.types.Menu):
      bl_idname = 'object.MyMenu'
      bl_label = 'MyMenu'

      def draw(self, context):
      layout = self.layout
      layout.operator(MyMenu.bl_idname, text=MyMenu.bl_label)


      def menu_func(self, context):
      # None of these is working :(
      self.layout.call_menu(name=MyMenu.bl_idname)
      self.layout.menu(MyMenu.bl_idname)


      def register():
      bpy.utils.register_class(MyOperator)
      bpy.types.VIEW3D_MT_object.append(menu_func)


      So, what's the problem about? How can I solve it?







      python






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      metaphor_set

      4,5901721




      4,5901721










      asked 2 days ago









      AivanF.AivanF.

      1647




      1647




















          1 Answer
          1






          active

          oldest

          votes


















          2












          $begingroup$

          There were a number of issues. From not registering menu class and having invalid bl_idname's (no capital letters)



          Here is working code. In 2.8 it is a requirement that class names reflect the bl_idname.



          import bpy

          class OBJECT_OT_myoperator(bpy.types.Operator):
          bl_idname = 'object.myoperator'
          bl_label = 'MyOperator'
          bl_options = 'REGISTER', 'UNDO'

          def execute(self, context):
          # ...affairs...
          return 'FINISHED'

          class OBJECT_MT_mymenu(bpy.types.Menu):
          bl_idname = 'object.mymenu'
          bl_label = 'MyMenu'

          def draw(self, context):
          layout = self.layout
          layout.operator(OBJECT_OT_myoperator.bl_idname)

          def menu_func(self, context):
          self.layout.menu(OBJECT_MT_mymenu.bl_idname)

          def register():
          bpy.utils.register_class(OBJECT_OT_myoperator)
          bpy.utils.register_class(OBJECT_MT_mymenu)
          bpy.types.VIEW3D_MT_object.append(menu_func)

          def unregister():
          bpy.utils.unregister_class(OBJECT_OT_myooperator)
          bpy.utils.unregister_class(OBJECT_MT_mymenu)
          bpy.types.VIEW3D_MT_object.remove(menu_func)

          if __name__ == "__main__":
          register()





          share|improve this answer











          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "502"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fblender.stackexchange.com%2fquestions%2f136447%2fpython-add-submenu%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2












            $begingroup$

            There were a number of issues. From not registering menu class and having invalid bl_idname's (no capital letters)



            Here is working code. In 2.8 it is a requirement that class names reflect the bl_idname.



            import bpy

            class OBJECT_OT_myoperator(bpy.types.Operator):
            bl_idname = 'object.myoperator'
            bl_label = 'MyOperator'
            bl_options = 'REGISTER', 'UNDO'

            def execute(self, context):
            # ...affairs...
            return 'FINISHED'

            class OBJECT_MT_mymenu(bpy.types.Menu):
            bl_idname = 'object.mymenu'
            bl_label = 'MyMenu'

            def draw(self, context):
            layout = self.layout
            layout.operator(OBJECT_OT_myoperator.bl_idname)

            def menu_func(self, context):
            self.layout.menu(OBJECT_MT_mymenu.bl_idname)

            def register():
            bpy.utils.register_class(OBJECT_OT_myoperator)
            bpy.utils.register_class(OBJECT_MT_mymenu)
            bpy.types.VIEW3D_MT_object.append(menu_func)

            def unregister():
            bpy.utils.unregister_class(OBJECT_OT_myooperator)
            bpy.utils.unregister_class(OBJECT_MT_mymenu)
            bpy.types.VIEW3D_MT_object.remove(menu_func)

            if __name__ == "__main__":
            register()





            share|improve this answer











            $endgroup$

















              2












              $begingroup$

              There were a number of issues. From not registering menu class and having invalid bl_idname's (no capital letters)



              Here is working code. In 2.8 it is a requirement that class names reflect the bl_idname.



              import bpy

              class OBJECT_OT_myoperator(bpy.types.Operator):
              bl_idname = 'object.myoperator'
              bl_label = 'MyOperator'
              bl_options = 'REGISTER', 'UNDO'

              def execute(self, context):
              # ...affairs...
              return 'FINISHED'

              class OBJECT_MT_mymenu(bpy.types.Menu):
              bl_idname = 'object.mymenu'
              bl_label = 'MyMenu'

              def draw(self, context):
              layout = self.layout
              layout.operator(OBJECT_OT_myoperator.bl_idname)

              def menu_func(self, context):
              self.layout.menu(OBJECT_MT_mymenu.bl_idname)

              def register():
              bpy.utils.register_class(OBJECT_OT_myoperator)
              bpy.utils.register_class(OBJECT_MT_mymenu)
              bpy.types.VIEW3D_MT_object.append(menu_func)

              def unregister():
              bpy.utils.unregister_class(OBJECT_OT_myooperator)
              bpy.utils.unregister_class(OBJECT_MT_mymenu)
              bpy.types.VIEW3D_MT_object.remove(menu_func)

              if __name__ == "__main__":
              register()





              share|improve this answer











              $endgroup$















                2












                2








                2





                $begingroup$

                There were a number of issues. From not registering menu class and having invalid bl_idname's (no capital letters)



                Here is working code. In 2.8 it is a requirement that class names reflect the bl_idname.



                import bpy

                class OBJECT_OT_myoperator(bpy.types.Operator):
                bl_idname = 'object.myoperator'
                bl_label = 'MyOperator'
                bl_options = 'REGISTER', 'UNDO'

                def execute(self, context):
                # ...affairs...
                return 'FINISHED'

                class OBJECT_MT_mymenu(bpy.types.Menu):
                bl_idname = 'object.mymenu'
                bl_label = 'MyMenu'

                def draw(self, context):
                layout = self.layout
                layout.operator(OBJECT_OT_myoperator.bl_idname)

                def menu_func(self, context):
                self.layout.menu(OBJECT_MT_mymenu.bl_idname)

                def register():
                bpy.utils.register_class(OBJECT_OT_myoperator)
                bpy.utils.register_class(OBJECT_MT_mymenu)
                bpy.types.VIEW3D_MT_object.append(menu_func)

                def unregister():
                bpy.utils.unregister_class(OBJECT_OT_myooperator)
                bpy.utils.unregister_class(OBJECT_MT_mymenu)
                bpy.types.VIEW3D_MT_object.remove(menu_func)

                if __name__ == "__main__":
                register()





                share|improve this answer











                $endgroup$



                There were a number of issues. From not registering menu class and having invalid bl_idname's (no capital letters)



                Here is working code. In 2.8 it is a requirement that class names reflect the bl_idname.



                import bpy

                class OBJECT_OT_myoperator(bpy.types.Operator):
                bl_idname = 'object.myoperator'
                bl_label = 'MyOperator'
                bl_options = 'REGISTER', 'UNDO'

                def execute(self, context):
                # ...affairs...
                return 'FINISHED'

                class OBJECT_MT_mymenu(bpy.types.Menu):
                bl_idname = 'object.mymenu'
                bl_label = 'MyMenu'

                def draw(self, context):
                layout = self.layout
                layout.operator(OBJECT_OT_myoperator.bl_idname)

                def menu_func(self, context):
                self.layout.menu(OBJECT_MT_mymenu.bl_idname)

                def register():
                bpy.utils.register_class(OBJECT_OT_myoperator)
                bpy.utils.register_class(OBJECT_MT_mymenu)
                bpy.types.VIEW3D_MT_object.append(menu_func)

                def unregister():
                bpy.utils.unregister_class(OBJECT_OT_myooperator)
                bpy.utils.unregister_class(OBJECT_MT_mymenu)
                bpy.types.VIEW3D_MT_object.remove(menu_func)

                if __name__ == "__main__":
                register()






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 days ago









                AivanF.

                1647




                1647










                answered 2 days ago









                batFINGERbatFINGER

                26.8k52977




                26.8k52977



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Blender Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fblender.stackexchange.com%2fquestions%2f136447%2fpython-add-submenu%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    -python

                    Popular posts from this blog

                    Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

                    Frič See also Navigation menuinternal link

                    Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant