hello,
so I spend a couple of months making my show reel which is a rig builder tool. Here you have the link if you want to check it
riggin/programing reel
I learned a lot doing it, and I want to thank this forum for helping me with my questions (even the stupids ones....)
Any way, now I want to rewrite my code avoiding making some mistakes I did previously, so I wanted to ask you If I am using the instance variables right.( code in pastebin link )
http://pastebin.com/yxMNRXHT
I thought that arguments like side, or name are very used in all the methods, so is it okey to out them in the __init__? this way, I don´t have to keep using those arguments over
and over again in the rest of the methods.
But of course that obligates me to create the class instance.
I now about classmethods to call directly the class. But then, should all my methods be classmethods?
I don´t know, a programer told me that scripting for 3d I don´t have to care too much about all that,
but I don´t want my code just to work, I want to make a proper code too when
I am applying it to rigging.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7bea2fb9-4b04-4a60-a42c-e95b0c776422%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If you have a class with only 2 methods, and one of them is __init__(), then you actually want a function: Stop Writing Classes
If you have a class with only 2 methods, and one of them is __init__(), then you actually want a function: Stop Writing ClassesThat was just an example, of course I have a lot of methods. It was just to understand if using in the __init__ the args "side" and "name" is okey., because the rest of the methods use those variables
at some point.
They way I am wrote my last code to do the tool in the reel I linked is:
1. coreTools class that has methods to gets distances, vectors, vertexcountes etc..etc..so generic stuff you use usally
2. then in another module I have a jointTools class, that has methods to do basic rigging stuff, like iks, fk/ik, etc...
3. a more detailed class that inherits from joint jointTools class to make methods like softIk, stretchyIk, bendings etc..etc...
Is this approach correct for OOP?
thanks for the tuple() and _private tips
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/81667cab-892c-4e07-a0e7-e3c989a7fbdc%40googlegroups.com.
On Sun, 5 Jun 2016 10:35 AM Rudi Hammad <rudih...@gmail.com> wrote:If you have a class with only 2 methods, and one of them is __init__(), then you actually want a function: Stop Writing ClassesThat was just an example, of course I have a lot of methods. It was just to understand if using in the __init__ the args "side" and "name" is okey., because the rest of the methods use those variables
at some point.Oh ok. Then sure, those seem fine. If they are the required variables that drive the functionality of the other methods then it makes sense to be able to construct and instance with them.
They way I am wrote my last code to do the tool in the reel I linked is:
1. coreTools class that has methods to gets distances, vectors, vertexcountes etc..etc..so generic stuff you use usally
2. then in another module I have a jointTools class, that has methods to do basic rigging stuff, like iks, fk/ik, etc...
3. a more detailed class that inherits from joint jointTools class to make methods like softIk, stretchyIk, bendings etc..etc...
Is this approach correct for OOP?If coreTools class needs state for each instance, then sure. If it's just a bunch of utility methods that don't access "self" other than than to call another method, then maybe not. And coreTools would be expected to be CoreTools if it's a class ;-)
--
thanks for the tuple() and _private tips
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+unsub...@googlegroups.com.
ok. I think I get it. I wrote this example to see if I am on the right path
http://pastebin.com/AqVCPpet
you right about the CoreTools with capital "C", I try to follow the python styling. There are somethings I don´t agree with. For instances, I tend to put more blank lines
than recomended by python gurus. For example I read better
def foo():
El domingo, 5 de junio de 2016, 1:15:50 (UTC+2), Rudi Hammad escribió:ok. I think I get it. I wrote this example to see if I am on the right path
http://pastebin.com/AqVCPpet
you right about the CoreTools with capital "C", I try to follow the python styling. There are somethings I don´t agree with. For instances, I tend to put more blank lines
than recomended by python gurus. For example I read betterdef foo():
bla bla bla bla
bla blabla bla
than
def foo():
bla bla bla blabla
bla blablablabla
or myTuple( "a", "b", "c" ) than ("a", "b", "c")
I know those are minor details, but I don´t know if that might annoy other python coders
bla blab la blabla
El domingo, 5 de junio de 2016, 0:40:31 (UTC+2), Justin Israel escribió:
On Sun, 5 Jun 2016 10:35 AM Rudi Hammad <rudih...@gmail.com> wrote:If you have a class with only 2 methods, and one of them is __init__(), then you actually want a function: Stop Writing ClassesThat was just an example, of course I have a lot of methods. It was just to understand if using in the __init__ the args "side" and "name" is okey., because the rest of the methods use those variables
at some point.Oh ok. Then sure, those seem fine. If they are the required variables that drive the functionality of the other methods then it makes sense to be able to construct and instance with them.
They way I am wrote my last code to do the tool in the reel I linked is:
1. coreTools class that has methods to gets distances, vectors, vertexcountes etc..etc..so generic stuff you use usally
2. then in another module I have a jointTools class, that has methods to do basic rigging stuff, like iks, fk/ik, etc...
3. a more detailed class that inherits from joint jointTools class to make methods like softIk, stretchyIk, bendings etc..etc...
Is this approach correct for OOP?If coreTools class needs state for each instance, then sure. If it's just a bunch of utility methods that don't access "self" other than than to call another method, then maybe not. And coreTools would be expected to be CoreTools if it's a class ;-)
--
thanks for the tuple() and _private tips
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/81667cab-892c-4e07-a0e7-e3c989a7fbdc%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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/046b0a5e-0300-408c-a23d-ebf8535f05e1%40googlegroups.com.
See from from that example, to me, classes don't make sense. You didn't show any usage of state. They just look like namespace of functions
no? hmmm....I inherited the method getDistance() to use it in the makesterchy()
How many instances of your classes will you have around? If it's only 1 or it's not holding any state get rid of it and use functions (you can aggregate them in a module if you like).
Also your class method makes no sense, class methods are supposed to return an instance (typically constructors). If you want to define methods not using requiring the instance you probably need to decorate it as a static method.
tl;dr: object oriented programming include the world object, not class, in the name/description. Make sure you understand the difference between those and everything will make sense.
Cheers
How many instances of your classes will you have around? If it's only 1 or it's not holding any state get rid of it and use functions (you can aggregate them in a module if you like).
tl;dr: object oriented programming include the world object, not class, in the name/description. Make sure you understand the difference between those and everything will make sense.
Anyway, thanks for the tips guys
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/64ce1dd3-99ee-410a-a960-4ea230aa7586%40googlegroups.com.
Wow I had tons of typos in that last reply, from my phone.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
okey, now I understand. As you said, I do classes according to themes. So it is more a way of organizing methods in themes than exploring the power of OOP. So when I inherit the method distance() from a superclass to use it
in another subclass I am not doing anything really. It just like having 2 modules with funcions, and importing functions from one modulo to another. I can do that without OOP. But is it that bad to use class just to organize your "themes"?
I think I understand what you mean now with idea of state. You are creating an initial variable that is used or modified in the rest of the methods. So can I use for example as instance variable self._side="", or self._name="" to avoid having to right
every time in every method side and name as arguments?
Can you also use the __init__() to create objects . I don´t know why I have this idea that creating an object inside a module or an init to use its methods is messy. Is this why @classmethods are used? to avoid creating having to create the object?
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/64ce1dd3-99ee-410a-a960-4ea230aa7586%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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1131a9c0-a0a2-42e7-aa19-0356c9f1fd15%40googlegroups.com.
I dont realy undertand this. Can you give an example? I feel like you mean that earlier point about using a class as a namespace for your functions, and having to construct an instance in order to call methods. As Cesar had also pointed out, classmethods can be used as factory functions or alternate constructors to return instances of the class. They can also be used to perform operations that don't require an instance but may want to reference class attributes.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAkM4%3DrH%2By14JmsiZXDFTBZNxT30wmc5VvvQo-DhZ6EPg%40mail.gmail.com.
> Nope, a class method take the class as first argument and is supposed to return an instance of said classJust so we don't confuse Rudi, a @classmethod is like a regular method, except that it doesn't have access to its instance.
ps: I just bought on cgcircuit intro to pymel to see If I get a better understanding of OOP
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/42005abc-18d3-4f20-b375-7bf678327d7a%40googlegroups.com.
I totally agree with Justin, forget about subclassing for a second and just go with the generic case. Limb can implement many features but you are not forced to use them all! You can call methods selectively on each instance/object setting different states (class define behaviour, instance hold the state).
I.e.
# stupid example typed on my phone
import Limb
# ik/fk arm
arm = Limb(name='arm', side='L')
arm.addFK()
arm.addIK() # assuming you can stack features
arm.makeStretchy()
arm.build()
# ik only leg
leg = Limb(name='leg', side='R')
leg.addIK()
leg.build()
# and so on...
No it's not really better.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/583bb317-d152-40e6-b024-bc93ad01e5ce%40googlegroups.com.
On Tue, Jun 7, 2016 at 11:54 AM Rudi Hammad <rudih...@gmail.com> wrote:No it's not really better.
wow I am completly useless!!! XXXXD. Okey okey, I will get there and finally get a good oop example. I see my mistakes thanks to all of you.
Next time I´ll get it right. And if I don´t , I´ll devote my life to work at McDonalds.I didn't mean any offense (hope none was taken?). Was just being honest. i completely understood your explanation of how you set things up, but didn't agree that it was the best usage of classes and inheritence, as it was intended. You should look up "mixins", as it sounds like what you are using classes for.Don't head to McDonalds yet, unless its for a 6 piece nuggets and a Big Mac.
--
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+unsub...@googlegroups.com.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c57199ee-bdb7-4c2f-9dcb-35de74faaf31%40googlegroups.com.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1e3de1ed-af92-403a-bfc3-11e1c035c547%40googlegroups.com.
Would you expect a Cartoon limb to always create a stretchy IK as part of its standard behaviour?
def makeIk(self):# do normal ik logicsuper(CartoonFeatures, self).makeIk()# do stretchy part hereIn this version, it would mean that no matter what kind of BaseLimbRig you had, you could always call makeIk() on it. Because of it being OOP, the message dispatches to the correct receiver and you get different implementations.
Would you expect a Cartoon limb to always create a stretchy IK as part of its standard behaviour?
yes
def makeIk(self):# do normal ik logicsuper(CartoonFeatures, self).makeIk()# do stretchy part hereIn this version, it would mean that no matter what kind of BaseLimbRig you had, you could always call makeIk() on it. Because of it being OOP, the message dispatches to the correct receiver and you get different implementations.
I don´t understand that. It is the first time I see super() in a method that is not __init__() so I don´t quite get
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9227446d-47d5-42ef-94b7-4fd8f1cc7f9b%40googlegroups.com.
Hi Rudi,
Why not pass the stretchy to makeIk as a argument? (i.e. foo.makeIK(stretchy=True) ) same with the method of the twist?
put some effort into testing so you can deliver solutions with some confidence
And all of you are right, you got obsessed with subclassing.
>> Why not pass the stretchy to makeIk as an argument?
>
>... Because maybe I makeIkStretchy has arguments on it own....
>... Same goes with the twist method. what if I discover a new setup of twisting in the future?
That is usually handled by abstracting the computation as a solver and passing a reference to said solver as an argument (it is what Maya does with its ik, there are not multiple subclasses per type of ik). Think about the code using your classes, your future self, when all the implementation details are not so clear in your mind, isn't it painful to have to import and learn how to use different things in order to create a limb with slightly different features? What about maintenance?
And yes, by testing I meant unit/integration/automated testing (hopefully test-first or tdd), sorry if I wasn't clear enough.
Anyway, good luck with the project,
Cheers!
>> Why not pass the stretchy to makeIk as an argument?
>
>... Because maybe I makeIkStretchy has arguments on it own....
>... Same goes with the twist method. what if I discover a new setup of twisting in the future?That is usually handled by abstracting the computation as a solver and passing a reference to said solver as an argument (it is what Maya does with its ik, there are not multiple subclasses per type of ik).
Think about the code using your classes, your future self, when all the implementation details are not so clear in your mind, isn't it painful to have to import and learn how to use different things in order to create a limb with slightly different features? What about maintenance?
And yes, by testing I meant unit/integration/automated testing (hopefully test-first or tdd), sorry if I wasn't clear enough.
Anyway, good luck with the project,
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPamJi_Ge58xuR8652veqq2T16vmJtgmo4UfdQEN77yCwetoYw%40mail.gmail.com.
That is usually handled by abstracting the computation as a solver and passing a reference to said solver as an argument
def makeIk(self):# do normal ik logicsuper(CartoonFeatures, self).makeIk()# do stretchy part hereIn this version, it would mean that no matter what kind of BaseLimbRig you had, you could always call makeIk() on it. Because of it being OOP, the message dispatches to the correct receiver and you get different implementations.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1d6ed251-9d88-4918-9d77-75b5809f99ee%40googlegroups.com.
def makeIk(self):Try it
self.makeIk()
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0b3b06f8-945d-42f3-b999-72ae18fd2edd%40googlegroups.com.
On Thu, 9 Jun 2016 9:48 PM Rudi Hammad <rudih...@gmail.com> wrote:
El jueves, 9 de junio de 2016, 10:41:00 (UTC+2), Marcus Ottosson escribió:def makeIk(self):Try it
self.makeIk()
it gives an error. So that´s why there is super(). it allows to have the same method in a subclass, and use that same method existing in the superclass. right?
isn´t that technically an extension, because you are using the same method from the superclass and add more functionality?
In this case isn´t the same talking about overriding and talking about extension?I haven't heard the term "extension method" used before in the context of Python, so I had to look it uphttps://en.wikipedia.org/wiki/Extension_methodThe definition doesn't seem to apply to how you are using it to describe this python code. Its defined as adding a method to a class after its type spec has already been defined (or compiled). So in python the closest thing would be to monkey patch an existing class by adding a new method to it (not to an instance but to the actual class, so that any instance will gain access).When you redefine an existing method from a super class in the derived class, that would be called "overriding" in Python. You are making an existing method do something different than the super class implementation. Whether you choose to also call the the super class implementation at any point in that new overload is up to you.
--
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+unsub...@googlegroups.com.
can you check this video for on second?
Hear what raymond hettinger says in the min 22 second 05. He says that if the parent is called it is extending, if not, overriding.
He says literally " we extend the parent´s method ", so he says that he is extending a method
raymond hettinger
El jueves, 9 de junio de 2016, 13:04:07 (UTC+2), Justin Israel escribió:
On Thu, 9 Jun 2016 9:48 PM Rudi Hammad <rudih...@gmail.com> wrote:
El jueves, 9 de junio de 2016, 10:41:00 (UTC+2), Marcus Ottosson escribió:def makeIk(self):Try it
self.makeIk()
it gives an error. So that´s why there is super(). it allows to have the same method in a subclass, and use that same method existing in the superclass. right?
isn´t that technically an extension, because you are using the same method from the superclass and add more functionality?
In this case isn´t the same talking about overriding and talking about extension?I haven't heard the term "extension method" used before in the context of Python, so I had to look it uphttps://en.wikipedia.org/wiki/Extension_methodThe definition doesn't seem to apply to how you are using it to describe this python code. Its defined as adding a method to a class after its type spec has already been defined (or compiled). So in python the closest thing would be to monkey patch an existing class by adding a new method to it (not to an instance but to the actual class, so that any instance will gain access).When you redefine an existing method from a super class in the derived class, that would be called "overriding" in Python. You are making an existing method do something different than the super class implementation. Whether you choose to also call the the super class implementation at any point in that new overload is up to you.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0b3b06f8-945d-42f3-b999-72ae18fd2edd%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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/92f6da08-e7a0-4ad2-9fa1-2d47682f7f1d%40googlegroups.com.
Can you find anything else to back up this statement he made?
Can you find anything else to back up this statement he made?
nop. This guy is one python "creators" I think, so he must know what he is talking about.
But anyway, the important thing is understanding what is he is doing i guess
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e9ae0909-c389-40b7-b267-d4135c5749a5%40googlegroups.com.
On Fri, 10 Jun 2016 8:52 AM Rudi Hammad <rudih...@gmail.com> wrote:Can you find anything else to back up this statement he made?
nop. This guy is one python "creators" I think, so he must know what he is talking about.He looks to be a consultant and trainer. Not a "creator". Guido was the creator
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e125005c-bbb5-4107-ac88-b7ae983dfd8f%40googlegroups.com.
hello,
so I spend a couple of months making my show reel which is a rig builder tool. Here you have the link if you want to check it
riggin/programing reel
I learned a lot doing it, and I want to thank this forum for helping me with my questions (even the stupids ones....)
Any way, now I want to rewrite my code avoiding making some mistakes I did previously, so I wanted to ask you If I am using the instance variables right.( code in pastebin link )
http://pastebin.com/yxMNRXHT
I thought that arguments like side, or name are very used in all the methods, so is it okey to out them in the __init__? this way, I don´t have to keep using those arguments over
and over again in the rest of the methods.
But of course that obligates me to create the class instance.
I now about classmethods to call directly the class. But then, should all my methods be classmethods?
I don´t know, a programer told me that scripting for 3d I don´t have to care too much about all that, but I don´t want my code just to work, I want to make a proper code too when
I am applying it to rigging.
cheers