Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to make a switch button in MEL script

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
Anonymous
3736 Views, 16 Replies

How to make a switch button in MEL script

Swap smooth wireframe button

Hello I search how to made a swap button for smooth wireframe 

I've those command line 

 

-the first to put on smooth:

///////////////////////////////////////////////////////////////////////////////////////

 

setAttr hardwareRenderingGlobals.lineAAEnable true; modelEditor -e -smoothWireframe true modelPanel4;

 

updateModelPanelBar MainPane|viewPanes|modelPanel4|modelPanel4|modelPanel4;

dR_setModelEditorTypes;

 

///////////////////////////////////////////////////////////////////////////////////////

 

The second to put off smooth

 

///////////////////////////////////////////////////////////////////////////////////////

setAttr hardwareRenderingGlobals.lineAAEnable false; modelEditor -e -smoothWireframe false modelPanel4;

 

updateModelPanelBar MainPane|viewPanes|modelPanel4|modelPanel4|modelPanel4;

dR_setModelEditorTypes;

///////////////////////////////////////////////////////////////////////////////////////

 

 

 

Thanks for your help

 

If anyone can explain me what the following command line does

 

updateModelPanelBar MainPane|viewPanes|modelPanel4|modelPanel4|modelPanel4;

dR_setModelEditorTypes;

16 REPLIES 16
Message 2 of 17
sean.heasley
in reply to: Anonymous

Hi @Anonymous

 

I almost have this figured out Smiley Tongue

 

The only issue is that smooth preview only works when a model is selected. In this case, the MEL script looks for a name "mymesh". So in your scene whatever object you're working with you'd want the name to match the script.

 

To turn on the wireframe and smooth the mesh use this:

 

setWireframeOnShadedOption true modelPanel4;
setAttr mymesh.displaySmoothMesh 2;

 

And to turn off the wireframe and the smooth preview use this:

 

setWireframeOnShadedOption false modelPanel4;
setAttr mymesh.displaySmoothMesh 0;

 

I'm going to test a little bit more and see if I can figure out how to get around the naming so all you have to do is have the object selected.

 

 

Message 3 of 17
sean.heasley
in reply to: sean.heasley

Hi @Anonymous

 

I'm just checking in again to see if you need more help with this. Did the suggestion I provided on Friday work for you?

If so, please click Accept as Solution on the posts that helped you so others in the community can find them easily.

 

 

 

 

Message 4 of 17
Anonymous
in reply to: sean.heasley

You can use the `ls` command to retrieve the name of the selected asset.

<PRE>
ls -sl
pymel.core.general.ls(selection=True)
</PRE>

You could probably mix that with the type command to specify shape nodes, as by default Maya will select the transform node. not sure if that’s necessary.

Side note: you can’t do code formatting apparently on the mobile site. Kind of a pain...

Cheers,
Mike
Message 5 of 17
NandoStille
in reply to: Anonymous

I assume you mean the Smooth Wireframe feature of the Legacy Viewport?

 

viewPanels = cmds.getPanel( type='modelPanel' )
if viewPanels:
    v = cmds.modelEditor(viewPanels[0], q=True, smoothWireframe=True)
    cmds.modelEditor(viewPanels[0], e=True, smoothWireframe=not v)

 

Is the Smooth Wireframe option of VP2 (lineAAEnable) doing anything for anybody?

Message 6 of 17
Anonymous
in reply to: NandoStille

I realize that I was not very clear in my question. I'm just trying to make a button for the shelf to switch between wireframe on and off

Message 7 of 17
NandoStille
in reply to: Anonymous

So, it's just about Wireframe vs Shading, not about the "Smooth Wireframe" viewport renderer option?

But what about the buttons on the view panel toolbar or the hotkeys (4, 5) which are supposed to fulfill this task? What are you missing with those?

Message 8 of 17
sean.heasley
in reply to: NandoStille

Hi @Anonymous

 

Ah in that case there is a button by default at the top of the viewport that looks like this:

 

wireframe.png

 

 

 

Please let me know if this helps or if you need any more assistance!

 

 

If one or more of these posts helped answer your question, please click Accept as Solution on the posts that helped you so others in the community can find them easily.

 

 

 

Kudos are greatly appreciated. Everyone likes a thumbs up!

 

 

Message 9 of 17
sean.heasley
in reply to: sean.heasley

Hi @Anonymous

 

I'm just checking in again to see if you need more help with this. Did the suggestion I provided yesterday work for you?

If so, please click Accept as Solution on the posts that helped you so others in the community can find them easily.

 

 

Message 10 of 17
Anonymous
in reply to: sean.heasley

Hi! I'm looking to script this switch button to put it on a marking menu.
Message 11 of 17
sean.heasley
in reply to: Anonymous

Hi @Anonymous

 

Okay then the code I linked before should work:

 

Add this code to a button to turn Wireframe ON:

 

setWireframeOnShadedOption true modelPanel4;

 

Add this code to a button to turn Wireframe OFF:

 

 

setWireframeOnShadedOption false modelPanel4;

 

So add these two lines to two separate buttons for a shelf and then you'll have two options on your custom marking menu to turn wireframe on/off.

 

Please let me know if this helps or if you need any more assistance!

 

 

If one or more of these posts helped answer your question, please click Accept as Solution on the posts that helped you so others in the community can find them easily.

 

 

 

Kudos are greatly appreciated. Everyone likes a thumbs up!

 

 

 

 

 

Message 12 of 17
Anonymous
in reply to: sean.heasley

Hi! I've already done this two button thanks.
I just want to know if it's possible to make a single on/off button.
I know I'm really annoying. Smiley LOL

Message 13 of 17
sean.heasley
in reply to: Anonymous

Hi @Anonymous

 

You aren't annoying at all don't worry!

 

I think I know what will work for you!

 

I just created a button and have the command set to turn on the wireframe. So naturally when you press the button the wireframe turns on and if you press it again nothing happens.

 

I then added the turn off code to the double click section so if you double click the button the wireframe turns off.

 

Now, when I have the marking menu, if I highlight over it the wireframe turns on, and if I go to highlight again, there's a little option box and if I hover over that it turns off!

 

Please try this and let me know if it works for you!

 

 

If one or more of these posts helped answer your question, please click Accept as Solution on the posts that helped you so others in the community can find them easily.

 

 

 

Kudos are greatly appreciated. Everyone likes a thumbs up!

 

 

Message 15 of 17
sean.heasley
in reply to: Anonymous

Hi @Anonymous

 

I'm just checking in again to see if you need more help with this. Did the suggestion I provided yesterday work for you?

If so, please click Accept as Solution on the posts that helped you so others in the community can find them easily.

 

 

Message 16 of 17
xiao_feng
in reply to: Anonymous

this one worked for me (second link)

coming from 3ds max, this is one of the functions I really missed 😛

Message 17 of 17
xiao_feng
in reply to: Anonymous

Also, in addition to the wireframe toggle, I found this thread on Polycount with with a wireframe on shaded toggle as well. Really nice, I got my F3 and F4 keys back Smiley Tongue

https://polycount.com/discussion/148884/maya-hotkeying-shading-wireframe-on-shaded

 

Hope this helps for those coming over learning Maya

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report