PDA

View Full Version : A few scripting questions


Mauritius
01-19-2003, 01:41 PM
Hi everybody.

My experience with Fusion is peripheral so far; I have though excessive experience with AfterEffects (bah!), Shake and Combustion. Anyway, I downloaded and installed the demo and I like a lot what I see. :)

The reason I have to learn another comp app now is that I have a new customer who are in the pre-production phase for a feature. They use solely Fusion for comp work. They asked me to write a few scripts for them, to automate some of their more boring tasks.
I must say that the DF Script docs a bit thin. In particular, four example scripts are a joke imho (I don't really count in those scripts spread through the reference docs to illustrate single functions). Or is this shortage of example scripts related to the fact that I only have the demo? I btw. downloaded the demo in late december. Maybe there are updates available to the scripting/docs already?

As a TD I'm certainly fluent in a dozen programming- and scripting languages; so Lua itself is not the problem I have.


Here go my questions:

- How can I find the tool connected to an input of a tool? I have everything in place, but I can't find a way to get the connected input tool. There is the 'INPB_Connected' Attribute, but it only tells me that there actually *is* a connection, not *what* is connected. How do I get a handle to the tool that provides the output connected to my tool's input?
To be more precise -- I need a way to recursively scan the flow upstream from its resp. last tool (usually a saver).
[Recursive scanning through a flow is a must have example in the docs imho]

- How can I get transformations (a path) connected to a tool (similiar to question 1).
I need to scan the paths for direction changes and curvature changes. That is, I also need first and second order derivatives of a path. If DF Script can't provide these, I have to evaluate the path at different (non local) times to approximate these myself. It may also mean I have to advance or play back time in steps smaller than one frame.

- Is there a way to call the File->Import command via DF Script to have fusion generate that flow from a multi-layer PSD file?

Thanks in advance,

Moritz

izyk
01-22-2003, 08:49 PM
Hello

[[ This forum has length restrictions, so this is part I ]]

You have a two or three big questions. So I have an even bigger answer. I have seperated your email into three different questions so I can handle them properly,

> Here go my questions:

> - How can I find the tool connected to an input
> of a tool?

The functions you want here are

input:GetConnectedOutput() - returns a output object
output:GetTool() - get the tool an output belongs to

So imagine a flow with three imaginary tools, as follows

loader -- glow -- blur

From the console you could type

inp = blur.Input
out = inp:GetConnectedOutput()
t = out:GetTool()
print t:GetAttrs().TOOLS_Name

and the console would type the name of the source tool - which is the 'glow' tool. You could then repeat for the glow tool.

The problem occurs when you get to a merge tool, which has two inputs, neither of which is called 'Input'. How do you determine which inputs to follow, and which to ignore

[[ Please see part II ]]

izyk
01-22-2003, 08:56 PM
[[
This is part II of a two part message
Hmm. I can't read, the length restriction is 20,000 not 2,000
grr. anyone know how to keep this forum from stripping the spaces out of my message? ]]

If you call the tool:GetInputList() function it will return a long list of inputs, some of which are data type inputs (i.e. the Blur Strength control in a numeric input. We are only interested in Image inputs, so we would want to filter that list by checking tgo see if the INPI_DataType attribute = DT_Image. Naturally, that constant (DT_Image) has not been defined for you (oops), so I will provide the magic number of 1734438217

So the following code would return a list of image inputs for the tool given as it's argument

function getImageInputList(tool)
image_inputs = {}
DT_Image = 1734438217

inp_l = tool:GetInputList()
for i = 1, table.getn(inp_l) do
if inp_l[i]:GetAttrs().INPI_DataType == DT_Image then
table.tinsert(image_inputs, inp_l[i])
end
end
return image_inputs
end

So you could then recurse down each branch given here (assuming the input was connected. Now, what if you just wantg to follow the dominant background branch of the flow? Each input of type DT_Image provides a priority, which indicates if it is the first, second, third and so on input. Naturally, this 'Primary_Input' is also a magic number from the DF Registry. ( 24145609 ). An input which has the INPI_ID attribute set to 24145609 is the primary input.

I have created a tool script to demonstrate.

http://vixen.eyeonline.com/DFReg/downloads/dfscript/recurseExample.dfscript

<also printed below my signature>

After installing this script in the dfusion/scripts/tool directory open a flow with a few tools in it. Right click on any tool and select the script from the scripts menu. If the script works it should work back and list all of the tools connected to the selected tool, following the background channel only.

On my system this script occasionally crashes, so I will have to see if I can discover why...but it definetly proves the concept.

BTW: output:GetConnectedInputs() will return a list of the inputs connected to a tool.

I will answer the other questions in a seperate message later.....

Thanks

Isaac Guenard
Product Manager - eyeon Software

P.S. The content of this posting will be formatted into a more reasonable example and placed on our wenbsite in the next few days.

-----------------------------------------------
-- SCRIPT EXAMPLE
-- shows how to trace connections from
-- input to output
-----------------------------------------------

function recurseFlow(tool)
local ta = tool:GetAttrs()
local inp = nil
local inp_l = tool:GetInputList()
for i = 1, getn(inp_l) do
-- 24145609 is 'magic' it basically means - the primary input for a tool
if inp_l[i]:GetAttrs().INPI_ID == 24145609 then
inp = inp_l[i]
end
end

if inp == nil then
--print("Completed : ".. ta.TOOLS_Name .. " must be a creator tool")
return
end

local out = inp:GetConnectedOutput()

if out == nil then
print("Completed : ".. ta.TOOLS_Name .. "primary input not connected to another tool?")
-- this would happen on an creator, so this would indicate the end of a branch
-- we should test the tool type for creators before reporting an error. This may just be
-- the recursion terminator
return
end

local tool = out:GetTool()
print(tool:GetAttrs().TOOLS_Name)
recurseFlow(tool)
end

print(tool:GetAttrs().TOOLS_Name)
recurseFlow(tool)

Mauritius
01-23-2003, 01:22 AM
Isaac, you rule man! :buttrock:

I had fiddled with GetConnectedOutput() for three days now! I though you'd never answer and I already was prepared to tell my customer tomorrow that I had to freeze my work until I got you response!

Since there is no documentation yet on GetConnectedOutput(), I had tried all sorts of stuff, resulting in all sorts of nice error messages. :D
I also noticed that the df:OpenFile() html page is completely missing, when I searched for info on how to solve my PSD import question, it also misses in the online docs on your site.
I had already suggested to my customer to save out their PSD layers as separate TIF files each from Photoshop, which is not as nice of course and creates a lot of work that could be avoided.
A a plain yes/no hint from your side on whether there is a way to solve this issue touched in my third question or not, via DF Script, would be of great help for now.

Many thanks for your detailed answer to my first question! :beer:
In return, I will, after I finishing my work on these scripts, provide feedback on what parts of the script manual I think could need some touch-up/re-ordering.

Cheers,

Moritz

izyk
01-23-2003, 06:10 AM
Sorry for the delay - scripting answers often take longer...

About triggering the import of a PSD file from script? That cannot be done. The best I can think of is that you might be able to duplicate some of the ability with your own script

1. add a loader with the PSD file
2. read the layers drop down menu in the loader, and obtain the list of available layers from the attributes
3. assemble the flow by adding 1 loader for each layer

I have no idea if this will work - I don't have a PSD at home to test - it may not be possible to work out the layer ordering.

We can probably get the ability to trigger import funcgtions added to DFScript for the next version.

I recommend that your client render layers out to TIFF, or TGA files (only if they have the latest path for PS 7).

I can't answer your path questions until morning (I need to sleep now )

Mauritius
01-23-2003, 09:40 AM
Isaac.

1. add a loader with the PSD file
2. read the layers drop down menu in the loader, and obtain the list of available layers from the attributes

I had thought about that, but I never could find out where those damn layers where stored. I remember starring at the dump() of the Loader for half an hour but there wasn't any attribute that looked as if it could be what I was looking for.

Cheers,

.mm

izyk
01-24-2003, 02:17 PM
Ah. You won't find it there. You want to find out what the contents of a menu are, you need to look at the Menu controls attributes, not the Tools attributes


for example, the following script can be used from the console to print the layers available from Loader1 (assuming Loader 1 is a PSD or OMF file)

x = Loader1.Layer:GetAttrs()
print( x.INPST_ComboControl_String )

Thanks
Isaac Guenard
Product Manager - eyeon Software

Mauritius
01-25-2003, 03:51 PM
Yeah, that works well enough. But is there also a way to see what blend mode the layer had in the PSD?

Thx,

.mm

CGTalk Moderation
01-14-2006, 04:02 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.