Eyeon:Script/Tutorials/Command Line/Command Line Scripting Intro

From VFXPedia

Jump to: navigation, search

Lesson 4.1 : Command Line Scripting

Part 1 - MakeAVI

We will begin with an extremely simple example - opening a comp, settings its controls and rendering. Make sure that all running copies of Fusion or the Fusion Render Slave are closed before proceeding.

Start by opening a command prompt window - (start/programs/accessories/command prompt). Navigate to the directory where you installed EyeonScript.exe - usually the directory where Fusion.exe is located.

Type 'eyeonScript.exe -i' and hit enter.

C:\Fusion\eyeonScript.exe -i
Fusion Script Interpreter
Copyright (C) 2002 eyeon Software

The name of the scripting interpreter and the copyright information will appear, followed by the cursor. This places eyeonScript in interactive mode, which allows us to execute commands without having to use a premade script.

Now type the following line and press enter.

fusion = Fusion("localhost")

In English this line says "Find a copy of Fusion running on the local machine, and establish a connection." We then assign that connection to the global variable 'fusion' so that we can refer to it later.

When you hit enter the screen will pause for a second, and then a new line will appear. Note that there is no message of success or failure. We know that the command must have failed because Fusion is not currently running, but in script, the only way to know that our attempt to connect has failed is to test the value of the variable 'fusion'.

Type the following and hit enter:

print(fusion)

The response should be 'nil' indicating that the variable fusion has no value to print.

Now start Fusion on your system, and lets try to connect again. You could retype the Fusion() function, or you could press the up cursor key to scroll through a history of past commands. When you hit enter the system should respond almost immediately, without the delay you experienced the first time you ran the Fusion() function. Type print(fusion) again and hit enter. You should see something like this...

fusion = Fusion("localhost")
print(fusion)
Fusion (0x021c0560) [App: 'Fusion' on 127.0.0.1, UUID: 2c73cbf2-03f4-4816-babd-68b9357b51b2]

This tells us that Fusion() found a running copy of Fusion on the local machine and successfully established a control connection. We can now use scripting to control that instance of Fusion. First, create a comp with a loader, a resize tool, and a saver all with their default names. Save it as lessons.comp.

Close all open comps in Fusion, so that you are looking at a blank grey screen. Now type:

comp = fusion:LoadComp("c:\\lessons.comp")

Replace the path "c:\\lessons.comp" with the correct path to the comp you just downloaded, using \\ instead of \ in the path.

When you hit enter, Fusion should load the comp script_example.comp and a connection to that comp will be assigned to the variable 'comp'. The variable doesn't have to be 'comp' - that's just easier to remember than something weird, like 'hndl_comp_1'.

Notice that we used double slashes in the path rather than the more common single slashes. Because of the way EyeonScript formats strings of text, we must use double slashes (\\) whenever we want just one (\) (see previous lessons).

In order to easily control the composition we just loaded we need to tell eyeonScript that this will be our current, active composition. This is necessary because eyeonScript can access and manipulate multiple comps at once. Type the line

SetActiveComp(comp)

Now we are ready to start issuing commands that affect the comp. Lets start by setting the loader to the correct footage. The footage we will use for this tutorial is located here.

Loader1.Clip = "c:\\images.0000.jpg"

Again replace the path here with the path to your own footage.

Now notice the way that we refer to the tool in the script. The name of the tool in the comp is Loader 1, so we can access the tool by its name, minus any spaces, or irregular characters (like "-" or "_"). Our goal was to set a clip for the Loader, so we set the filename input (or control) of the loader tool. The format used is Tool.Input, or in this case Loader1.Filename.

It is easy to determine the name of a tool and it's inputs. Place your mouse pointer over the tools control header and then look in the status bar at the bottom left. The name of the tool will be displayed below. Now place your mouse pointer over one of that tools controls, and the exact terminology that should be used to refer to that control in script will also be shown in the status bar.

Now that we have set the clip for Loader 1, we need to set the width and height used by the resize:

Resize1.Width = 160
Resize1.Height = 120

Now we set the filename to be used by the saver:

Saver1.Clip = "c:\\script_example.avi"

Before we can render our comp, we might also want to save it.

comp:Save("c:\\example_avi.comp")

And finally to render our comp:

comp:Render(true, 0, 59, 1)

When you hit enter, the composition will begin to render. The three arguments for the Render() function are wait_for_render, renderstart, renderend, and step. Note that if the variable is set to false, eyeonScript does not wait for the render to complete, but immediately returns, looking for its next command.

Once the render is complete type the following to close the comp.

comp:Close()

So far we have created a ten line script that loads a template comp, adds a clip, resizes it, and renders the result to an AVI file. When collected together the lines of the script look like the following.

comp = Comp("localhost")
comp = fusion:LoadComp("c:\\lessons.comp")
SetActiveComp(comp)
Loader1.Clip = "c:\\image.0000.jpg"

Resize1.Width = 160
Resize1.Height = 120

Saver1.Clip = "c:\\script_example.avi"

comp:Save("c:\\example_avi.comp")
comp:Render(true, 0, 59, 1)

comp:Close()

Copy and paste these lines into a text document and save it as MakeAVI.eyeonScript - replace the paths with ones that will work for you. We will use this script again in the next lesson.


Tips for Command Line Scripting Intro (edit)

EyeonTips:Script/Tutorials/Command Line/Command Line Scripting Intro