Re: [Maya-Python] Help with a closure in Maya and Python.

2016-10-28 Thread Padraig Ó Cuínn
Hi Marcus,

I am trying to get to selection() which is in a maya code file, The UI is 
built under a create_window() function, in a UI specific file. The code is 
separated from the UI. 

under create_window() I have another function nested in it for the button 
to call selection() but it is not reaching due to the enclosure,

File_1 
from file_2 import selection as sel


def create_window():

 def pushButton():
 file_2.sel()

File_2
import pymel.core


def selection():
pymel.core.selection(n="transforms")

as you can see there are two files and due to the closure I can't execute 
the selection function. I know I could easily throw it under the pushbutton 
inside the UI but i strictly want UI code alone and maya code alone on 
another file. 

Thanks again

-- 
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/722fd689-aeb6-4298-a54b-90e718ae211c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Help with a closure in Maya and Python.

2016-10-28 Thread Robert White
Does this work by chance?

# File_1 
from file_2 import selection as sel


def create_window():

 def pushButton():
 sel()



On Friday, October 28, 2016 at 10:46:26 AM UTC-5, Padraig Ó Cuínn wrote:
>
> Hi Marcus,
>
> I am trying to get to selection() which is in a maya code file, The UI is 
> built under a create_window() function, in a UI specific file. The code 
> is separated from the UI. 
>
> under create_window() I have another function nested in it for the button 
> to call selection() but it is not reaching due to the enclosure,
>
> File_1 
> from file_2 import selection as sel
>
>
> def create_window():
> 
>  def pushButton():
>  file_2.sel()
>
> File_2
> import pymel.core
>
>
> def selection():
> pymel.core.selection(n="transforms")
>
> as you can see there are two files and due to the closure I can't execute 
> the selection function. I know I could easily throw it under the pushbutton 
> inside the UI but i strictly want UI code alone and maya code alone on 
> another file. 
>
> Thanks again
>

-- 
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/a6ed571e-c9ef-4274-a263-cfd47d779837%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] How do I make maya 2015 font bigger by stylesheet ?

2016-10-28 Thread oglop
That works but in production environment, I have no power to edit that file, 
plus our maya is on a network share. It affects everyone.

maybe I can use mount -bind to replace that file, but I have no root 
privileges. or maybe I can use https://github.com/proot-me/PRoot , but I can 
not compile it in office. and it may affect our maya launcher.

-- 
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/3ff2ed91-8136-405e-9574-4640a50558eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Help with a closure in Maya and Python.

2016-10-28 Thread Padraig Ó Cuínn
Nope no difference

On Friday, 28 October 2016 08:58:37 UTC-7, Robert White wrote:
>
> Does this work by chance?
>
> # File_1 
> from file_2 import selection as sel
>
>
> def create_window():
> 
>  def pushButton():
>  sel()
>
>
>
> On Friday, October 28, 2016 at 10:46:26 AM UTC-5, Padraig Ó Cuínn wrote:
>>
>> Hi Marcus,
>>
>> I am trying to get to selection() which is in a maya code file, The UI 
>> is built under a create_window() function, in a UI specific file. The 
>> code is separated from the UI. 
>>
>> under create_window() I have another function nested in it for the 
>> button to call selection() but it is not reaching due to the enclosure,
>>
>> File_1 
>> from file_2 import selection as sel
>>
>>
>> def create_window():
>> 
>>  def pushButton():
>>  file_2.sel()
>>
>> File_2
>> import pymel.core
>>
>>
>> def selection():
>> pymel.core.selection(n="transforms")
>>
>> as you can see there are two files and due to the closure I can't execute 
>> the selection function. I know I could easily throw it under the pushbutton 
>> inside the UI but i strictly want UI code alone and maya code alone on 
>> another file. 
>>
>> Thanks again
>>
>

-- 
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/e898505d-1c98-4e19-aeb4-8b6ecd906eb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Help with a closure in Maya and Python.

2016-10-28 Thread Robert White
What error exactly are you getting when you try that?


On Friday, October 28, 2016 at 12:50:46 PM UTC-5, Padraig Ó Cuínn wrote:
>
> Nope no difference
>
> On Friday, 28 October 2016 08:58:37 UTC-7, Robert White wrote:
>>
>> Does this work by chance?
>>
>> # File_1 
>> from file_2 import selection as sel
>>
>>
>> def create_window():
>> 
>>  def pushButton():
>>  sel()
>>
>>
>>
>> On Friday, October 28, 2016 at 10:46:26 AM UTC-5, Padraig Ó Cuínn wrote:
>>>
>>> Hi Marcus,
>>>
>>> I am trying to get to selection() which is in a maya code file, The UI 
>>> is built under a create_window() function, in a UI specific file. The 
>>> code is separated from the UI. 
>>>
>>> under create_window() I have another function nested in it for the 
>>> button to call selection() but it is not reaching due to the enclosure,
>>>
>>> File_1 
>>> from file_2 import selection as sel
>>>
>>>
>>> def create_window():
>>> 
>>>  def pushButton():
>>>  file_2.sel()
>>>
>>> File_2
>>> import pymel.core
>>>
>>>
>>> def selection():
>>> pymel.core.selection(n="transforms")
>>>
>>> as you can see there are two files and due to the closure I can't 
>>> execute the selection function. I know I could easily throw it under the 
>>> pushbutton inside the UI but i strictly want UI code alone and maya code 
>>> alone on another file. 
>>>
>>> Thanks again
>>>
>>

-- 
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/8fa92a6d-64d9-48bc-ad46-615ac0d1fa41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: [Maya-Python] Help with a closure in Maya and Python.

2016-10-28 Thread Padraig O Cuinn
I don’t get any errors it just doesn’t pass but it does freeze up on me.

 

Padraig O Cuinn

Technical Director / Artist

-- 
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/005c01d23147%24b83f7050%2428be50f0%24%40Gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Help with a closure in Maya and Python.

2016-10-28 Thread Justin Israel
On Sat, 29 Oct 2016, 7:18 AM Padraig O Cuinn 
wrote:

> I don’t get any errors it just doesn’t pass but it does freeze up on me.
>
Please provide a small reproduction of the problem via pastebin or gist.
After Roberts suggestion to correct a naming issue, I can't see anything
else wrong in your small snippets of code.

>
>
> Padraig O Cuinn
>
> Technical Director / Artist
>
> --
> 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/005c01d23147%24b83f7050%2428be50f0%24%40Gmail.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/CAPGFgA1h_A1r4qeos06OQpC9Gjr5yPF-CaSexvHEAe5Rcquyzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] How to get case accurate path on windows

2016-10-28 Thread Chad_Fox
Hi all,

I'd like to confirm if the paths written in maya (on windows) has the 
correct character case. In otherwords I need to verify the path is good for 
use on Linux.

I have the following solution, but glob is ... not very fast. 

Would like to know if anyone here has come accross an effective/fast 
solution for this problem.

import glob
import re
import os

def fix_path_case( path ):
   case_on_disk_path = glob.glob( re.sub( r'([^:])(?=[/\\]|$)', r'[\1]' , 
path ) )[0]
   slash_fixed_path =  os.path.realpath(case_on_disk_path )
   return slash_fixed_path
   
# Real path on disk is  ''W:/Shows/Proj/Pub/TEX/Proj_skin_DIF.1001.TIF'
bad_case_texture_path = 'W:/shOws/PRoj/PUB/tex/proj_skin_DIF.1001.tif' 
#path in maya

fixed_path = fix_path_case( path = bad_case_texture_path )



Thanks!

Chad

-- 
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/11dfb149-d63d-4f1b-88d0-c02de401e86e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Using strings as a check in __init__?

2016-10-28 Thread Cesar Saez
There's a fundamental problem with this in my view, the dounder init method
of a class gets executed _after_ the instance (aka self) get created, doing
checks there means you basically create an object that can potentially be
invalid by passing the wrong thing and that's a problem.

You could use a classmethod instead or even a dounder new, but I would go
the other way around by using a simple function instead! Classes are a very
powerful tool but it's a bit overkill on this case (imho anyway).

Cheers!

-- 
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/CAPamJi9JY90vPHxJxaNJpU2C3D6zPix1TUv%2BcfXmMTN1gTW-5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] rename in PyMel

2016-10-28 Thread bartlomiej . karon
Hi

I have a question. I want to create in pymel a 'while True' loop
how can I add variable to my rename object? 

example

i = 1
while True:
   pm.rename('group' i '|old_name, 'new_name')



so for example i = 1 so my 'group' should be 'group1'. I am not sure how can I 
make it. How to add variable input into the name of the object?

-- 
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/debb1b4e-9e16-46d5-8f8b-f5c6a5003b38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] How to get case accurate path on windows

2016-10-28 Thread Justin Israel
On Sat, Oct 29, 2016 at 8:39 AM Chad_Fox  wrote:

> Hi all,
>
> I'd like to confirm if the paths written in maya (on windows) has the
> correct character case. In otherwords I need to verify the path is good for
> use on Linux.
>
> I have the following solution, but glob is ... not very fast.
>
> Would like to know if anyone here has come accross an effective/fast
> solution for this problem.
>
> import glob
> import re
> import os
>
> def fix_path_case( path ):
>case_on_disk_path = glob.glob( re.sub( r'([^:])(?=[/\\]|$)', r'[\1]' ,
> path ) )[0]
>slash_fixed_path =  os.path.realpath(case_on_disk_path )
>return slash_fixed_path
>
> # Real path on disk is  ''W:/Shows/Proj/Pub/TEX/Proj_skin_DIF.1001.TIF'
> bad_case_texture_path = 'W:/shOws/PRoj/PUB/tex/proj_skin_DIF.1001.tif'
> #path in maya
>
> fixed_path = fix_path_case( path = bad_case_texture_path )
>
>
>
> Thanks!
>
> Chad
>

Part of this problem, for me, would be something I would think to solve
through conventions at a facility. Are people actually using whatever
casing they feel like as opposed to what matches on disk? Is it really a
concern about the filename portion, or just a naming issue with the mount
points between Windows and Linux? And also, what is the logic of your regex
that you hope to express?

It would be difficult to know exactly what to transform the string into,
without also doing a glob of the filesytem. If people are allowed to use
any caseing they want, then you don't really have a choice but to stat the
directory and case-insensitive match the files with your string.

Justin


>
> --
> 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/11dfb149-d63d-4f1b-88d0-c02de401e86e%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/CAPGFgA3i07oDqNcTs8%3DUQ0FFHcBZbpRBe0sqSDtodNDpdzh_KQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] rename in PyMel

2016-10-28 Thread Justin Israel
On Sat, Oct 29, 2016 at 1:46 PM  wrote:

> Hi
>
> I have a question. I want to create in pymel a 'while True' loop
> how can I add variable to my rename object?
>
> example
>
> i = 1
> while True:
>pm.rename('group' i '|old_name, 'new_name')
>
>
>
> so for example i = 1 so my 'group' should be 'group1'. I am not sure how
> can I make it. How to add variable input into the name of the object?
>

You can use string formatting, to create a string with variable values:

pm.rename('group{0}'.format(i), '|old_name, 'new_name')

Out of curiousity, what breaks you out of your 'while True' loop? Or was
this only a partial example of what you intend to do?



> --
> 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/debb1b4e-9e16-46d5-8f8b-f5c6a5003b38%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/CAPGFgA3n5-LeYiPCExWMSd5q9_geHNsn_oTtErwDzk0dS8BEZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Using strings as a check in __init__?

2016-10-28 Thread Justin Israel
On Sat, Oct 29, 2016 at 1:41 PM Cesar Saez  wrote:

> There's a fundamental problem with this in my view, the dounder init
> method of a class gets executed _after_ the instance (aka self) get
> created, doing checks there means you basically create an object that can
> potentially be invalid by passing the wrong thing and that's a problem.
>
> You could use a classmethod instead or even a dounder new, but I would go
> the other way around by using a simple function instead! Classes are a very
> powerful tool but it's a bit overkill on this case (imho anyway).
>

What's the "dounder init method"?  Did I miss some code somewhere?

> Cheers!
>
> --
> 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/CAPamJi9JY90vPHxJxaNJpU2C3D6zPix1TUv%2BcfXmMTN1gTW-5g%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/CAPGFgA2OEPUi6hr2M%2BZwug672GKyjiC9hJUHoi75G3yHwSUqhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Using strings as a check in __init__?

2016-10-28 Thread Alok Gandhi
>
> What's the "dounder init method"?  Did I miss some code somewhere?

I think Cesar is referring to the 'double-underscore' aka 'dunder ' aka
'magic methods' aka 'special methods'-  def __init__()

On Sat, Oct 29, 2016 at 9:30 AM, Justin Israel 
wrote:

>
>
> On Sat, Oct 29, 2016 at 1:41 PM Cesar Saez  wrote:
>
>> There's a fundamental problem with this in my view, the dounder init
>> method of a class gets executed _after_ the instance (aka self) get
>> created, doing checks there means you basically create an object that can
>> potentially be invalid by passing the wrong thing and that's a problem.
>>
>> You could use a classmethod instead or even a dounder new, but I would go
>> the other way around by using a simple function instead! Classes are a very
>> powerful tool but it's a bit overkill on this case (imho anyway).
>>
>
> What's the "dounder init method"?  Did I miss some code somewhere?
>
>> Cheers!
>>
>> --
>> 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/CAPamJi9JY90vPHxJxaNJpU2C3D6zP
>> ix1TUv%2BcfXmMTN1gTW-5g%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/CAPGFgA2OEPUi6hr2M%2BZwug672GKyjiC9hJUHoi75G3yHwS
> Uqhw%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/CAPaTLMTWREaRPUXwBn%3DnY_0dqe5AaMEy_PJOO5PFstdWRCtFTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Using strings as a check in __init__?

2016-10-28 Thread Justin Israel
On Sat, Oct 29, 2016 at 2:51 PM Alok Gandhi 
wrote:

> What's the "dounder init method"?  Did I miss some code somewhere?
>
> I think Cesar is referring to the 'double-underscore' aka 'dunder ' aka
> 'magic methods' aka 'special methods'-  def __init__()
>

Oh right. It's like those illusion pictures, where they don't click until
you stare at it the right way. Now I get it :-)


>
> On Sat, Oct 29, 2016 at 9:30 AM, Justin Israel 
> wrote:
>
>
>
> On Sat, Oct 29, 2016 at 1:41 PM Cesar Saez  wrote:
>
> There's a fundamental problem with this in my view, the dounder init
> method of a class gets executed _after_ the instance (aka self) get
> created, doing checks there means you basically create an object that can
> potentially be invalid by passing the wrong thing and that's a problem.
>
> You could use a classmethod instead or even a dounder new, but I would go
> the other way around by using a simple function instead! Classes are a very
> powerful tool but it's a bit overkill on this case (imho anyway).
>
>
> What's the "dounder init method"?  Did I miss some code somewhere?
>
> Cheers!
>
> --
> 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/CAPamJi9JY90vPHxJxaNJpU2C3D6zPix1TUv%2BcfXmMTN1gTW-5g%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/CAPGFgA2OEPUi6hr2M%2BZwug672GKyjiC9hJUHoi75G3yHwSUqhw%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/CAPaTLMTWREaRPUXwBn%3DnY_0dqe5AaMEy_PJOO5PFstdWRCtFTw%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/CAPGFgA31Bg4nfjvsRTmvrdLmnwJGRrfGfQfo0vtuz%3DJAjU3ZOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Using strings as a check in __init__?

2016-10-28 Thread Alok Gandhi
>
> There's a fundamental problem with this in my view, the dounder init
> method of a class gets executed _after_ the instance (aka self) get
> created, doing checks there means you basically create an object that can
> potentially be invalid by passing the wrong thing and that's a problem.

I don't see this as a problem. The __init__() method is for initialization
of the instance. If something goes wrong during the initialization, you can
always raise from within __init__(). I mean, whatever sanity checks you
want to put in for 'filling in' the variables should happen in __init__()
because that is the primary role of this method. If anything bad happens
and the object becomes 'invalid' python will call __del__() to clean it
after itself. So it is perfectly safe to raise from __init__().

Here's a snippet exhibiting the call to __del__() by python's memory
management when __init__() fail:

class A(object):
def __init__(self):
raise ValueError('Something bad happened!')

def __del__(self):
print "Delete Called"

def main():
try:
a = A()
except ValueError, e:
print e
if __name__ == '__main__':
main()


Would result in:
>>>Something bad happened!
>>>Delete Called

-- 
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/CAPaTLMS434aqjf8AMrLVZTvE%3DCJxXXN7-ChHN%3DMd%2B8wG-6v1%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Help with a closure in Maya and Python.

2016-10-28 Thread Alok Gandhi
>
> Please provide a small reproduction of the problem via pastebin or gist.
> After Roberts suggestion to correct a naming issue, I can't see anything
> else wrong in your small snippets of code.

I agree, a repro would help. Also, I do not see a call to pushButton() in
your create_window(), it is just defined there. Maybe you are calling it
somewhere but we do not see that in your example code. Of course, you would
have to call it within the scope of create_window().

Another very minorish comment would be your use mixed 'snake case'
(create_window()) and 'lower camel case' (pushButton()) in function
signatures. It is recommend to use a uniform naming convention. So either
use create_window() with push_button() or use createWindow() with
pushButton()

Also, a few points about your use of the term closure -
What you have is simply a nested function. On the other hand, a CLOSURE is
a function object that remembers values in enclosing scopes regardless of
whether those scopes are still present in memory. You can find more about
them here


On Sat, Oct 29, 2016 at 3:21 AM, Justin Israel 
wrote:

>
>
> On Sat, 29 Oct 2016, 7:18 AM Padraig O Cuinn <
> patchquinnanimat...@gmail.com> wrote:
>
>> I don’t get any errors it just doesn’t pass but it does freeze up on me.
>>
> Please provide a small reproduction of the problem via pastebin or gist.
> After Roberts suggestion to correct a naming issue, I can't see anything
> else wrong in your small snippets of code.
>
>>
>>
>> Padraig O Cuinn
>>
>> Technical Director / Artist
>>
>> --
>> 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/005c01d23147%24b83f7050%
>> 2428be50f0%24%40Gmail.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/CAPGFgA1h_A1r4qeos06OQpC9Gjr5yPF-
> CaSexvHEAe5Rcquyzg%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/CAPaTLMSXeOESo4q1aYW0v1DrEGW5sraLJri1qi4aL4HskxTAfw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Using strings as a check in __init__?

2016-10-28 Thread Cesar Saez
Sure you can (although it forces the user to enclose any instantiation on a
try except, but it works). I guess my point is that validation is usually
done in the constructor and not initialisation, creating an instance just
to destroy it later on without doing any work (contributing to solve the
problem the programmer is trying to solve) is a bit wasteful and I would
not recommend it as good practice to someone trying to learn.

On 29 Oct 2016 1:21 PM, "Alok Gandhi"  wrote:

> There's a fundamental problem with this in my view, the dounder init
>> method of a class gets executed _after_ the instance (aka self) get
>> created, doing checks there means you basically create an object that can
>> potentially be invalid by passing the wrong thing and that's a problem.
>
> I don't see this as a problem. The __init__() method is for initialization
> of the instance. If something goes wrong during the initialization, you can
> always raise from within __init__(). I mean, whatever sanity checks you
> want to put in for 'filling in' the variables should happen in __init__()
> because that is the primary role of this method. If anything bad happens
> and the object becomes 'invalid' python will call __del__() to clean it
> after itself. So it is perfectly safe to raise from __init__().
>
> Here's a snippet exhibiting the call to __del__() by python's memory
> management when __init__() fail:
>
> class A(object):
> def __init__(self):
> raise ValueError('Something bad happened!')
>
> def __del__(self):
> print "Delete Called"
>
> def main():
> try:
> a = A()
> except ValueError, e:
> print e
> if __name__ == '__main__':
> main()
>
>
> Would result in:
> >>>Something bad happened!
> >>>Delete Called
>
>
>
> --
> 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/CAPaTLMS434aqjf8AMrLVZTvE%
> 3DCJxXXN7-ChHN%3DMd%2B8wG-6v1%2Bg%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/CAPamJi-KnYYb3f1OOWEcMJMmjHeKmy1jzUSvp0hHmZuc%3DsmT9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.