Re: [Maya-Python] Best way to check if current panel is viewport

2019-06-24 Thread AK Eric
I've used this for a looong time:

import maya.cmds as mc
modelPanel = mc.playblast(activeEditor=True)

That's it:  The playblast command always knows the last active panel it 
could use, so querying that has always worked for me.

-- 
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/4f718022-a3b4-4ea0-903d-384c06e04209%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Best way to check if current panel is viewport

2019-06-05 Thread Tim Fowler
I'm typing this off the top of my head while watching the basketball game,
but I think there are a couple options...

1. Pretty sure the getPanel command has a "type" flag where you can give it
the name of the panel you got back from the "active" call.  That should
return something like "modelPanel" if it is a viewport.
2. The M3dView class has an active3dView static function that I'm pretty
sure returns the last active viewport if the current active panel is some
other type.  If that's the case then this is the one you want.


On Wed, Jun 5, 2019 at 8:18 PM kiteh  wrote:

> Hey Tomas, thanks for getting back.
>
> I actually managed to get it working by using the following (too much?):
>
> model_panels = []
> focus_panel = cmds.getPanel(withFocus=True)
> # Check if current panel is a modelPanel
> if cmds.objectTypeUI(focus_panel) == "modelEditor":
> cmds.modelEditor(focus_panel, edit=True, imagePlane=True)
> else:
> for panel in cmds.lsUI(editors=True):
> if "modelPanel" in panel:
> model_panels.append(panel)
>
> for model_panel in model_panels:
> if cmds.modelEditor(model_panel, query=True, activeView=True):
> try:
> cmds.modelEditor(model_panel, edit=True,
> imagePlane=True)
> except Exception as e:
> pass
>
> Basically it checks if the current focus panel is of modelPanel. If it is
> not, it will query all modelPanels and sets the main viewport (not the tear
> off etc)
>
> If anyone has a better approach to this, do feel free to chip in :)
>
> --
> 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/365fea6f-4a0a-4ad8-831b-dd80bb545243%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/CALKD2WokHE%3DQZDY_68Bi1peqmdEK%2BaT0UG8HovS2WnuXJpRZ%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Best way to check if current panel is viewport

2019-06-05 Thread kiteh
Hey Tomas, thanks for getting back.

I actually managed to get it working by using the following (too much?):

model_panels = []
focus_panel = cmds.getPanel(withFocus=True)
# Check if current panel is a modelPanel
if cmds.objectTypeUI(focus_panel) == "modelEditor":
cmds.modelEditor(focus_panel, edit=True, imagePlane=True)
else:
for panel in cmds.lsUI(editors=True):
if "modelPanel" in panel:
model_panels.append(panel)

for model_panel in model_panels:
if cmds.modelEditor(model_panel, query=True, activeView=True):
try:
cmds.modelEditor(model_panel, edit=True, 
imagePlane=True)
except Exception as e:
pass

Basically it checks if the current focus panel is of modelPanel. If it is 
not, it will query all modelPanels and sets the main viewport (not the tear 
off etc)

If anyone has a better approach to this, do feel free to chip in :)

-- 
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/365fea6f-4a0a-4ad8-831b-dd80bb545243%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Best way to check if current panel is viewport

2019-06-05 Thread tomas mikulak
I come up with this:

import maya.cmds as mc

viewports = mc.getPanel(type='modelPanel')
visible = mc.getPanel(vis=True)
active_panel=''

for i in viewports:
if i in visible:
print('\n[vieport]: '+i)
active_panel = i

vieportCam = mc.modelPanel(active_panel, q=True, camera = True)

mc.setFocus(i)

if you have only one viewport in layout it is good solution, don't know
about other scenario.

tomas

st 5. 6. 2019 o 19:48 tomas mikulak  napísal(a):

> yes, that is true, you might query if panel has some attrs only vieport
> could have, I might check it later
>
> On Wed, 5 Jun 2019 at 19:37, kiteh  wrote:
>
>> Hi Tomas,
>>
>> I totally get what you mean.
>> But say, if I have make my commands into a shelf icon command..
>>
>> And if my last panel, which could be the Outliner or the Attribute
>> Editor, the mostly used panels (viewports too of course) and I hit on that
>> shelf icon command that I did, it will also error out.
>> As such, I asked this question..
>>
>>
>>
>>
>> On Tuesday, June 4, 2019 at 11:52:00 PM UTC-7, tomas mikulak wrote:
>>>
>>> I use python line (lower left )to test that code and when it works I
>>> know it will once viewport is active. When you use script editor it is used
>>> as active panel.
>>> tomas
>>>
>>> st 5. 6. 2019 o 1:06 kiteh  napísal(a):
>>>
 What is the best way to check if the current panel is a viewport type?
 i am trying to set the 'Image Plane' option (under Show > Image Planes)
 and currently I am doing it as follows:

 panel = cmds.getPanel(withFocus=True)
 cmds.modelEditor(panel, edit=True, imagePlane=True)

 with the assumption that the current panel is a 'valid' viewport.

 But this will fails, eg. if I am running the above code in my
 scriptEditor as that is my current focus panel.

 --
 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/46a4a173-e0a2-41a0-bcac-038118ce7c2b%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/726fa1b7-fb2b-4e0b-aa6a-70e49a91d5eb%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/CAEUzAD2TdA1GZb%3Dgx6Nk%2B-8-AP4s3or4mDyrkdaL0%3DSnADSC0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Best way to check if current panel is viewport

2019-06-05 Thread tomas mikulak
yes, that is true, you might query if panel has some attrs only vieport
could have, I might check it later

On Wed, 5 Jun 2019 at 19:37, kiteh  wrote:

> Hi Tomas,
>
> I totally get what you mean.
> But say, if I have make my commands into a shelf icon command..
>
> And if my last panel, which could be the Outliner or the Attribute Editor,
> the mostly used panels (viewports too of course) and I hit on that shelf
> icon command that I did, it will also error out.
> As such, I asked this question..
>
>
>
>
> On Tuesday, June 4, 2019 at 11:52:00 PM UTC-7, tomas mikulak wrote:
>>
>> I use python line (lower left )to test that code and when it works I know
>> it will once viewport is active. When you use script editor it is used as
>> active panel.
>> tomas
>>
>> st 5. 6. 2019 o 1:06 kiteh  napísal(a):
>>
>>> What is the best way to check if the current panel is a viewport type?
>>> i am trying to set the 'Image Plane' option (under Show > Image Planes)
>>> and currently I am doing it as follows:
>>>
>>> panel = cmds.getPanel(withFocus=True)
>>> cmds.modelEditor(panel, edit=True, imagePlane=True)
>>>
>>> with the assumption that the current panel is a 'valid' viewport.
>>>
>>> But this will fails, eg. if I am running the above code in my
>>> scriptEditor as that is my current focus panel.
>>>
>>> --
>>> 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/46a4a173-e0a2-41a0-bcac-038118ce7c2b%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/726fa1b7-fb2b-4e0b-aa6a-70e49a91d5eb%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/CAEUzAD3ubT5Rvk5QHqVECtA%3DaDmex8OFCFtUFu1fL2qCBeyLPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Best way to check if current panel is viewport

2019-06-05 Thread kiteh
Hi Tomas,

I totally get what you mean.
But say, if I have make my commands into a shelf icon command..

And if my last panel, which could be the Outliner or the Attribute Editor, 
the mostly used panels (viewports too of course) and I hit on that shelf 
icon command that I did, it will also error out.
As such, I asked this question..




On Tuesday, June 4, 2019 at 11:52:00 PM UTC-7, tomas mikulak wrote:
>
> I use python line (lower left )to test that code and when it works I know 
> it will once viewport is active. When you use script editor it is used as 
> active panel.
> tomas
>
> st 5. 6. 2019 o 1:06 kiteh > napísal(a):
>
>> What is the best way to check if the current panel is a viewport type?
>> i am trying to set the 'Image Plane' option (under Show > Image Planes) 
>> and currently I am doing it as follows:
>>
>> panel = cmds.getPanel(withFocus=True)
>> cmds.modelEditor(panel, edit=True, imagePlane=True)
>>
>> with the assumption that the current panel is a 'valid' viewport.
>>
>> But this will fails, eg. if I am running the above code in my 
>> scriptEditor as that is my current focus panel.
>>
>> -- 
>> 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/46a4a173-e0a2-41a0-bcac-038118ce7c2b%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/726fa1b7-fb2b-4e0b-aa6a-70e49a91d5eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Best way to check if current panel is viewport

2019-06-05 Thread tomas mikulak
I use python line (lower left )to test that code and when it works I know
it will once viewport is active. When you use script editor it is used as
active panel.
tomas

st 5. 6. 2019 o 1:06 kiteh  napísal(a):

> What is the best way to check if the current panel is a viewport type?
> i am trying to set the 'Image Plane' option (under Show > Image Planes)
> and currently I am doing it as follows:
>
> panel = cmds.getPanel(withFocus=True)
> cmds.modelEditor(panel, edit=True, imagePlane=True)
>
> with the assumption that the current panel is a 'valid' viewport.
>
> But this will fails, eg. if I am running the above code in my scriptEditor
> as that is my current focus panel.
>
> --
> 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/46a4a173-e0a2-41a0-bcac-038118ce7c2b%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/CAEUzAD3nJ4Bj0YCz5UrVY97QBh9ERASkbhcDJVRa--ixh%3DGQwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Best way to check if current panel is viewport

2019-06-04 Thread kiteh
What is the best way to check if the current panel is a viewport type?
i am trying to set the 'Image Plane' option (under Show > Image Planes) and 
currently I am doing it as follows:

panel = cmds.getPanel(withFocus=True)
cmds.modelEditor(panel, edit=True, imagePlane=True)

with the assumption that the current panel is a 'valid' viewport.

But this will fails, eg. if I am running the above code in my scriptEditor 
as that is my current focus panel.

-- 
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/46a4a173-e0a2-41a0-bcac-038118ce7c2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.