How to show/hide items(?) in active view on maya with python?












0














Now I know how to hide all the nurbs curves on active viewport. But how can I do same thing for all the items on show menu on viewport such as cameras, manipulator, grid...etc at the same time?



I think that I need to use for loop for this but I need some guide. Thank you.



import maya.cmds as cmds

actView = cmds.getPanel(wf=True)

if cmds.modelEditor(actView, q=True, nurbsCurves=True) == 1:
cmds.modelEditor(actView, e=True, nurbsCurves=False)









share|improve this question



























    0














    Now I know how to hide all the nurbs curves on active viewport. But how can I do same thing for all the items on show menu on viewport such as cameras, manipulator, grid...etc at the same time?



    I think that I need to use for loop for this but I need some guide. Thank you.



    import maya.cmds as cmds

    actView = cmds.getPanel(wf=True)

    if cmds.modelEditor(actView, q=True, nurbsCurves=True) == 1:
    cmds.modelEditor(actView, e=True, nurbsCurves=False)









    share|improve this question

























      0












      0








      0







      Now I know how to hide all the nurbs curves on active viewport. But how can I do same thing for all the items on show menu on viewport such as cameras, manipulator, grid...etc at the same time?



      I think that I need to use for loop for this but I need some guide. Thank you.



      import maya.cmds as cmds

      actView = cmds.getPanel(wf=True)

      if cmds.modelEditor(actView, q=True, nurbsCurves=True) == 1:
      cmds.modelEditor(actView, e=True, nurbsCurves=False)









      share|improve this question













      Now I know how to hide all the nurbs curves on active viewport. But how can I do same thing for all the items on show menu on viewport such as cameras, manipulator, grid...etc at the same time?



      I think that I need to use for loop for this but I need some guide. Thank you.



      import maya.cmds as cmds

      actView = cmds.getPanel(wf=True)

      if cmds.modelEditor(actView, q=True, nurbsCurves=True) == 1:
      cmds.modelEditor(actView, e=True, nurbsCurves=False)






      python hide show maya






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 at 3:22









      user8972552

      344




      344
























          1 Answer
          1






          active

          oldest

          votes


















          0














          here is a method to hide everything :



          actView = cmds.getPanel(wf=True) # actView='modelPanel4'
          # list the flag we use to hide, not that alo hide nearly everything
          hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos', 'sel']
          # value is used to make visible or to hide (0 is for hiding)
          value = 0
          # flags is used to create a dictionary that will be used in the command to do : manipulators = 0
          flags = { i : value for i in hide_attrs }
          # the double star unpack a python dictionnary the key = value, i.e in this case : alo = 0, hud = 0....
          cmds.modelEditor(actView, e=1, **flags)


          if you want to be more specific, you can build another dictionnary for visible attrs



          # merge dictionnaries
          def merge_two_dicts(x, y):
          # In Python 3.5 or greater, : z = {**x, **y}
          # or w = {'foo': 'bar', 'baz': 'qux', **y}

          z = x.copy() # start with x's keys and values
          z.update(y) # modifies z with y's keys and values & returns None
          return z

          actView = cmds.getPanel(wf=True) # actView='modelPanel4'
          hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
          vis_attrs = ['sel']
          hide_flags = { i : 0 for i in hide_attrs }
          vis_flags = { i : 1 for i in vis_attrs }
          flags = merge_two_dicts(hide_flags, vis_flags)
          cmds.modelEditor(actView, e=1, **flags)


          but if i were you, I would just encapsulate this into a single def :



          def set_actviewVis(value, attrs=list):
          actView = cmds.getPanel(wf=True) # actView='modelPanel4'
          flags = { i : value for i in attrs }
          cmds.modelEditor(actView, e=1, **flags)

          hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
          set_actviewVis(0, hide_attrs)
          vis_attrs = ['sel']
          set_actviewVis(1, vis_attrs)





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f53440289%2fhow-to-show-hide-items-in-active-view-on-maya-with-python%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









            0














            here is a method to hide everything :



            actView = cmds.getPanel(wf=True) # actView='modelPanel4'
            # list the flag we use to hide, not that alo hide nearly everything
            hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos', 'sel']
            # value is used to make visible or to hide (0 is for hiding)
            value = 0
            # flags is used to create a dictionary that will be used in the command to do : manipulators = 0
            flags = { i : value for i in hide_attrs }
            # the double star unpack a python dictionnary the key = value, i.e in this case : alo = 0, hud = 0....
            cmds.modelEditor(actView, e=1, **flags)


            if you want to be more specific, you can build another dictionnary for visible attrs



            # merge dictionnaries
            def merge_two_dicts(x, y):
            # In Python 3.5 or greater, : z = {**x, **y}
            # or w = {'foo': 'bar', 'baz': 'qux', **y}

            z = x.copy() # start with x's keys and values
            z.update(y) # modifies z with y's keys and values & returns None
            return z

            actView = cmds.getPanel(wf=True) # actView='modelPanel4'
            hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
            vis_attrs = ['sel']
            hide_flags = { i : 0 for i in hide_attrs }
            vis_flags = { i : 1 for i in vis_attrs }
            flags = merge_two_dicts(hide_flags, vis_flags)
            cmds.modelEditor(actView, e=1, **flags)


            but if i were you, I would just encapsulate this into a single def :



            def set_actviewVis(value, attrs=list):
            actView = cmds.getPanel(wf=True) # actView='modelPanel4'
            flags = { i : value for i in attrs }
            cmds.modelEditor(actView, e=1, **flags)

            hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
            set_actviewVis(0, hide_attrs)
            vis_attrs = ['sel']
            set_actviewVis(1, vis_attrs)





            share|improve this answer




























              0














              here is a method to hide everything :



              actView = cmds.getPanel(wf=True) # actView='modelPanel4'
              # list the flag we use to hide, not that alo hide nearly everything
              hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos', 'sel']
              # value is used to make visible or to hide (0 is for hiding)
              value = 0
              # flags is used to create a dictionary that will be used in the command to do : manipulators = 0
              flags = { i : value for i in hide_attrs }
              # the double star unpack a python dictionnary the key = value, i.e in this case : alo = 0, hud = 0....
              cmds.modelEditor(actView, e=1, **flags)


              if you want to be more specific, you can build another dictionnary for visible attrs



              # merge dictionnaries
              def merge_two_dicts(x, y):
              # In Python 3.5 or greater, : z = {**x, **y}
              # or w = {'foo': 'bar', 'baz': 'qux', **y}

              z = x.copy() # start with x's keys and values
              z.update(y) # modifies z with y's keys and values & returns None
              return z

              actView = cmds.getPanel(wf=True) # actView='modelPanel4'
              hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
              vis_attrs = ['sel']
              hide_flags = { i : 0 for i in hide_attrs }
              vis_flags = { i : 1 for i in vis_attrs }
              flags = merge_two_dicts(hide_flags, vis_flags)
              cmds.modelEditor(actView, e=1, **flags)


              but if i were you, I would just encapsulate this into a single def :



              def set_actviewVis(value, attrs=list):
              actView = cmds.getPanel(wf=True) # actView='modelPanel4'
              flags = { i : value for i in attrs }
              cmds.modelEditor(actView, e=1, **flags)

              hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
              set_actviewVis(0, hide_attrs)
              vis_attrs = ['sel']
              set_actviewVis(1, vis_attrs)





              share|improve this answer


























                0












                0








                0






                here is a method to hide everything :



                actView = cmds.getPanel(wf=True) # actView='modelPanel4'
                # list the flag we use to hide, not that alo hide nearly everything
                hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos', 'sel']
                # value is used to make visible or to hide (0 is for hiding)
                value = 0
                # flags is used to create a dictionary that will be used in the command to do : manipulators = 0
                flags = { i : value for i in hide_attrs }
                # the double star unpack a python dictionnary the key = value, i.e in this case : alo = 0, hud = 0....
                cmds.modelEditor(actView, e=1, **flags)


                if you want to be more specific, you can build another dictionnary for visible attrs



                # merge dictionnaries
                def merge_two_dicts(x, y):
                # In Python 3.5 or greater, : z = {**x, **y}
                # or w = {'foo': 'bar', 'baz': 'qux', **y}

                z = x.copy() # start with x's keys and values
                z.update(y) # modifies z with y's keys and values & returns None
                return z

                actView = cmds.getPanel(wf=True) # actView='modelPanel4'
                hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
                vis_attrs = ['sel']
                hide_flags = { i : 0 for i in hide_attrs }
                vis_flags = { i : 1 for i in vis_attrs }
                flags = merge_two_dicts(hide_flags, vis_flags)
                cmds.modelEditor(actView, e=1, **flags)


                but if i were you, I would just encapsulate this into a single def :



                def set_actviewVis(value, attrs=list):
                actView = cmds.getPanel(wf=True) # actView='modelPanel4'
                flags = { i : value for i in attrs }
                cmds.modelEditor(actView, e=1, **flags)

                hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
                set_actviewVis(0, hide_attrs)
                vis_attrs = ['sel']
                set_actviewVis(1, vis_attrs)





                share|improve this answer














                here is a method to hide everything :



                actView = cmds.getPanel(wf=True) # actView='modelPanel4'
                # list the flag we use to hide, not that alo hide nearly everything
                hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos', 'sel']
                # value is used to make visible or to hide (0 is for hiding)
                value = 0
                # flags is used to create a dictionary that will be used in the command to do : manipulators = 0
                flags = { i : value for i in hide_attrs }
                # the double star unpack a python dictionnary the key = value, i.e in this case : alo = 0, hud = 0....
                cmds.modelEditor(actView, e=1, **flags)


                if you want to be more specific, you can build another dictionnary for visible attrs



                # merge dictionnaries
                def merge_two_dicts(x, y):
                # In Python 3.5 or greater, : z = {**x, **y}
                # or w = {'foo': 'bar', 'baz': 'qux', **y}

                z = x.copy() # start with x's keys and values
                z.update(y) # modifies z with y's keys and values & returns None
                return z

                actView = cmds.getPanel(wf=True) # actView='modelPanel4'
                hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
                vis_attrs = ['sel']
                hide_flags = { i : 0 for i in hide_attrs }
                vis_flags = { i : 1 for i in vis_attrs }
                flags = merge_two_dicts(hide_flags, vis_flags)
                cmds.modelEditor(actView, e=1, **flags)


                but if i were you, I would just encapsulate this into a single def :



                def set_actviewVis(value, attrs=list):
                actView = cmds.getPanel(wf=True) # actView='modelPanel4'
                flags = { i : value for i in attrs }
                cmds.modelEditor(actView, e=1, **flags)

                hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
                set_actviewVis(0, hide_attrs)
                vis_attrs = ['sel']
                set_actviewVis(1, vis_attrs)






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 23 at 11:40

























                answered Nov 23 at 10:29









                DrWeeny

                1,4321912




                1,4321912






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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.


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





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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.


                    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%2fstackoverflow.com%2fquestions%2f53440289%2fhow-to-show-hide-items-in-active-view-on-maya-with-python%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







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)