Re: [Maya-Python] New items are not added into QMenu

2019-01-14 Thread Tenghao Wang
Hey likage:

I cannot repro your second question. Items are added properly into the
QMenu on my site. For your second question, because you put the "addAction"
(2 of the default items)  under the "_showContextMenu" , so theyare added
when you right clicking the tab.
To be noticed, I am using Pyside2, so I placed all the QtGui to QtWidgets.

I paste the new code, hope that helps:
from PySide2 import QtWidgets
from PySide2 import QtCore

class TabBar(QtWidgets.QTabBar ):
def __init__(self, parent=None):
super(TabBar, self).__init__(parent)

self.qmenu = QtWidgets.QMenu()
self.setExpanding(False)

add_item_action = QtWidgets.QAction('Add new item', self,
triggered=self.add_new_item)
self.qmenu.addAction(add_item_action)
self.qmenu.addSeparator()
def_item_01 = self.qmenu.addAction("Default Item A")
def_item_02 = self.qmenu.addAction("Default Item B")
self.separator =  self.qmenu.addSeparator()

def tabSizeHint(self, index):
return super(TabBar, self).tabSizeHint(index)

def mousePressEvent(self, event):
index = self.tabAt(event.pos())
if event.button() == QtCore.Qt.RightButton:
self._showContextMenu(event.pos(), index)
else:
super(TabBar, self).mousePressEvent(event)

def _showContextMenu(self, position, index):
# Default items

global_position = self.mapToGlobal(self.pos())
self.qmenu.exec_(QtCore.QPoint(
global_position.x() - self.pos().x() + position.x(),
global_position.y() - self.pos().y() + position.y()
))


@QtCore.Slot()
def add_new_item(self):
new_item_name, ok = QtWidgets.QInputDialog.getText(
self,
"name of item",
"Name of new item : "
)
if ok:
new_action = QtWidgets.QAction(new_item_name, self.qmenu,
checkable=True)
self.qmenu.insertAction(self.separator, new_action)


class TabWidget(QtWidgets.QTabWidget):
def __init__(self, parent=None):
super(TabWidget, self).__init__(parent)
self.setTabBar(TabBar(self))

def resizeEvent(self, event):
self.tabBar().setMinimumWidth(self.width())
super(TabWidget, self).resizeEvent(event)


class Window(QtWidgets.QWidget):
def __init__(self):
super(Window, self).__init__()
self.tabs = TabWidget(self)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.tabs)

some_tabs = ['TabA', 'TabB', 'TabC', 'TabD']
for my_tab in some_tabs:
self.tabs.addTab(QtWidgets.QWidget(self), my_tab)

test = Window()
test.show()

Tenghao Wang
Sr. Technical Artist
Visual Concepts

On Mon, Jan 14, 2019 at 4:06 PM likage  wrote:

> Hi everyone, I have a tool which utilizes QTabWidget and the tabs are
> populated with a list of keys from within a dictionary.
> Each of the QMenu are equipped with 3 default options, with one of the
> option called `Add new item` where when User uses that option, a prompt
> dialog will popped up and adds in the user-inputted naming as a new menu
> option into the current QMenu of the tab (where the right mouse click
> happens on)
>
> The problems that I am encountering right now is:
> 1. 2 of the default items in the QMenu are getting added more than once,
> depending on the number of right mouse clicks made on the tool within the
> session
> 2. no new item are added into the QMenu - after I added in a new name for
> the prompt > when performing another right-click, the menu is still showing
> the default items plus 2 additional default items as mentioned in #1
>
> Even so, wondering if this is a possible scenario for tabs + qmenu(s)?
> I asked this because when doing a google search online, it seems that
> QMenu is generally used as a generic menu (eg. multiple buttons adopts the
> same menu etc)
>
> Or should I be adopting to use a different widget for my case?
>
> This is my code - https://pastebin.com/raw/4nakpnm8
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/b9cccfda-a8c5-4f00-bcd2-689ea4777640%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Re: [Maya-Python] Re: Array Attribute on maya python api deformer node

2019-01-14 Thread Tenghao Wang
Hey Yixiong,

_jiggleMap is a user defined list. We need to save the jiggleMap weights
for each *input geometry*.
hJiggleMap.inputValue().asFloat() only returns the weight for the current
vertex ID on the current input geometry.
jiggleMapArray stores all the weight for the current input geometry but
_jiggleMap will store all the jiggleMapArray for all the input geometry.
So I get the jiggleMapArray by using _jiggleMap[geoIndex].

If you do not save this data, you will definitely see this issue: "When I
move one mesh, the other mesh or some components of the other mesh will
perform jiggle effect" Because your weights actually messed up.

On Sun, Jan 13, 2019 at 8:02 PM 徐一雄  wrote:

> Hi Tenghao,
> Thank you for your reply.
> I mainly use python for programming.
> I have changed my code.
> As you said, I can get the world matrix by code:
> *worldMatrix =
> mPreGeomretyHandle.child(jiggleDeformerNode.worldMatrix).asMatrix()*
>
> For getting the jiggle map and other custom paintable map.
> Why do you use following code?
>
> *jiggleMap = _jiggleMap[geoIndex] *
>
> I don't find any variable named *_jiggleMap*.
> Is it the maya inside type variable?
> Can you explain it? Or is there any explaination in maya document?
>
> In my opinion, I used to get jiggleMap by:
> *hJiggleMap = mPreGeomretyHandle.child(jiggleDeformerNode.jiggleMap)*
>
> *jiggleMapArray = []*
> *for i in range(geoIterator.count()):*
> *  jump2Element(hJiggleMap, i)*
> *  jiggleMapArray.append(hJiggleMap.inputValue().asFloat())*
>
> Looking forward to your reply.
> Yixiong Xu
> 2019.01.14
>
> 在 2019年1月13日星期日 UTC+8下午4:20:21,Tenghao Wang写道:
>>
>> Hey Yixiong,
>>
>> "When I move one mesh, the other mesh or some components of the other
>> mesh will perform jiggle effect. That is not what I want."
>> I looked at your code a little bit, it looks like you commented this
>> part: # MFnCompoundAttr.addChild(JiggleDeformerNode.worldMatrix)
>> You should understand "perGeometry" is an array compound attribute and
>> stored information for each input mesh, so you need to have worldmatrix for
>> each input geometry.
>>
>> # access compound array attibute:
>> mGeometryHandle = dataBlock.inputArrayValue(perGeo)
>> # access to each geometry handle, looks like you already implemented
>> "jump2Element" to access to each element in the compound array attribute.
>> jump2Element(mGeometryHandle, geoIndex)
>> mPerGeometryHandle = mGeometryHandle.inputValue()
>> worldMatrix = mPreGeomretyHandle.child(jiggleDeformerNode.worldMatrix)
>>
>> # access to all the paintable maps
>> jiggleMap = _jiggleMap[geoIndex]
>>
>> if you are using Python: _jiggleMap is a list and each element is the
>> jiggleMap list for each input mesh.
>> if you are using C++: _jiggleMap is map: std::map> MFloatArray> _jiggleMap
>>
>> So basically,  the in the deform(self, dataBlock, geoIterator,
>> local2WorldMatrix, geoIndex) function, you have to implement your jiggle
>> algorithm for each input geometry by using "geoIndex".
>> Let me know if you have more questions.
>>
>> Tenghao Wang
>> Sr. Technical Artist
>> Visual Concepts
>>
>> On Sat, Jan 12, 2019 at 2:05 AM 徐一雄  wrote:
>>
>>> Hello Angelo,
>>> Thank you for your reply.
>>> I have some weird effect when I use my custom jiggle deformer on two
>>> different meshes by only one deform node.
>>> First, my custom deform node has some paintable attributes and all of
>>> them are the child of one MFnCompoundAttribute().
>>> When I move one mesh, the other mesh or some components of the other
>>> mesh will perform jiggle effect. That is not what I want.
>>> I think the problem is due to reading(storing) the float array attribute
>>> by different meshes.
>>> So, my question is how to get paintable attributes (mainly
>>> MFloatArray()) of a MFnCompoundAttribute()?
>>>
>>> Thank you very much.
>>> Yixiong Xu
>>>
>>> 在 2017年11月25日星期六 UTC+8上午5:07:03,Angelo写道:

 def inititialize(self)
 self.aBindData = cAttr.create('bindData', 'bindData')
 cAttr.setArray(True)
 def deform(self, data, itGeo, matrix, index):
 bindArrayData = data.inputArrayValue(self.aBindData)
 size = bindArrayData.elementCount()

 for i in range(size):
 bindData = bindArrayData.inputValue()
 someVariable = bindData.child(someAttribute).someDataType

 try:
 bindArrayData.next()
 except:
 pass

 This is how i get data from a compound array attribute. I recommend
 using om.MFnTypedAttribute.MDoubleArray to store weight data since you can
 obtain all the data in one call which is faster. You only need to use
 MArrayDataBuilder when you need to add data on an existing array attribute
 (like outputting an array of matrices). If all you're doing is accessing an
 array, you can just iterate through them using either
 inputArrayData.next(), inputArrayData.jumpToLogicalElement() or
 

[Maya-Python] Re: Array Attribute on maya python api deformer node

2019-01-14 Thread 徐一雄
Hi Tenghao,
The following code is the main code how I get Paintable map values:































*# perGeometryhGeo = 
dataBlock.inputArrayValue(JiggleDeformerNode.perGeo)self.jump2Element(hGeo, 
geoIndex)hGeo.jumpToElement(geoIndex)hPerGeo = hGeo.inputValue()hJiggleMap 
= om.MArrayDataHandle(hPerGeo.child(JiggleDeformerNode.jiggleMap))hStiffMap 
= om.MArrayDataHandle(hPerGeo.child(JiggleDeformerNode.stiffMap))hDampMap = 
om.MArrayDataHandle(hPerGeo.child(JiggleDeformerNode.dampMap))matrix = 
hPerGeo.child(JiggleDeformerNode.worldMatrix).asMatrix()jiggleMapArray = 
[]stiffMapArray = []dampMapArray = []# loop through the geoIterator.count() 
(i.e. mesh geometry) for getting the jiggleMap Value.for i in 
range(geoIterator.count()):  self.jump2Element(hJiggleMap, i)  
hJiggleMap.jumpToElement(i)  
jiggleMapArray.append(hJiggleMap.inputValue().asFloat())  
self.jump2Element(hDampMap, i)  hDampMap.jumpToElement(i)  
dampMapArray.append(hDampMap.inputValue().asFloat())  
self.jump2Element(hStiffMap, i)  hStiffMap.jumpToElement(i)  
stiffMapArray.append(hStiffMap.inputValue().asFloat())*

And my *jump2Element *method is following*:*







*def jump2Element(self, arrayHandle, index):  if index not in 
xrange(arrayHandle.elementCount()):  builder = arrayHandle.builder()
  builder.addElement(index)*

I don't know how to get the  *_jiggleMap *or  *_jiggleMap[geoIndex]* as you 
said.
Can you help me on my code?
Thank you very much.
Yixiong Xu
2019.01.15
arrayHandle.set(builder)在 2017年11月25日星期六 UTC+8上午5:07:03,Angelo写道:
>
> def inititialize(self)
> self.aBindData = cAttr.create('bindData', 'bindData')
> cAttr.setArray(True)
> def deform(self, data, itGeo, matrix, index):
> bindArrayData = data.inputArrayValue(self.aBindData)
> size = bindArrayData.elementCount()
> 
> for i in range(size):
> bindData = bindArrayData.inputValue()
> someVariable = bindData.child(someAttribute).someDataType
> 
> try:
> bindArrayData.next()
> except:
> pass
>
> This is how i get data from a compound array attribute. I recommend using 
> om.MFnTypedAttribute.MDoubleArray to store weight data since you can obtain 
> all the data in one call which is faster. You only need to use 
> MArrayDataBuilder when you need to add data on an existing array attribute 
> (like outputting an array of matrices). If all you're doing is accessing an 
> array, you can just iterate through them using either 
> inputArrayData.next(), inputArrayData.jumpToLogicalElement() or 
> inputArrayData.jumpToPhysicalElement() The docs for MArrayDataHandle and 
> MArrayDataBuilder should describe this pretty well.
> 
>
>
> On Sunday, November 19, 2017 at 4:12:19 PM UTC-6, degne...@googlemail.com 
> wrote:
>>
>> hi together, 
>>
>> I have been trying to write a custom deformer using the maya python api 
>> which basically is a shrink wrap deformer using a custom vector to project 
>> each vertex to the another mesh. 
>>
>> The deformer works fine as is. I really would like to add one option 
>> though which I cannot figure out how to achieve as I am new to the api and 
>> the logics of it in general. I would like to add an array attribute to the 
>> deformer node which for each input geometry vertex saves the index of 
>> another vertex which should be included into the calculation of the deform 
>> function. 
>>
>> My question is: How do I create the array attribute and also how do I 
>> populate and access it in the deform function? 
>>
>> I guess I have already somewhat figured out how to create the Array using 
>> setArray() function and also adding child attributes to it but I still have 
>> troubles understanding where and how to populate and access the array 
>> attribute. There is a lot of information out there concerning MPlugs and 
>> arrayDataBuilder but I simply have not been able to understand it. Can 
>> somebody provide me with an example or explain me how to properly do using 
>> the python api? Any help is greatly appreciated! 
>>
>> This is the code, that I was able put together with the examples 
>> available online: 
>>
>> import maya.OpenMaya as OpenMaya 
>> import maya.OpenMayaAnim as OpenMayaAnim 
>> import maya.OpenMayaMPx as OpenMayaMPx 
>> import maya.cmds as cmds 
>>
>>
>> class surfaceSlideDeformer(OpenMayaMPx.MPxDeformerNode): 
>> kPluginNodeId = OpenMaya.MTypeId(0x0012) 
>> kPluginNodeTypeName = "surfaceSlideDeformer" 
>>
>> bindData = OpenMaya.MObject() 
>> sampleWeights = OpenMaya.MObject() 
>>
>>
>>
>> def __init__(self): 
>> OpenMayaMPx.MPxDeformerNode.__init__(self) 
>> self.accelParameters = OpenMaya.MMeshIsectAccelParams()  # speeds 
>> up intersect calculation 
>>
>>
>> def deform(self, block, geoItr, matrix, index): 
>>
>> # get ENVELOPE 
>> envelope = OpenMayaMPx.cvar.MPxGeometryFilter_envelope 
>> 

[Maya-Python] New items are not added into QMenu

2019-01-14 Thread likage
Hi everyone, I have a tool which utilizes QTabWidget and the tabs are 
populated with a list of keys from within a dictionary.
Each of the QMenu are equipped with 3 default options, with one of the 
option called `Add new item` where when User uses that option, a prompt 
dialog will popped up and adds in the user-inputted naming as a new menu 
option into the current QMenu of the tab (where the right mouse click 
happens on)

The problems that I am encountering right now is:
1. 2 of the default items in the QMenu are getting added more than once, 
depending on the number of right mouse clicks made on the tool within the 
session
2. no new item are added into the QMenu - after I added in a new name for 
the prompt > when performing another right-click, the menu is still showing 
the default items plus 2 additional default items as mentioned in #1

Even so, wondering if this is a possible scenario for tabs + qmenu(s)?
I asked this because when doing a google search online, it seems that QMenu 
is generally used as a generic menu (eg. multiple buttons adopts the same 
menu etc)

Or should I be adopting to use a different widget for my case?

This is my code - https://pastebin.com/raw/4nakpnm8

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/b9cccfda-a8c5-4f00-bcd2-689ea4777640%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] How to select object with unknown parent

2019-01-14 Thread Michael Boon
Another couple of options: 
- the command cmds.rename returns the new name (which is often the name you 
gave it, but not always)
- you can rename without changing the selection by using cmds.rename(oldName, 
newName), and it will still all be selected when you're done.


On Wednesday, 9 January 2019 16:07:18 UTC+11, Francesco wrote:
>
> Hi Jakob,
>
> I never heard of the UUID (I'm still a beginner) but it works perfectly!
>
> I've changed the lines from 48 to 64 to this and it now works exactly as I 
> wanted. Thank you so much!!
>
> #Get UUID of renamed object (UUID to prevent error caused by long names 
>>> not matching)
>>> newLongName= cmds.ls(sl= True, uuid= True)[0]
>>> newNameSelection.insert(0, newLongName)
>>> #Decrease number input by User by 1
>>> startingNumberText= startingNumberText - 1
>>> #Select UUID (re-establish original selection)
>>> for each in newNameSelection:
>>> cmds.select(cmds.ls(each), add= True)
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/43c13fbe-6cfd-4c8c-a8fb-7e8cfdfaa47e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: connectAttr with set groups

2019-01-14 Thread Michael Boon
I think it might help if you included a screenshot of your scene and your 
Outliner.
Does this work if you connect the attributes using the Connection Editor? 
Or in other words, are you asking for help with making the rig work, or 
with converting your rig setup to Python?

On Friday, 11 January 2019 13:26:34 UTC+11, Francesco wrote:
>
> Hi everybody!
>
> I had a question regarding the python connectAttr command in Maya. 
>
> I have created FK controllers that I connected the rotation of to the 
> rotation of a joint chain through the connectAttr command. The FK 
> controllers are in a hierarchy where there is a group and a set group above 
> each controller (something like tail_01_GRP --> tail_01_setGRP --> 
> tail_01_CNTL --> tail_02_GRP --> etc...). What I'm trying to do is create a 
> master controller and connect its rotation to the rotation of the setGRPs 
> through the connectAttr command, so that when I rotate it it rotates all 
> the controllers keeping the rotation to zero. 
>
> The problem is that rotating the setGRPs doesn't rotate the joints 
> (guessing because the actual controller doesn't have any rotation). How 
> would I fix that? I know it could be done with orient constraints but I'm 
> trying to avoid using too many constraints.
>
> Thanks!
>
> -Francesco
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/73e3377f-766c-490c-8274-722de36a4623%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] query current layer in batch render process

2019-01-14 Thread Juan Cristóbal Quesada

Hi,

Im trying to  retrieve the current layer being rendered in a batch 
render process within an interactive maya session.


currently im trying to do it like this:

string $current_render_layer = `editRenderLayerGlobals -q 
-currentRenderLayer`;


And im setting this code as a mel script in the render options tab, as 
"pre" script for preRenderLayerMel.


When i launch the batch render im getting among other things the frame 
number being rendered but i keep getting


the same render layer name when rendering two different ones.

Im guessing this code is not actually querying the batch render process, 
but the Maya GUI tab.


So my question is: how can i retrieve the current render layer that is 
being rendered? Maybe there is another Maya API command that im not 
aware of, or maybe in the render options scripts there are already some 
global variables built in and the render layer would be one of those...


Thanks

--
You received this message because you are subscribed to the Google Groups "Python 
Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/1f4ed9b7-151b-f4cf-9a55-2eeade4eb98e%40gmail.com.
For more options, visit https://groups.google.com/d/optout.