Invalid flag "testVisibility" in Autodesk Maya 2016 - python

I'm trying to determine if a set of mesh nodes is currently visible or not. Using pymel and isVisible() works, but it's a huge performance hit.
Looking through the documentation, I found something that would (hopefully) solve my problem, the flag testVisibility on the Command hide.
According to the documentation the flag command will return a value that tells me if the specified nodes are visible or not.
The problem is, that flag doesn't exist.
import maya.cmds as cmds
cmds.sphere(name='testsphere')
cmds.hide('testsphere', testVisibility = True)
Gives an error
# Error: Invalid flag 'testVisibility'
# Traceback (most recent call last):
# File "<maya console>", line 4, in <module>
# TypeError: Invalid flag 'testVisibility' #
Same thing with the shortname of the flag "tv", as well as doing the whole thing in MEL: hide -testVisibility;.
The documentation includes this flag since Maya 2016. This is also the Maya version that I am using currently (more specifically, Maya 2016 SP5). Using the built-in link to the python documentation I arrive at the same documentation as I posted above. Looking through the changelog of SP6 doesn't mention anything of it either, so I assume it won't solve my problem.
I tried the same command on Maya 2017 and it works. That won't help me much though because that's not the Maya version that our team uses currently.
I can't contact Autodesk support because I'm not a subscriber (thanks autodesk, great help).
So my questions are:
is there something that I'm missing/that I overlooked? Are these flags only implemented in some kind of super duper developer plugin? Do Maya versions only use the API of the previous versions or something?
is there a way to check if a command has a flag, without try-catching it?
any workarounds that are not as performance draining as the pymel route I mentioned above?

You're right. I also tried tv flag for hide command and it definitely doesn't work.
Try setter/getter:
import maya.cmds as cmds
cmds.sphere(name="testsphere")
cmds.setAttr("testsphere.visibility", False)
cmds.getAttr("testsphere.visibility")
I tested it in Maya 2016/2018.
# Result: False #

Related

pysnmp.smi.error.MibNotFoundError: No module __SNMP-FRAMEWORK-MIB loaded at <pysnmp.smi.builder.MibBuilder object at 0x0418A110>

I'm just starting out in Python so please bear with me.
I've been trying to find a solution to this error for the last 3 days in google, Stack Overflow, Github, python.org and also snmplabs.com. I have progressed from other errors (thanks in part to the above websites) but this one has me stumped and I cannot seem to resolve it.
I'm running the following versions of stuff:
Windows 10 Enterprise 64-bit
python 3.6, pysnmp 4.4.4, pyasn1 0.2.3
and I am using paramiko for ssh and tkinter as a GUI
My project is composed using Visual Studio Code v1.20.1
Basically I have made a python app that logs into a cisco switch and adds a vlan to a trunk, replaces it with another vlan, or removes both vlans
Each time one of these vlan changes is made the script sends an snmp trap to an NMS saying what was just done. The trap is just an OID as follows:
def sendTrap(system):
debug.setLogger(debug.Debug('msgproc'))
next(sendNotification(SnmpEngine(),
CommunityData('blahblah'),
UdpTransportTarget(('1.1.1.1', 162)),
ContextData(),
'trap',
# sequence of custom OID-value pairs
[ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'), OctetString(system))]))
Some other stuff happens as well, like the background colour when a change is made, and a timer begins which resets everything back after a predetermined amount of time.
The program works flawlessly when I run it as a python script.
However, when I use cx_freeze to create an exe file of my little app everything works EXCEPT for the snmp trap and I currently get the following traceback error:
2018-02-17 02:17:39,956 pysnmp: running pysnmp version 4.4.4
2018-02-17 02:17:39,957 pysnmp: debug category 'msgproc' enabled
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python\Python36-32\lib\site-packages\pysnmp\entity\engine.py", line 91, in __init__
'__SNMP-FRAMEWORK-MIB', 'snmpEngineMaxMessageSize')
File "C:\Python\Python36-32\lib\site-packages\pysnmp\smi\builder.py", line 409, in importSymbols
'No module %s loaded at %s' % (modName, self)
pysnmp.smi.error.MibNotFoundError: No module __SNMP-FRAMEWORK-MIB loaded at pysnmp.smi.builder.MibBuilder object at 0x034C9150
The module __SNMP-FRAMEWORK-MIB is located in C:\Python\Python36-32\Lib\site-packages\pysnmp\smi\mibs\instances and I have this folder included in the setup file as follows (Now THIS is where I think I have gone wrong):
options = {
'build_exe': {
#'packages':packages,
'include_files':[
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
'C:\\Python\\Python36-32\\Lib\\site-packages\\idna',
'C:\\Python\\Python36-32\\Lib\\site-packages\\pysnmp\\smi\\mibs',
'C:\\Python\\Python36-32\\Lib\\site-packages\\pysnmp\\smi\\mibs\\instances'
],
},
}
*Please ignore the weird indents as I was trying to get the format correct for presenting it here
Apologies but, although I've done a lot of reading about this over the past few days I'm not totally clued up on things like packages, modules, options and includes so it's all a bit alien to me.
If someone can see where I'm going wrong or if I need to provide more information please let me know. Any assistance would be much appreciated.
Thanks
With some great help from snippsat at python-forum I finally got this to work.
Essentially cx_freeze wouldn't play nice so we ended up using pyinstaller with a little tweak to the "spec" file (As detailed at python-forum) and everything is now working.

maya python cmds.file(query = True, shortName = True) not working

I noticed a strange thing in Maya. I would like to know if you guys got the same problem or if I am doing something wrong?
There is the cmds.file command. The documentation says it got a "shortName" flag which should return the currently opend scenename without the complete path.
cmds.file(query = True, shortName = True)
# Error: RuntimeError: file <maya console> line 1: Flag cannot be queried. #
Also the doc. says that shortName is a queryable flag.
I also tried to just use the sceneName flag which should return the complete path of the currently opend file. Which indeed it does. But when I set it to "False" it gives me the same error you saw above.
This happens on Maya 2016 and Maya 2017.
The doc: http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/CommandsPython/file.html#flagshortName
Thanks for reading and have a nice day!
I'm not sure if you tried the command in the right way, but what the documentation says is:
When used with a main query flag it indicates that the file name returned will be the short name
So, in this situation the main query flag could be sceneName and then the shortName can be specified, to get just the filename.
import maya
print maya.cmds.file(query=True, sceneName=True, shortName=True)
Anyway, if you want to have a little more control over the specific path manipulation, may I suggest you to use the python os module? Or even better the os.path module?

pywinauto find_elements() returns ElementNotFoundError

I'm trying to automate a simple app using pywinauto & Python 3.6. The app has a Windows "Open" dialog like this and I want to click on the "Cancel" button:
I used SWAPY to get the class_name and control_id attributes for the button.
Now the problem is that when I call the find_element() method with these parameters it raises an ElementNotFoundError. Here's my code:
cancel_button = pywinauto.findwindows.find_element(class_name="button", control_id=2)
I've tried (class_name="button", control_id="2"), (class_name="Button", control_id=2) but they all give the same error. The same problem occurs for any other element I try to find on this dialog.
So how do I use the attributes read from SWAPY? I didn't find the official pywinauto documentation to be very useful. It doesn't explain a lot of things clearly.
EDIT: I decided not to use the find_elements method and instead used find_windows() to get a handle to the Open dialog.
w_open_handle = pywinauto.findwindows.find_windows(title=u'Open', class_name='#32770')[0]
I then get a WindowSpecification object using this handle:
w_open = app.window_(handle=w_open_handle)
I then call:
w_open['Cancel'].click()
and this works. Now I want to enter a file name in the "File name:" edit box and click on Open button to open that file. So I do this:
w_open['File name:'].type_keys("abc.txt")
This works. I printed out the control identifiers using print_control_identifiers() and got the name for Open button. So using draw_outline() I draw a boundary outside it and it shows the correct button.
w_open['SplitButton6'].draw_outline()
But calling .click() method on 'SplitButton6' throws a WindowSpecification class has no 'click' method error. Any idea what's causing this? The error seems to be misleading since WindowSpec class does have a .click method.
Correct answer is that you missed top_level_only=False (it's True by default because higher level API calls it at least twice). Then you may have 2 controls matching this criterion (maybe from different applications). find_element is a low level function. I wouldn't recommend its direct usage (the code is too long, there are many pitfalls that were taken into account on a higher level API).
>>> pywinauto.findwindows.find_element(class_name="Button", control_id=2, top_level_only=False)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "...\pywinauto\findwindows.py", line 98, in find_element
raise exception
ElementAmbiguousError: There are 2 elements that match the criteria {'class_name': 'Button', 'control_id': 2, 'top_level_only': False}
>>> pywinauto.findwindows.find_element(class_name="Button", title='Cancel', top_level_only=False)
<win32_element_info.HwndElementInfo - 'Cancel', Button, 395554>
Using higher level API (Application object and WindowSpecifications described in the Guide) you shouldn't care about passing process id, backend name and other things to find_element every time.
P.S. In my mind SWAPY could be significantly improved, but it's not maintained last year. I hope to re-write it in the future with smaller code base and MS UI Automation support. But currently fully automatic script generator is a higher priority.
EDIT:
This button w_open['SplitButton6'].draw_outline() could be detected as general HwndWrapper object instead of ButtonWrapper. You can check it using this:
w_open['SplitButton6'].wrapper_object()
And this is what exactly written in the Getting Started Guide (which you said you've read).
Fortunately you can use method .click_input() for any control:
w_open['SplitButton6'].click_input()
I can say more: WindowSpecification does NOT have click method. It's a method of ButtonWrapper which is instantiated dynamically. For example these statements work the same way (but Python can hide .wrapper_object() call):
w_open['SplitButton6'].wrapper_object().click_input()
w_open['SplitButton6'].click_input()
And again this is all described in the Getting Started Guide. Please read the whole guide. You will find many useful high level things. I can advise for some corner cases if something is still not clear.

How to make SublimeText support Python 3's annotations?

I tested both SublimeText 2 and 3 and both are buggy:
If you test this code, you'll notice all code right after the : will not be syntax highlighted properly.
def foo(a, b) -> str:
# Nothing gets properly colored from here
# A bunch of codeā€¦
return "bar"
I found some links explaining how to add your own syntax highlighting rules but I didn't find how to modify those already implemented in a attempt to fix them.
EDIT: Now knowing where to modify default syntax highlighting rules thanks to MattDMo, I tried to change line 385 of my file
<key>end</key>
<string>(\))\s*(?:(\:)|(.*$\n?))</string>
to
<key>end</key>
<string>(\))\s*(?:\->\s*[A-Za-z_][A-Za-z0-9_]*\s*)?(?:(\:)|(.*$\n?))</string>
But it didn't work.
I created my own version ~2 months ago, it still has some (serious) bugs, so don't hesitate to report those bugs on this github page or contribute a fix for it:
https://github.com/petervaro/python
Although there is a Cython version which is generated from the same file as the Python itself -> but it's absolutely a work-in-progress tmLanguage, so don't use it!:)
UPDATE: It is now "stable" and ready for the serious work, so use it, share it, and please report bugs! :)

Control-Alt-Delete from python or command line

I've done some research but I would like to be able to call control-alt-delete from python. If that is not possible is it possible to call it from command line because then I could just use that command in python because I can call command lines in python. If someone could point me in the right direction that would be great. this is for a task manager written with wxPython.
edit:
im trying to launch the windows security and from a user answer i tried
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("{CONTROL}{ALT}{DELETE}")
and i get this error
Traceback (most recent call last):
File "C:/Python27/tescontrol.py", line 4, in <module>
shell.SendKeys("{CONTROL}{ALT}{DELETE}")
File "<COMObject WScript.Shell>", line 2, in SendKeys
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024809), None)
You surely mean activating the Windows Security window. In this case:
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("^(%{DELETE})")
UPDATE
The above code seems not to work because of the reasons described in other posts. In that case, the alternative is to create a similar window and call from Python the different programs/functions called by the real Windows Security window.
On reading OP's comments to the original question, OP's final need is to change a user's password. This can be done with:
from win32com import adsi
ads_obj = adsi.ADsGetObject("WinNT://localhost/%s,user" % username)
ads_obj.SetPassword(password)
I just tested this in my PC, so is final information (though not necessarily correct; this is up to the OP :-) ).
UPDATE 2: Copying the later as a separate answer as comments seem to indicate that all of the answer doesn't work. This is correct for the SendKeys proposition, which doesn't work.
If what you want to do is to shutdown or restart the system, Windows has a 'shutdown' command and linux's typically have 'shutdown' and 'reboot' commands.
Check out the following thread:
http://forums.codeguru.com/showthread.php?330557-Ctrl-alt-delete
According to it, VNC uses something like this:
PostMessage HWND_BROADCAST, WM_HOTKEY, 0, MakeLong(MOD_ALT Or MOD_CONTROL, VK_DELETE)
I suspect you would need to use ctypes or PyWin32 to do something like this. I would probably go with ctypes since it's cross-platform, however, even with ctypes you would probably need to write a special method for each OS that you support.
On reading OP's comments, his/her original need was to change the user's password. In fact, this can be done with:
from win32com import adsi
ads_obj = adsi.ADsGetObject("WinNT://localhost/%s,user" % username)
ads_obj.SetPassword(password)
You can use vncdotool library
At:
lib
And use vncdotool by:
os.system("vncdotool key ctrl-alt-del")
Here is one way you can try at least:
(It may only work on windows 7)
import sys
import localize
import os
value_from = 0
Integer = _clear_type_cache(get_object[win\%sys(vnc_value*cache)* value_from])
def Interclass(event):
try:
[<'ctrl'><'alt'><'del'>{%user_value(*object)*value_form}] % cache
except:
{%TOPMOST%'TEMP'_%VALUE_REGISTRY}*
else:
print("No value")
As far as I know, Ctrl-Alt-Delete is protected for security reasons, so programs cannot use it. (At least in Windows 7 and before.)

Categories

Resources