Nexrender: Passing arguments to jsx script

Created on 12 Oct 2019  Â·  6Comments  Â·  Source: inlife/nexrender

Is your feature request related to a problem? Please describe.
It seems that this library doesn't support passing arguments to a JSX script. It would be really handy.

Describe the solution you'd like
It would be great if there was a way to send an array of parameters in the JSON object.

Describe alternatives you've considered
The only solution is to create a file with the parameters and read it in the script, however that is a bit of a hassle since it would limit the rendering to one item a time.

feature

Most helpful comment

Nvm, you can easily pass parameters using assets.

All 6 comments

Nvm, you can easily pass parameters using assets.

@ahardworker pass parameters using assets to the script or to the global operation? If it's the former, what's the syntax for it?

I'd still like this as a feature (unless passing params with assets is actually easier than I realize—not clear atm).

Apparently the current solution, which was briefly discussed on discord (invite), is to compile a script with the correct parameters, encode it in base64 and pass it to the JSON file as an asset using the data:// protocol.

So one solution off the top of my head could be to enhance the data script asset with a parameter parsing/injection feature, which would in turn require to have a different syntax of the script code to handle blank/placeholder parameters maybe?

So one solution off the top of my head could be to enhance the data asset with a parameter parsing/injection feature, which would in turn require to have a different syntax of the script code to handle blank/placeholder parameters maybe?

I think this idea is in the right direction; I've found the following approach most convenient:

{
    type: "data",
    property: "startTime",
    expression: `
      var comp;
      for (var i = 1; i <= app.project.numItems; i++) {
          if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === "${compName}")) {
              comp = app.project.item(i);
              break;
          }
      }
      comp.duration = comp.layer(1).outPoint;
      layer.startTime;
    `
  }

Basically, this uses a data/expression asset to execute a script with injected parameters. The final line of the script sets the layer property startTime (arbitrary) to the same value. This allows the opportunity to run an arbitrary script defined in code rather than a file.

If this approach isn't too crazy, it would be nice to have a { type: "script", expression: "..." } option or similar which didn't require dummy values for layerIndex / layerName and property.

—

More useful example:

...
assets.push(
      getAssetForSetPropertyToParentProperty({
        layer: { index: 1, property: "startTime" },
        parent: { index: 2, property: "outPoint" }
      })
    );
...
function getAssetForSetPropertyToParentProperty({
  layer,
  parent
}: {
  layer:
    | { name: string; property: string }
    | { index: number; property: string };
  parent:
    | { name: string; property: string }
    | { index: number; property: string };
}) {
  const asset = {
    type: "data",
    property: `${layer.property}`,
    expression: `
      var comp;
      for (var i = 1; i <= app.project.numItems; i++) {
          if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === "${compName}")) {
              comp = app.project.item(i);
              break;
          }
      }
      comp.layer(${
        "name" in parent ? '"' + parent.name + '"' : parent.index
      }).${parent.property};
    `
  };
  return "name" in layer
    ? { layerName: layer.name, ...asset }
    : { layerIndex: layer.index, ...asset };
}

My PR #307 has an implementation of dynamic variables! Try it out @danielgwilson and let me know if it's of any use to your case.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

senthudms picture senthudms  Â·  3Comments

panchenkoprog picture panchenkoprog  Â·  5Comments

byumark picture byumark  Â·  3Comments

pdkn picture pdkn  Â·  5Comments

dsrts picture dsrts  Â·  3Comments