[Maya-Python] Re: remap reference paths on load

2018-12-07 Thread Robert White
I've done this at a past job, and sadly don't have the code in front of me 
anymore.
But from what I remember you get a MFile object from the callback, and can 
edit the paths in that file object, and they will be passed into the 
created reference node after the callback is finished.


On Friday, December 7, 2018 at 8:50:14 AM UTC-6, Michał Frątczak wrote:
>
> So, has anybody found a nice way to remap path to a referenced file based 
> on referenceNode attributes?
> It seems referenceNode is not accessible inside 
> kBeforeCreateReferenceCheck callback
>
>
> On Thursday, December 30, 2010 at 3:12:58 PM UTC+1, Pierre A wrote:
>>
>> Thanks for the link, actually I had already bumped into that one.
>>
>> So let's recap the issue: if the file path does not lead to an existing 
>> file, the reference is not created.
>> This behavior is the same with buildLoadSettings set to True in the 
>> cmds.file function. And when there is no reference node in the scene, 
>> you've lost all your data. Too late.
>>
>> Regarding the callbacks, only MSceneMessage.addCheckFileCallback, 
>> and MSceneMessage.addCheckCallback can be used, with 
>> the kBeforeCreateReferenceCheck enum. These callbacks will be triggered 
>> before reference creation.
>>
>> If you parse a .ma file, there are at least three lines regarding 
>> reference creation:
>> 1/ file -rdi 1 -ns "REF_NS" -dr 1 -rfn "REF_NAME" "/path/to/file.ma";
>> 2/ file -r -ns "REF_NS" -dr 1 -rfn "REF_NAME" "/path/to/file.ma";
>> 3/ createNode reference -n "REF_NAME";
>>
>> The first line does not trigger the remap path popup ("abort..." - "skip" 
>> - "browse..." buttons). The second one does.
>> addCheckFileCallback and addCheckCallback are called just before 2/ is 
>> executed.
>>
>> If you want to monitor the reference node creation, this step is executed 
>> after the path check. It's the line 3/. You can have callbacks thanks 
>> to MDGMessage.addNodeAddedCallback, but it's useless for me.
>>
>> Among MSceneMessage.addCheckFileCallback 
>> and MSceneMessage.addCheckCallback, only addCheckFileCallback is relevant 
>> here because you can modify the MFileObject passed as argument of the 
>> callback (by reference).
>>
>> http://download.autodesk.com/us/maya/2011help/API/class_m_scene_message.html#5e6feb8445b04b7277c0a425a613444f
>>
>> http://download.autodesk.com/us/maya/2011help/API/class_m_message.html#c9d1a728216d6a9618052ad122710fa8
>>
>> Note: Don't forget to set retCode to True with 
>> OpenMaya.MScriptUtil.setBool(retCode, True). The signature of setBool is 
>> bool& but it seems to accept a bool*
>>
>> In my particular case, I need the reference node name (rfn) to be able to 
>> remap the bad path to an existing one. Unfortunately, I have not found a 
>> way to get this piece of info in a straightforward manner.
>> I have tried to use the MCommandMessage.addCommandCallback in order to 
>> see which 2/ "file -r -ns  " is executed, but the callback is called 
>> after the addCheckFileCallback.
>> Of course, the 1/ "file -rdi 1 -ns ... " are executed 
>> before addCheckFileCallback, and I could assume that 2/ commands will be 
>> called in the same order than 1/.
>> Another hack would be to directly parse the .ma file and build a 
>> list/dict for the list of 2/ command lines.
>> Then, by incrementing an index for each addCheckFileCallback call, I 
>> could match the reference name with the corresponding path.
>>
>> The first solution proposed by Christian is clearly simpler, providing 
>> that the renaming process is not harmful. Unfortunately I can not overwrite 
>> the maya files.
>>
>> I think I'll go with a .ma parsing for 2/ lines & building list of 
>> reference node name.
>>
>>

-- 
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/6250d149-c446-4781-8444-ca2af49303b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] clicked signals around a QLabel

2018-12-07 Thread Justin Israel
On Sat, Dec 8, 2018, 8:24 AM likage  wrote:

> I am slightly confused now...
> I apologize in advance, not an excuse but this is my first time dealing
> with QGraphicsXXX and have it integrated with the 'normal' widgets..
>
> In the BaseWidget script - filled_round_rect(), it appears that the icon
> creation is made there and so I added this part in:
>
> def filled_round_rect():
>...
>...
>painter.fillPath(rounded_rect, colour)
>
> # I added the following line
>self.pixmapItem = QtGui.QGraphicsPixmapItem(self.type_icon())
>
> if self.ICON:
>top_right = self.boundingRect().topRight()
>painter.drawPixmap(
>top_right.x() - 35,
>top_right.y() + 5,
>self.pixmapItem # I replace this with self.type_icon()
>)
>
>
> and got the following error... I had thought that it will work, as the
> BaseWidget is within QGraphicsScene?
>
> # TypeError: # 'PySide2.QtGui.QPainter.drawPixmap' called with wrong
> argument types:
> #   PySide2.QtGui.QPainter.drawPixmap(float, float,
> PySide2.QtWidgets.QGraphicsPixmapItem)
> # Supported signatures:
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPoint,
> PySide2.QtGui.QPixmap)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPoint,
> PySide2.QtGui.QPixmap, PySide2.QtCore.QRect)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPointF,
> PySide2.QtGui.QPixmap)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPointF,
> PySide2.QtGui.QPixmap, PySide2.QtCore.QRectF)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRect,
> PySide2.QtGui.QPixmap)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRect,
> PySide2.QtGui.QPixmap, PySide2.QtCore.QRect)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRectF,
> PySide2.QtGui.QPixmap, PySide2.QtCore.QRectF)
> #   PySide2.QtGui.QPainter.drawPixmap(int, int, PySide2.QtGui.QPixmap)
> #   PySide2.QtGui.QPainter.drawPixmap(int, int, PySide2.QtGui.QPixmap,
> int, int, int, int)
> #   PySide2.QtGui.QPainter.drawPixmap(int, int, int, int,
> PySide2.QtGui.QPixmap)
> #  PySide2.QtGui.QPainter.drawPixmap(int, int, int, int,
> PySide2.QtGui.QPixmap, int, int, int, int)
>

Sorry, I had misunderstood part of your previous question based on your
original example of wanting to do a clickable icon with a Qlabel or
Qpushbutton. And I thought you were trying to integrate QWidget into
QGraphicsScene. It is still true that you should avoid them as much as
possible and do all drawing through QGraphicsItem classes.

Your current error is exactly what the exception says. You can't pass a
QGraphics item to the QPainter draw like that. You don't even need a custom
draw call if you are using a QGraphicsPixmapItem for your icon. Just add it
as a child to your item and position it where it needs to go. It will draw
itself and also give you the mouse press handler for its bounds.
Otherwise if you continue drawing your own pixmap (which is fine) then you
have to handle the mouse press in that main item and test if it hits the
bounds for the icon you drew. I find it's a bit easier if the items are
just composed and encapsulate their own event handling. Just think of
parent-child composition with QGraphicsItems

Hope that makes sense.


>
> --
> 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/7d37d380-c1ae-447c-a47d-aacd19976bc0%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 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2ZvvahYD3vdBeMnuf%3D73%3DH11fsY-diwP-MyRuLeF2rrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] clicked signals around a QLabel

2018-12-07 Thread likage
I am slightly confused now...
I apologize in advance, not an excuse but this is my first time dealing 
with QGraphicsXXX and have it integrated with the 'normal' widgets..

In the BaseWidget script - filled_round_rect(), it appears that the icon 
creation is made there and so I added this part in:

def filled_round_rect():
   ...
   ...
   painter.fillPath(rounded_rect, colour)

# I added the following line
   self.pixmapItem = QtGui.QGraphicsPixmapItem(self.type_icon())

if self.ICON:
   top_right = self.boundingRect().topRight()
   painter.drawPixmap(
   top_right.x() - 35,
   top_right.y() + 5,
   self.pixmapItem # I replace this with self.type_icon()
   )


and got the following error... I had thought that it will work, as the 
BaseWidget is within QGraphicsScene?

# TypeError: # 'PySide2.QtGui.QPainter.drawPixmap' called with wrong 
argument types:
#   PySide2.QtGui.QPainter.drawPixmap(float, float, 
PySide2.QtWidgets.QGraphicsPixmapItem)
# Supported signatures:
#   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPoint, 
PySide2.QtGui.QPixmap)
#   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPoint, 
PySide2.QtGui.QPixmap, PySide2.QtCore.QRect)
#   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPointF, 
PySide2.QtGui.QPixmap)
#   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPointF, 
PySide2.QtGui.QPixmap, PySide2.QtCore.QRectF)
#   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRect, 
PySide2.QtGui.QPixmap)
#   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRect, 
PySide2.QtGui.QPixmap, PySide2.QtCore.QRect)
#   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRectF, 
PySide2.QtGui.QPixmap, PySide2.QtCore.QRectF)
#   PySide2.QtGui.QPainter.drawPixmap(int, int, PySide2.QtGui.QPixmap)
#   PySide2.QtGui.QPainter.drawPixmap(int, int, PySide2.QtGui.QPixmap, int, 
int, int, int)
#   PySide2.QtGui.QPainter.drawPixmap(int, int, int, int, 
PySide2.QtGui.QPixmap)
#  PySide2.QtGui.QPainter.drawPixmap(int, int, int, int, 
PySide2.QtGui.QPixmap, int, int, int, int)


-- 
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/7d37d380-c1ae-447c-a47d-aacd19976bc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: remap reference paths on load

2018-12-07 Thread Michał Frątczak
So, has anybody found a nice way to remap path to a referenced file based 
on referenceNode attributes?
It seems referenceNode is not accessible inside kBeforeCreateReferenceCheck 
callback


On Thursday, December 30, 2010 at 3:12:58 PM UTC+1, Pierre A wrote:
>
> Thanks for the link, actually I had already bumped into that one.
>
> So let's recap the issue: if the file path does not lead to an existing 
> file, the reference is not created.
> This behavior is the same with buildLoadSettings set to True in the 
> cmds.file function. And when there is no reference node in the scene, 
> you've lost all your data. Too late.
>
> Regarding the callbacks, only MSceneMessage.addCheckFileCallback, 
> and MSceneMessage.addCheckCallback can be used, with 
> the kBeforeCreateReferenceCheck enum. These callbacks will be triggered 
> before reference creation.
>
> If you parse a .ma file, there are at least three lines regarding 
> reference creation:
> 1/ file -rdi 1 -ns "REF_NS" -dr 1 -rfn "REF_NAME" "/path/to/file.ma";
> 2/ file -r -ns "REF_NS" -dr 1 -rfn "REF_NAME" "/path/to/file.ma";
> 3/ createNode reference -n "REF_NAME";
>
> The first line does not trigger the remap path popup ("abort..." - "skip" 
> - "browse..." buttons). The second one does.
> addCheckFileCallback and addCheckCallback are called just before 2/ is 
> executed.
>
> If you want to monitor the reference node creation, this step is executed 
> after the path check. It's the line 3/. You can have callbacks thanks 
> to MDGMessage.addNodeAddedCallback, but it's useless for me.
>
> Among MSceneMessage.addCheckFileCallback 
> and MSceneMessage.addCheckCallback, only addCheckFileCallback is relevant 
> here because you can modify the MFileObject passed as argument of the 
> callback (by reference).
>
> http://download.autodesk.com/us/maya/2011help/API/class_m_scene_message.html#5e6feb8445b04b7277c0a425a613444f
>
> http://download.autodesk.com/us/maya/2011help/API/class_m_message.html#c9d1a728216d6a9618052ad122710fa8
>
> Note: Don't forget to set retCode to True with 
> OpenMaya.MScriptUtil.setBool(retCode, True). The signature of setBool is 
> bool& but it seems to accept a bool*
>
> In my particular case, I need the reference node name (rfn) to be able to 
> remap the bad path to an existing one. Unfortunately, I have not found a 
> way to get this piece of info in a straightforward manner.
> I have tried to use the MCommandMessage.addCommandCallback in order to see 
> which 2/ "file -r -ns  " is executed, but the callback is called after 
> the addCheckFileCallback.
> Of course, the 1/ "file -rdi 1 -ns ... " are executed 
> before addCheckFileCallback, and I could assume that 2/ commands will be 
> called in the same order than 1/.
> Another hack would be to directly parse the .ma file and build a list/dict 
> for the list of 2/ command lines.
> Then, by incrementing an index for each addCheckFileCallback call, I could 
> match the reference name with the corresponding path.
>
> The first solution proposed by Christian is clearly simpler, providing 
> that the renaming process is not harmful. Unfortunately I can not overwrite 
> the maya files.
>
> I think I'll go with a .ma parsing for 2/ lines & building list of 
> reference node name.
>
>

-- 
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/b38c7e80-4d56-483c-9f7a-9a83fde7bec9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Can't read worldMatrix of custom Python API 2.0 node

2018-12-07 Thread Marcus Ottosson
> Can you use fn.dagPath().inclusiveMatrix() ?

Yes! That looks very promising (for completeness, it was `getPath()` rather
than `dagPath()`). I worked around it this time around, by getting the
parent of any shape, and fetching it's matrix instead. Not as neat, so will
experiment with your suggestion as well.

Thank you!

On Tue, 4 Dec 2018 at 21:25, Michael Boon  wrote:

> Can you use fn.dagPath().inclusiveMatrix() ?
>
> On Wednesday, 5 December 2018 02:02:25 UTC+11, Marcus Ottosson wrote:
>>
>> Mm, I'm looking to get a matrix out of Maya 2015 and above, so a patch
>> would unfortunately not help me in this case. Do you know of another way of
>> getting hold of that matrix?
>>
>> On Tue, 4 Dec 2018 at 14:50, Tim Fowler  wrote:
>>
>>> Hmm...looks like I tried that on an unreleased version of Maya (and a
>>> Debug version too).  Just tried again in Maya 2018 and got the same error
>>> as you.  I'll take a quick look and see if I can figure out what fixed it,
>>> but I should warn you that API fixes can sometimes be tricky to get into
>>> Updates since those typically have to remain binary compatible.
>>>
>>> -Tim
>>>
>>> On Tue, Dec 4, 2018 at 9:26 AM Marcus Ottosson 
>>> wrote:
>>>
 Wuw! What version of Maya is that, and what OS? I'm on Windows, Maya
 2018. Hadn't considered it might be a version or OS thing, will have a look
 at that.

 On Tue, 4 Dec 2018 at 14:14, Tim Fowler  wrote:

> Not sure what you're hitting.  That last line gives me...
>
> om.MFnMatrixData(plug.asMObject()).matrix()
> # Result: maya.api.OpenMaya.MMatrix(((1, 0, 0, 0), (0, 1, 0, 0), (0,
> 0, 1, 0), (0, 0, 0, 1))) #
>

 --
>>> 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/CALKD2WpxdzsLdBWBnhSS_cMoxMZ33v4FRQ9P%2BPjiUaB%3Dwi7xtA%40mail.gmail.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
> https://groups.google.com/d/msgid/python_inside_maya/1100aff0-f149-4c2d-93e0-2c99af1e5912%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 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBxkto%2BtUx3B2XcBqLjPyXbdXL4XxWg2fmFhz-y-eg%2Bdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.