Unbind skin in Autodesk Maya - python

Despite following the Maya command documentation shown here:
import maya.cmds as cmds
cmds.bindSkin( unbind=True ) # While my object is selected.
or
cmds.bindSkin( 'mySelectedObj', unbind=True ) # Specifying which object to unbind
results in:
Error: RuntimeError: file line 1: No skin partition
found in scene.
I'm also getting the same error in MEL. But the script editor's history shows a doDetachSkin command - and searching on it just keeps leading me back to the bind skin command.
How should I correctly write this command when following the example on the documentation is giving me the error message?
P.S.: My selection is a geo mesh that is skinned to a few joints.

Did you tried with selection ?
mySelectedObj = cmds.ls(sl=True) or []
if mySelectedObj:
cmds.bindSkin(mySelectedObj[0], unbind=True )

import maya.mel as mel
skinC = mel.eval('doDetachSkin "2" { "1","1" }')
Decided to work around the issue instead by just invoking the mel command that I see in the script editor history. Not ideal but serves my purposes for now.
If anyone knows of a better way or can clue in why following the documentation isn't working, please feel free to chime in.

If Unbind Skin Python command doesn't work:
import maya.cmds as cmds
cmds.bindSkin( unbind=True, bp=False )
Try its great old MEL equivalent:
DetachSkin;

It looks like bindSkin can only delete the jointCluster, and you can try skinCluster.
import pymel.core as pm
pm.skinCluster(objname, edit=True, unbind=True)enter code here

Related

How can I get the attribute of a selected key in the graph editor in Maya

I need to get the attribute from a key (or keys) selected in the graph editor. Preferably in Python. I was trying to follow this tutorial to figure it out in MEL, but unfortunately when I try it, it just gets me all of the attributes instead of just the selected one.
This was my attempt in Python
import pymel.core as pm
objects=pm.ls(sl=1)
attrs=pm.selectionConnection('graphEditor1FromOutliner', q=1, object=1)
for attr in attrs:
buffer = []
buffer=attr.split(".")
attribute=buffer[1]
print attribute
I'm still relatively new to Python, so any help would be appreciated! Thanks so much!
Are you able to use the keyframe command to get what you need? From MEL, with keys selected in the Graph Editor and running this command, you get the Return below, showing the attributes of the selected keys following an under_score.
Not sure how you would integrate this into your Python script, but hopefully it's a start...
keyframe -sl -q -attribute -name;
//Result pCube1_translateX pCube1_translateY pCube1_rotateY
I think this should solve your issue.
import pymel.core as pm
objects=pm.ls(sl=1)
attrs = pm.selectionConnection('graphEditor1FromOutliner', q=1, object=1)
buffer = []
for attr in attrs:
buffer = attr.split(".")
buffer = buffer[1]
print buffer

Toggle X-Ray Mode in Maya using Python

I'm trying to bind some Python code to a key so I can toggle X-Ray mode in Maya.
One thing that's confusing me is that when I run this line of code...
def xrayQuery():
cmds.modelEditor('modelPanel4', q=True, xr=True)
xrayQuery()
no result is returned, even though I've queried xray mode. But when I run just the command without the function...
cmds.modelEditor('modelPanel4', q=True, xr=True)
I get what I expected the first time, which is a boolean result based on whether or not xray mode is enabled. Can anyone tell me why this is?
I'm very new to python inside Maya, so any help will be much appreciated! Thanks!
You need to call return if you want the user-defined function to return the same output as called inside.
Like below:
def xrayQuery():
return cmds.modelEditor('modelPanel4', q=True, xr=True)
On a side note, if you could explain the purpose to write a function instead of calling the original function, it would be helpful to understand the use-case
So I've figured out a way to simplify what I was trying to achieve, which was a few lines of code to toggle the x-ray view mode on and off for a specific viewport. I was able to eliminate the need for if else statements by using the 'not' operator in this block of code:
import maya.cmds as cmds
def xray_toggle():
result = cmds.modelEditor('modelPanel4', q=True, xr=True)
cmds.modelEditor('modelPanel4', e=True, xr=not result)
xray_toggle()

python WMI screen brightness adjuster gets error 0x8004100c

I'm currently working on a script that creates a tray icon that allows the user to adjust screen brightness through menu options. The source code, written in python 3.6.8, can be found as a paste HERE. There seems to be an error message coming up when trying to select one of the brightness options, seen HERE. I did some reading and found that the error I'm getting (0x8004100c) refers to a feature or operation not being supported. Are there any workarounds available for this?
Thank you in advance.
code: https://pastebin.com/sLbyE9yb
error: https://pastebin.com/Xs7wHk73
WMI error reference: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants
gist: https://gist.github.com/imri0t/12e768e3d7e08734b85ae532d56090e1
(also if anyone can let me know if there's a way to keep the script from dying after an action is made it would be appreciated)
modules needed: pip install infi.systray / pip install wmi
code snip that I believe produces the error:
from infi.systray import SysTrayIcon
import wmi
def brightness_50(systray):
'''brightness: 50%'''
b = 50
c = wmi.WMI(namespace='root\\wmi')
br = c.WmiMonitorBrightnessMethods()[0]
br.WmiSetBrightness(3, b) #b will be a precentage / 100
menu = (("brightness: 100%", None, brightness_50))
systray = SysTrayIcon("icon.ico", "brightness", menu)
systray.start()

Maya Python polySeparate error

import maya.cmds as cmds
cmds.polyChipOff(ltz=0.1, kft=False)
cmds.polySeparate()
When running the polySeparate command, I get the error "polySeparate needs exactly 1 polygonal obkect or polygonal faces from one object" despite having a face duplicated and selected.
Total noob here, wondering why this is the case?
Looks like you need to pass an object to the polySeparate function.
Since you already have a face selected you can use cmds.ls to get the selected object:
import maya.cmds as cmds
cmds.polyChipOff(ltz=0.1, kft=False)
cmds.polySeparate(cmds.ls(sl=True, objectsOnly=True)[0])
Works as expected when testing with new objects.

wxPython RichTextCtrl.SetStyle([...]) Issue

I want to change the font of a RichTextControl in wxPython but I've encountered an issue that I can not figure out. Here is the relevant code:
import wx
import wx.richtext as rt
#....
codebox = rt.RichTextCtrl(self)
f = wx.Font(10, wx.TELETYPE, wx.NORMAL, wx.NORMAL)
s = wx.TextAttr(font = f)
codebox.SetStyle((0,0), s)
The last line is what throws an error. Specifically:
TypeError: in method 'RichTextCtrl_GetStyle',
expected argument 3 of type 'wxTextAttrEx &'
I based my code on stuff I found online, however I immediately recognized that my version of wxPython was different because the tuple I supplied as a range in SetStyle() was instead supplied as two different arguments, however when I imitated that setup the interpreter threw me an error and asked me to use a tuple.
Does anyone know where I'm going wrong? Or, of course, a workaround? Thanks.
s should be of type wx.TextAttrEx, not wx.TextAttr like you have done.
SetStyle(self, range, style)
Set the style for the text in range to style
Parameters:
range
(type=RichTextRange)
style
(type=TextAttrEx)

Categories

Resources