• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Expression Get Project Path or Name

New Here ,
Jul 25, 2013 Jul 25, 2013

Copy link to clipboard

Copied

Hi,

I am new to After Effects as in I have just seen it for the first time today!

What I'd like to know is, is it possible to write an expression to return either the current project name or file path?

I'm assuming no as I cannot find any reference to this in the language reference. How would I go about integrating a script with the project to return the project name?

I have tried something basic like:

Expression code:

var currpath = $.evalFile(filepath);

filepath is the path to my script file, the script is like the below:

GetPath()

function GetPath() {

return app.project.name;

}

With this I get an error similar to method name 'Global' not found - not at my work computer so can't remember the exact message.

Any help would be appreciated.

Thanks,

Mark

TOPICS
Expressions

Views

10.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 25, 2013 Jul 25, 2013

Copy link to clipboard

Copied

Doesn't look like it's directly accessible. The top level properties and methods came back as:

PROPERTIES:

          name

          numEntries

          numProperties

          propertyIndex

          active

          enabled

>Global

          this_comp

          this_layer

          this_property

          thisComp

          time

          color_depth

          colorDepth

<

>Vector Math

>Random Numbers

>Interpolation

>Color Conversion

>Other Math

>--------

>Layer

>Sub-objects

          source

>General

          width

          height

          index

          parent

          has_parent

          in_point

          out_point

          start_time

          has_video

          has_audio

          hasParent

          inPoint

          outPoint

          startTime

          hasVideo

          hasAudio

          audio_active

          audioActive

>Properties

          anchor_point

          anchorPoint

          position

          scale

          rotation

          opacity

          audio_levels

          time_remap

          audioLevels

          timeRemap

          marker

>3D

          orientation

          rotationX

          rotationY

          rotationZ

          castsShadows

          casts_shadows

          lightTransmission

          light_transmission

          acceptsShadows

          accepts_shadows

          acceptsLights

          accepts_lights

          ambient

          diffuse

          specularIntensity

          specular

          specularShininess

          shininess

          metal

>Space Transforms

          __proto__

METHODS:

propertyGroup

comp

footage

posterize_time

posterizeTime

timeToFrames

framesToTime

timeToTimecode

timeToNTSCTimecode

timeToFeetAndFrames

timeToCurrentFormat

add

sub

mul

div

clamp

dot

cross

normalize

length

look_at

lookAt

seed_random

seedRandom

random

gauss_random

gaussRandom

noise

linear

ease

ease_in

ease_out

easeIn

easeOut

rgb_to_hsl

hsl_to_rgb

rgbToHsl

hslToRgb

degrees_to_radians

radians_to_degrees

degreesToRadians

radiansToDegrees

sourceTime

effect

mask

sampleImage

to_comp

from_comp

to_world

from_world

to_comp_vec

from_comp_vec

to_world_vec

from_world_vec

from_comp_to_surface

computePSDRoll

world_position_to_psd

world_rotation_to_psd

world_scale_to_psd

toComp

fromComp

toWorld

fromWorld

toCompVec

fromCompVec

toWorldVec

fromWorldVec

fromCompToSurface

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 25, 2013 Jul 25, 2013

Copy link to clipboard

Copied

Simple !

app.project.file

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 25, 2013 Jul 25, 2013

Copy link to clipboard

Copied

I thought he was trying to do so through an expression though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

Hi,

Yes I'm trying to do it through an expression.

Essentially what I am doing is creating videos on the fly with bits of information being added to placeholders throughout the video, AE only allows absolute paths for these though.

If it can't be done as an expression, how would I get a script to return the project name to an expression? I have tried running a script using the evalFile() method but this seems to execute the script WITHIN the expression and hence fails as expressions don't have such functions as app.project etc etc. Is it possible to include a script in a project and call it directly in the expression. So if I had a script with a method called getFile(), could I add that script to the project and call it within an expression?

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

I don't think the object "app" exists in expressions, so you maybe had something like "global has no property called app".

http://help.adobe.com/en_US/aftereffects/cs/using/WS3878526689cb91655866c1103906c6dea-7a0ca.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

Yeah that's what I had as it doesn't exist in expressions.

How can I call a script from an expression that would return the current project name?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

I don't think you can do that, but then why would you need an expression at all? It's not like the name will change very often and you need to always update it.

Couldn't you just run a script that would write the project name inside a Text layer? In this case app.project.name will work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

Well I will be making personalised videos on the fly for potentially thousands of users and what I was thinking, if I couldn't get the project path, was to rename the project file for each user with their ID and read that in, as their ID will correspond to their folder path.

How would I run a script to do such a thing, would that need to be ran by using the file menu or can an expression call that? If I was able to automate that script running, would an expression be able to read in the text value in the layer once the script has ran?

Sorry for the questions, I'm very new to this!

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

argggh ... I was editing my answer and you posted your message ... I lost the code I was typing.

Here's a second attempt:

var comp = app.project.activeItem;

if (     comp &&

          comp instanceof CompItem &&

          comp.selectedLayers.length == 1)

{

     var layer = comp.selectedLayers[0];

     if (layer instanceof TextLayer)

     {

          layer.sourceText.setValue(app.project.file);

     }

}

Select a single text layer and run the script (go in File > Scripts to create and run scripts, or run the extendscript toolkit since you can hook it to AE, in the top-left dropdown).

All this is explained here, you just need to go through the classes and you'll understand how to use them:

http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/aftereffects/pdfs/aftereffectsc...

David will recommend you to read the CS6 scripting guide:

http://blogs.adobe.com/aftereffects/files/2012/06/After-Effects-CS6-Scripting-Guide.pdf?file=2012/06...

... but keep in mind that CS4, CS5 and CS5.5 will be missing stuff from the CS6 guide so it's safer to start with features from the CS3 guide and then handle the new CS6 ones.

Copying the post before submitting ... just in case 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

Cool, cheers for that and sorry for making you loose your work!

Is there anyway I can make a script run automatically or can it only be ran from the scripting menu?

I see you can run a script from commandline but I take it that means you have to have the project already open, or can I open the project from command line and then run the script?

Oh yeah and I take it an expression can read in the text from the layer okay?

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

I don't know Mark, that really depends on how you want to use all that.

The three choices for scripts are:

- put the script in the Script/Startup folder, this will run on startup of AE obviously but I don't remember if that is used before or after the project is open

- put the script in the root of the Script folder and it will then appear in the script list in File > Script. Then I think you can add a keyboard shortcut for that by using the script Keyed Up

- put the script in the Script/ScriptUI Panel folder and then it'll appear in the menu under Window, and will get open in a panel.

I think you've got all the info now, all this is already explained in many places too:

look for Dan Ebberts (motionscript), David Torno (tutorials on PVC), this forum, videocopilot.net/forum, ...

EDIT: I didn't put the command line thing since already know about that, but note that it doesn't work on Mac, instead you need to use DoScript in an AppleScript

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

Yeah it seems that the script is ran before the project opens so doesn't work.

Only other thing I can think is can I use the command line to do the following:

  • Open Project
  • Run Script
  • Render Project

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

Oh got that part sorted!

Created a bat file like so:

"full path to afterfx.exe" -r full path to script (no quotes around script path)

When it runs it opens the project file and runs the script!

Now to figure out how to replace footage items....

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

OK I think this is starting to make sense to me: so you want to have a template project that you'd copy/rename before opening, then open it and you want the text and footage to come from say a folder with the same name as the project, is that right?

To replace footage item you need to read about the Project, AVLayer and FootageSource objects in the scripting guide. I don;t know what you want to do exactly but Project has an importFile functions, AVLayer has a replaceSource function, ... one should be what you need.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 14, 2013 Aug 14, 2013

Copy link to clipboard

Copied

Hi,

So it's been a few weeks from I posted here and I found a solution to my problem.

Essentially I was going down the scripting route initially to try to pull in the project path to build up an expression dynamically.

This was because each video is created on the fly and I couldn't set fixed paths, the expression would then read in various values and add them to placeholders within the video itself. The video would then be rendered using a batch file called from .net code.

Well, the scritting route just did not cut it - expressions just can't do dynamic paths or custom fuctions. I was able to get a script to work, but this meant opening after effects to allow the script to trigger, saving using the script, then rendering the video - a process that was taking too long.

Instead what I ended up doing was to convert the project to an xml format aepx I believe. This then creates a 'human readable' project. You can open this project file with a text editor and manipulate it.

With this in mind, I simply found the expressions I needed to be updated and added placeholder text such as [username]. When the video is being created, my c# .net code just copies the project file to a users folder, updates these placeholders with the correct values (even though adobe says the xml projects are human readable, all the values are in hex, so you need to convert everything to hex code before updating the placeholders) then save the project. I am then able to render using the batch file I wrote and the video is then ready.

You can go and have a look at the finished result here: https://www.facebook.com/VisitNMNI/app_155678694620856

(you will need to authenticate with facebook  to allow it to pull in some details - name, hometown and profile

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

I think this must work... (on Mac 😉 )

 

projectPath = thisProject.fullPath.split("/").length;

projectName = thisProject.fullPath.split("/")[projectPath - 1];

 

Cheers!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

LATEST

Yes!
And for Windows replace

"/" with "\\"

Thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines