Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

8 Dec 2015

Git tutorial

I have just found a brilliant tutorial for git. If you had any problem how git works definitely you have to watch this page.

Atlassian Git Tutorial


31 Mar 2015

PyCharm is awesome

So rigging guys, I started to use pycharm at Digic one year ago. Thanks Boris to mention me! This program easily awesome! I can not get enough of it! I can just really suggest for every rigging and developer guys. The best IDE for python programming that I've ever seen.

Official web

8 Nov 2012

Python 'super()' function bug

I have a diamond inheritance and used super() function to avoid issues.

# TypeError: super(type, obj): obj must be an instance or subtype of type #
I got this error message. I've seeked for solutions for this problem.
First you could try to reorder the importing. Sometimes it helps but not in every case. There is still the issue probably you have too many reload in baseclasses. Remove them.

I hope it is handy for you.

18 Oct 2012

Some definitions

Objects

Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects. (In a sense, and in conformance to Von Neumann’s model of a “stored program computer,” code is also represented by objects.) Every object has an identity, a type and a value.


Types

An object’s type determines the operations that the object supports (e.g., “does it have a length?”) and also defines the possible values for objects of that type.
to be continued..


Variable

In computer programming, a variable is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information, a value. The variable name is the usual way to reference the stored value; this separation of name and content allows the name to be used independently of the exact information it represents. The identifier in computer source code can be bound to a value during run time, and the value of the variable may thus change during the course of program execution. Variables in programming may not directly correspond to the concept of variables in mathematics. The value of a computing variable is not necessarily part of an equation or formula as in mathematics. In computing, a variable may be employed in a repetitive process: assigned a value in one place, then used elsewhere, then reassigned a new value and used again in the same way (see iteration). Variables in computer programming are frequently given long names to make them relatively descriptive of their use, whereas variables in mathematics often have terse, one- or two-character names for brevity in transcription and manipulation.

15 Oct 2012

Nested Attributes

If you want to create nested attributes you need to take care of unique attribute names, because you can call it from the root. When you want to create an attribute with the existed name you will get an error. I had this problem when I created a really deep coumpound attribute.

In the example the sphere is a pymel object.

WRONG attribute concept name:
sphere.position.X

CORRECT attribute concept name:
sphere.position.positionX

Calling:
sphere.positionX

# =======================================================
import pymel.core as pc
plane = pc.polyPlane()[0]
plane.addAttr('sphere0', at='float3')
plane.addAttr('sphere0pos', at='float', p='sphere0')
plane.addAttr('sphere0rot', at='float', p='sphere0')
plane.addAttr('sphere0scl', at='float', p='sphere0')
# =======================================================

23 Jun 2012

Python tipps and tricks

Class Attribute vs. Instance Attribute

I will show what is the difference between class and instance attribute. If you have some instances the class attribute will be affected by all of them, but the instance attribute just by the own instance.
1
2
3
4
5
6
7
8
9
10
11
12
class Name ():
   count = 0
   def __init__ (self, name):
      self .name = name
      Name.count += 1

man1 = Name('David')
man2 = Name('Jozsi')
print Name.count
# Result: 2 #
print man2.name
# Result: 'Jozsi' #


Lambda function bug

Sometimes the lambda function does not want to work. You do everything on right way but you've got error.

1
2
3
4
# If it's not working:
lamda x: call_function()
# Try this:
lamda : call_function()


For statement an other way

Today I learnt a new way to use 'for' statement. It is really useful if we want to give a simple function to every item:

1
2
3
4
5
# We have a list
lst = ['a_1', 'b_2', 'c_3']
numbers = [str.split('_') for str in lst]
# equivalent with this:
numbers = map ( lambda str: str.split('_')[1], lst)


Map function

There is the "map" function in pyton that is very handy. I show how it works.

1
2
3
4
5
6
7
8
9
10
# Example 1.
# We define a function first.
def myFunction (input): return input+1
result = map (myFunction, [1,2,3,4])
print result[1]
# Result: 3 #

# Example 2.
map ( lambda x : x+1, [1,2,3])
# Result: [-1, 1, 3] #
"map(f, sequence)" is directly equivalent with: "[f(x) for x in sequence]"


Class inheritance

I wrote a little template for class inheritance with super function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class A (object):
   def __init__ ( self , name= 'alma' , *args, **kwds):
     super (A, self ).__init__( *args, **kwds )
     self .name = name
   def getName ( self ):
     print self .name

class B (A):
   def __init__ ( self , number=12 , *args, **kwds):
     super (B, self ).__init__( *args, **kwds )
     self .number = number
   def getNumber ( self ):
     print self .number

b_object = B()
b_object.getName()
# Result: 'alma' #


SetAttr command

I wrote a script some days ago and I had a problem with cmds.setAttr's keyable flag. If you want to lock and hide a double3-type-attribute you need to set separately each attribute.

# Wrong:
cmds.setAttr('pCube1.t', k=False)
# Correct:
for axis in ['x', 'y', 'z']:
  cmds.setAttr('pCube1.t'+axis, k=False)


1 May 2012

Eclipse plugin: Umlet

It's a great plugin for ecplise to show a flow about your program. No more comments, just check the link and videos. Enjoy!
http://www.umlet.com/

31 Jan 2012

Aptana Studio/Eclipse set up

I write a little description how you can create a good workspace for programming. I am using Aptana for purpose because it contains a lot of useful features.

Step 1.
Install Aptana:http://www.aptana.com/products/studio3/download
or eclipse: http://download.eclipse.org/eclipse/downloads

Step 2.
Install pydev. Go to Help → Install Software
You should add this url: http://pydev.org/updates

Step 3.
Adding interpreter to the application.
For Maya 2011 add C:/Program Files/Autodesk/Maya2011/bin/mayapy.exe
Check all checkboxes, but remove site-packages path afterwards add
(Path To Your Pymel/pymel-1.0.2)/extras/completion/py/
and finally add back the site-packages path.Check on the picture the order.


Step 4.
Window→ Open Perspective→ Other…→ Pydevmake sure that the PyDev Package Explorer is open: Window→ Show View→ Pydev Package Explorer
In the Pydev Package Explorer, Right click and select New→ project→ Pydev(folder)→ Pydev Project


Step 5.
Right click on the project in explorer, Import→General→File system


Step 6.
Follow the setup based on picture. You can add filters, if you want.

Step 7.
Adding new file to the project:
New→Pydev module