Please correct my mel to python command (Show & Hide NURBS Curves in MAYA Hotkey in python).

Please correct my mel to python command (Show & Hide NURBS Curves in MAYA Hotkey in python).

amaterasu-qbb
Collaborator Collaborator
4,679 Views
9 Replies
Message 1 of 10

Please correct my mel to python command (Show & Hide NURBS Curves in MAYA Hotkey in python).

amaterasu-qbb
Collaborator
Collaborator

I am rewriting the mel command on this site to a python command for learning python.(maya2019)

https://www.patrickgambleanimation.com/post/show-hide-nurbs-curves-in-maya-hotkey

code[mel]:

string $activePanel = `getPanel -wf`;

if (`modelEditor -q -nurbsCurves $activePanel` == 1) {

   modelEditor -e -nurbsCurves 0 $activePanel;

} else {

   modelEditor -e -nurbsCurves 1 $activePanel;

}

 my code[python]

import maya.cmds as cmds

activePanel = cmds.getPanel(withFocus=True)

if cmds.modelEditor(query=True, nurbsCurves=True,  activePanel=True):
    cmds.modelEditor(edit=True, nurbsCurves=False, activePanel)

else:
    cmds.modelEditor(edit=True, nurbsCurves=True, activePanel)

 If I search for Technical Document in the linked command, I can find

  • getPanel<undoable, NOT queryable, NOT editable.>(-wf= withFocus boolean)
  • modelEditor<undoable, queryable, and editable.>[-nc= nurbsCurves boolean]

I can not find string $activePanel so this could be a variable. 

 

I am a beginner in programming. learning on Zurbrick's site.
http://zurbrigg.com/tutorials/beginning-python-for-maya/2-1-maya-commands

 

It's not finished yet. Please give me various advice.

 

Accepted solutions (1)
4,680 Views
9 Replies
Replies (9)
Message 2 of 10

mspeer
Consultant
Consultant

Hi!

Place "activePanel" at the beginning.

if cmds.modelEditor(activePanel, query=True, nurbsCurves=True):
    cmds.modelEditor(activePanel, edit=True, nurbsCurves=False)

else:
    cmds.modelEditor(activePanel, edit=True, nurbsCurves=True)

 

Message 3 of 10

amaterasu-qbb
Collaborator
Collaborator

Hi! @mspeer thanks for the reply.

I got this error.

# Error: line 1: TypeError: file <maya console> line 5: Invalid flag 'activePanel'

am I doing wrong in a variable?

0 Likes
Message 4 of 10

stuzzz
Collaborator
Collaborator

hi,

activePanel = cmds.getPanel(withFocus=True)

if cmds.modelEditor(activePanel, query=True, nurbsCurves=True):
    cmds.modelEditor(activePanel, edit=True, nurbsCurves=False)

else:
    cmds.modelEditor(activePnale, edit=True, nurbsCurves=True)
Message 5 of 10

stuzzz
Collaborator
Collaborator
oupss too late
Message 6 of 10

mspeer
Consultant
Consultant

Hi!

 

@amaterasu-qbb 

It seems you still use "activePanel=True".

This is a variable and you can't use this with a flag, so simply use "activePanel" as shown in the examples provided by @stuzzz  and me.

For further help, please provide your code which produces the error.

Message 7 of 10

amaterasu-qbb
Collaborator
Collaborator

Hi! I was moving sorry for the reply.

 

thank you, everyone. I made it!

# Show hide curves in python
import maya.cmds as cmds

activePanel = cmds.getPanel(withFocus=True)

if cmds.modelEditor(activePanel, query=True, nurbsCurves=True):
    cmds.modelEditor(activePanel, edit=True, nurbsCurves=False)

else:
    cmds.modelEditor(activePanel, query=True, edit=True, nurbsCurves=True)

thank you for helping me!

0 Likes
Message 8 of 10

mspeer
Consultant
Consultant
Accepted solution

Hi!

Although this works, the last line is still wrong.

It should be:

# Show hide curves in python
import maya.cmds as cmds

activePanel = cmds.getPanel(withFocus=True)

if cmds.modelEditor(activePanel, query=True, nurbsCurves=True):
    cmds.modelEditor(activePanel, edit=True, nurbsCurves=False)

else:
    cmds.modelEditor(activePanel, edit=True, nurbsCurves=True)

You don't want to query something, you want to set something.

Message 9 of 10

amaterasu-qbb
Collaborator
Collaborator

Thanks. I didn't need to query it because I already queried it with if cmds.modelEditor(activePanel, query=True, nurbsCurves=True): as you said.
And it worked.

0 Likes
Message 10 of 10

deepakamba13
Enthusiast
Enthusiast

deepakamba13_0-1625513252310.png

please can you make Tweak/Marquee keyboard hotkey