First Steps =========== This example covers your first steps with the Guerilla python sdk. Selection --------- To start, let's select something in our scene .. code-block:: python from guerilla import Modifier, pynode with Modifier() as mod: # select RenderGraph node # replace current selection mod.select(['RenderGraph'], mode='replace') Access Nodes ------------ Access nodes of the scene with their path .. code-block:: python from guerilla import pynode # Look up the Output inside the RenderGraph n = pynode ('RenderGraph|Output') # You can also use the _ function, which is equivalent from guerilla import _ n = _('RenderGraph|Output') # Both the pynode and _ functions are equivalent to: from guerilla import Document n = Document ().findchild ('RenderGraph|Output') You can also access an immediate child of a node .. code-block:: python from guerilla import _ # Look up the Output inside the RenderGraph rg = _('RenderGraph') output = rg.getchild ('Output') Scene Parsing ------------- Now Let's see what is inside this node .. code-block:: python from guerilla import pynode n = pynode('RenderGraph') for c in n.children(): print c.name, type(c) If we want to list lights .. code-block:: python from guerilla import Document # Note: # type='Light' to filter lights only # recursive=True option to iterate deep in hierarchy for c in Document().children(type='Light',recursive=True): print c.name, type(c) List all the shading overrides of the RenderGraph node .. code-block:: python import guerilla for c in guerilla.pynode("RenderGraph").children (): for plug in c.plugs(type="AttributePlug") : print plug.getname () Dealing with attributes ----------------------- Let's add a square light in our scene. First we need to create a light then we change its Plug (named LightType) to 'square' .. code-block:: python from guerilla import Modifier with Modifier() as mod: ln = mod.doc.loadfile('$(LIBRARY)/lights/pointlight.glight')[0] ln.LightType.set('square') Now we will store the artist name in a new attribute .. code-block:: python from guerilla import Modifier, Plug, pynode with Modifier() as mod: ln = pynode('light1') # or create it... # create a Dynamic (saved in the scene) user plug (show up in the UI) mod.createplug(ln, 'CreatedBy', 'user', 'string', Plug.Dynamic, 'Jimi Hendrix') And now for experts (yeah!): * Add a node with a custom color attributes which will drive our light color .. code-block:: python from guerilla import Modifier, Document, Plug, pynode with Modifier() as mod: lr = mod.createnode('lightRig') c = mod.createplug(lr, 'Color', 'user', 'color', Plug.Dynamic, [0, 1, 0]) ln = pynode('light1') # or create it... # so now changing light rig color will change the light color ln.Color.connect(lr.Color) # let's print our light color (to check connection) print ln.Color.get() * List all attributes of a node .. code-block:: python from guerilla import Document # iterate over all cameras of the scene for camera in Document ().children (type='Camera'): print ("*** "+camera.getpath ()) # iterate over all plugs for plug in camera.plugs (): print (" "+plug.getname ()) plugtype = plug.gettype () if plugtype != None: print (" type " + plugtype.getname ()) plugvalue = plug.get () print (" value " + str (plugvalue)) * List all textures .. code-block:: python from guerilla import Document # iterate over all nodes of the scene for node in Document ().children (recursive=True): # iterate over all plugs which type is 'texture' for plug in node.plugs (): plugtype = plug.gettype () if plugtype != None and plugtype.getname () == 'texture': print (plug.get ()) or alternatively: .. code-block:: python from guerilla import Document # iterate over all nodes of the scene for node in Document ().children (recursive=True): # iterate over all plugs which type is 'texture' for plug in node.plugs (typename='texture'): print (plug.get ()) Going further ------------- * Try the next example in :doc:`index` * Explore the API documentation * :class:`~guerilla.Modifier` * :class:`~guerilla.Document` * :class:`~guerilla.Node` * :class:`~guerilla.Plug` * :meth:`~guerilla.pynode`