lObj Basic Attribute / Plug ExampleΒΆ

Demonstration the usage of attributes and plugs in a lObj derived class.

import litho.core as lc
class DerivedFromLObj (lc.lObj):
	def __init__(self):
		super().__init__(self) # it is important to call the constructor of lObj here
	
	# this function is called during the creation of internal type information.
	# here all (static) attributes should be created
	def createAttributes():
		attrList = list()
		attrList.append(lc.attribute.valueAttr("int", "start", "Start Value", 1))
		attrList.append(lc.attribute.valueAttr("string", "someString", "Some String", "Hello World"))
		attrList.append(lc.attribute.valueAttr("bool", "isOn", "Is enabled", True))
		return attrList


# in order to benefit from attributes in instances of this type, the new type must be registered:
lc.registerObjectType(DerivedFromLObj)

myInst = DerivedFromLObj()
print(myInst.start) # prints 1
myInst.start = 5
print(myInst.start) # prints 5

# create a second instance
myInst2 = DerivedFromLObj()
print(myInst2.start) # prints 1

# plug output of myInst.start to the ouput of myInst2.start
myInst2.plug('start').plugToInput(myInst.plug('start'), True) 
print(myInst2.start) # prints 5

myInst.start = -10 # also affects myInst2.start 
print(myInst2.start) # prints -10

# add a list of points as a dynamic attribute
myInst2.addPlug(lc.attribute.valueAttr("vec2[]", "pointList", "A Pointlist", ((2, -1), (4, 9))))
print(myInst2.pointList[0]) # prints 2, -1

# get rid of type again
lc.removeType(DerivedFromLObj)