the self thing

how does it works what does it represent ?

class Material:

def makeNode(self, type, name):
self.node = self.nodes.new(type)
self.node.name = name
self.xpos += 200
self.node.location = self.xpos, self.ypos
return self.node

first you have to instantiate the class material
then you call the function inside like

diffuseBSDF = m1.makeNode(‘ShaderNodeBsdfDiffuse’, ‘diff1’)

what does the self represent is it a name cause if i print it i get

self= <main.Material object at 0x1227C170>
but looks more like an addres!

i tought self for a class was the class 's name!

thanks

There is a difference between ‘classes’ and ‘instances’.

Dog is a class. Fido is a dog, an instance of Dog.

The name of the class is Dog.
The name of Fido is Fido.

“self” refers to Fido, not to Dog.

i see the 2 names
self.node = self.nodes.new(type)
self.node.name = name

i can see that node in self.node would be an API name !

so these methods are use for making new material

so if i want to make this for world i need basicaly to create a new class for the world things

thanks