How to make a switch button in MEL script

Anonymous

How to make a switch button in MEL script

Anonymous
Not applicable
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;

0 Likes
Reply
Accepted solutions (2)
3,734 Views
16 Replies
Replies (16)

sean.heasley
Alumni
Alumni

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.

 

 

sean.heasley
Alumni
Alumni

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.

 

 

 

 

Anonymous
Not applicable
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

NandoStille
Advocate
Advocate

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?

Anonymous
Not applicable

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

0 Likes

NandoStille
Advocate
Advocate

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?

0 Likes

sean.heasley
Alumni
Alumni

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!

 

 

0 Likes

sean.heasley
Alumni
Alumni

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.

 

 

0 Likes

Anonymous
Not applicable
Hi! I'm looking to script this switch button to put it on a marking menu.
0 Likes

sean.heasley
Alumni
Alumni
Accepted solution

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!

 

 

 

 

 

Anonymous
Not applicable

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

0 Likes

sean.heasley
Alumni
Alumni
Accepted solution

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!

 

 

sean.heasley
Alumni
Alumni

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.

 

 

xiao_feng
Explorer
Explorer

this one worked for me (second link)

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

xiao_feng
Explorer
Explorer

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