Create Layers with python
_
=

Create Layers with python

How to create layers with python?

2D layers

In order to create layers, you need the name of its generator class; check the layers Class names Listing of layers class names Read More list for information.
  1. Instantiate your layer
  2. Define the type
  3. Change it's parameters
  4. Place it in the Element tree

Example with a simple 2d compo layer
comp = Oil.createObject("Compo") #Create the compo generator
myLayer = Oil.createObject("TextureLayer") #create the Layer for the compo
myLayer.generator = comp #assign the Compo to the Layer
myLayer.label = "myCompo" #change the label of the compo (can be done for every parameter of the layer or compo)
script.rootElement.layers.append(myLayer) #add the layer to the tree

3D Layers

Here is an example of a simple 3d layer with a box and an additional modifier:
box = Oil.createObject("BoxGeometryGenerator")
modifier = Oil.createObject("ColorizeGeometryModifier")
modifier.color = Oil.HsvColor(red = 1.0, alpha= 1.0)

renderer = Oil.createObject("SurfaceGeometryRenderer")
myLayer = Oil.createObject("GeometryLayer")
box.modifiers.append(modifier)
myLayer.generator = box
myLayer.renderer = renderer
script.parentElement.layers.append(myLayer)

Shapes

Here is an example of a shape layer drawing a simple circle:
circle = Oil.createObject("CircleShapeGenerator")
renderer = Oil.createObject("DefaultShapeRenderer")
layer = Oil.createObject("ShapeLayer")
layer.generator = circle
layer.renderer = renderer
script.parentElement.layers.append(layer)

See Also: