Display clip (file) name?

User avatar
duofuan
Posts: 16
Joined: Sun May 27, 2018 3:18 am

Display clip (file) name?

#1

Post by duofuan » Thu Jul 11, 2019 4:26 am

Hi.

I'm completely new to fusion. I would like to create a script of setting to get a file name, take a part of it and display it as lower 3drs.

Could you help me?

Cheers!

User avatar
Midgardsormr
Fusionator
Posts: 1321
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 6
Location: Los Angeles, CA, USA
Been thanked: 120 times
Contact:

Re: Display clip (file) name?

#2

Post by Midgardsormr » Thu Jul 11, 2019 10:09 am

This thread will get you started:

viewtopic.php?p=10922#p10922

Parsing the filename so you're not showing the entire path can be done with bmd.parseFilename(), which is described in the scriptlib.lua file in your Scripts folder. For your convenience, here is the documentation from that file:

Code: Select all

------------------------------------------------------------------------------
-- parseFilename()
--
-- this is a great function for ripping a filepath into little bits
-- returns a table with the following
--
-- FullPath	: The raw, original path sent to the function
-- Path		: The path, without filename
-- FullName	: The name of the clip w\ extension
-- Name     : The name without extension
-- CleanName: The name of the clip, without extension or sequence
-- SNum		: The original sequence string, or "" if no sequence
-- Number 	: The sequence as a numeric value, or nil if no sequence
-- Extension: The raw extension of the clip
-- Padding	: Amount of padding in the sequence, or nil if no sequence
-- UNC		: A true or false value indicating whether the path is a UNC path or not
------------------------------------------------------------------------------
In Andrew's example comp, the Text+ tool's Styled Text input has this expression:
Text(self:GetSourceTool("MetadataSource").Output.Metadata.Filename)
which will show the full path of the current file. You can use parseFilename() to take just the part you want like so:
Text(bmd.parseFilename(self:GetSourceTool("MetadataSource").Output.Metadata.Filename).CleanName)

To break that down a little, working from inside to outside, self:GetSourceTool() will return the tool connected to an input, in this case "MetadataSource", which is the name of the custom image input that was added to the Text+ tool. The tool that we get in this fashion is assumed to have a standard output called Output, and you can read metadata off it, one field of which will be the filename. So we have someTool.Output.Metadata.Filename, which returns the full path of the image. That is what you feed to parseFilename().CleanName, which returns the CleanName field from the table described above. And, finally, Text() returns a Text object that the Text+ tool can use.

If you were doing this in a script, you'd probably assign variables for each piece, making it easier to read, but that's more difficult to do in a Simple Expression (not impossible, but probably more trouble than it's worth in this case).

User avatar
duofuan
Posts: 16
Joined: Sun May 27, 2018 3:18 am

Re: Display clip (file) name?

#3

Post by duofuan » Sun Jul 14, 2019 2:14 pm

Thanks for the reply!!!

I'm going to follow your guides.


:)

User avatar
duofuan
Posts: 16
Joined: Sun May 27, 2018 3:18 am

Re: Display clip (file) name?

#4

Post by duofuan » Sun Jul 14, 2019 4:31 pm

After trying many times different variations finally I've found the variation witch works for me:
in text+ node the expression is : self:GetSourceTool("MetadataSource").ClipName

The ones in your example didn't work at all.

Now the question is - how to apply this comp to all clips in my timeline at once?

User avatar
Iddos
Posts: 18
Joined: Sat Oct 06, 2018 4:21 pm
Been thanked: 2 times

Re: Display clip (file) name?

#5

Post by Iddos » Wed Jul 17, 2019 11:07 am

Now the question is - how to apply this comp to all clips in my timeline at once?
You can try using resolve script API to import fusion comp onto every clip in timeline.

User avatar
duofuan
Posts: 16
Joined: Sun May 27, 2018 3:18 am

Re: Display clip (file) name?

#6

Post by duofuan » Sat Jul 20, 2019 1:39 pm

Thanks Iddos, I'll try to figure it out.

User avatar
SirEdric
Fusionator
Posts: 2074
Joined: Tue Aug 05, 2014 10:04 am
Answers: 4
Real name: Eric Westphal
Been thanked: 162 times
Contact:

Re: Display clip (file) name?

#7

Post by SirEdric » Sun Jul 21, 2019 2:15 am

duofuan wrote:
Sun Jul 14, 2019 4:31 pm
in text+ node the expression is : self:GetSourceTool("MetadataSource").ClipName
Hmmm...interesting.
But how do you define the SourceTool of a Text+?

User avatar
Midgardsormr
Fusionator
Posts: 1321
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 6
Location: Los Angeles, CA, USA
Been thanked: 120 times
Contact:

Re: Display clip (file) name?

#8

Post by Midgardsormr » Sun Jul 21, 2019 7:59 am

SirEdric wrote:
Sun Jul 21, 2019 2:15 am
duofuan wrote:
Sun Jul 14, 2019 4:31 pm
in text+ node the expression is : self:GetSourceTool("MetadataSource").ClipName
Hmmm...interesting.
But how do you define the SourceTool of a Text+?
MetadataSource is a user control on the Text+. That was set up in Andrew's thread that I linked to early on.


duofuan: Apologies that I didn't test what I suggested. I was on vacation and didn't have Fusion or Resolve available to me, so I was working entirely from memory. If I had noticed that this was posted in the Resolve forum, I'd have been more careful, since a MediaIn doesn't work the same way as a Loader, and you don't actually need to parse out the path. And now that I stop to think about it, I don't think a Simple Expression can access the scriptlib, anyway, so I failed on two counts. :/


I don't have a clue about working with Resolve's timeline, so I can't help you there, but I'm glad you at least got the first part of the puzzle solved!

User avatar
SirEdric
Fusionator
Posts: 2074
Joined: Tue Aug 05, 2014 10:04 am
Answers: 4
Real name: Eric Westphal
Been thanked: 162 times
Contact:

Re: Display clip (file) name?

#9

Post by SirEdric » Sun Jul 21, 2019 8:32 am

Midgardsormr wrote:
Sun Jul 21, 2019 7:59 am
MetadataSource is a user control on the Text+. That was set up in Andrew's thread that I linked to early on.
Ah! I see! Totally missed that one...:-)

User avatar
Iddos
Posts: 18
Joined: Sat Oct 06, 2018 4:21 pm
Been thanked: 2 times

Re: Display clip (file) name?

#10

Post by Iddos » Sun Jul 21, 2019 10:07 am

For adding fu comps to timeline clips using python:

After instantiating a Resolve object. (I'm using "python_get_resolve")

This should do it:
  1. from python_get_resolve import GetResolve
  2.  
  3. resolve = GetResolve()
  4.  
  5. projectManager = resolve.GetProjectManager()
  6. project = projectManager.GetCurrentProject()
  7. currentTimeline = project.GetCurrentTimeline()
  8.  
  9. video1Clips = currentTimeline.GetItemsInTrack('video', 1)
  10.  
  11. for key in video1Clips:
  12.     video1Clips[key].ImportFusionComp('PATH TO COMP.comp')

User avatar
duofuan
Posts: 16
Joined: Sun May 27, 2018 3:18 am

Re: Display clip (file) name?

#11

Post by duofuan » Sun Aug 04, 2019 11:25 am

Thanks guys a lot for responses especially Iddos.
No problem Midgardsormr . After trials and errors slowly I'm getting there.

For a while I was out but now I have some time to try out the script.

One more (I figure simple) question is how to extract a part of a file name?
The result of expression self:GetSourceTool("MetadataSource").ClipName is a filename, in my case filenames are in format: 2018_05_31= 21_30_10.MP4

I was searching this on internet but without success. How can I adapt my expression above to get only date from filename like such: "2018-05-31" ?

What language is used for fusion expressions anyway? Is it lua?

User avatar
duofuan
Posts: 16
Joined: Sun May 27, 2018 3:18 am

Re: Display clip (file) name?

#12

Post by duofuan » Mon Aug 05, 2019 1:32 am

So I'm making my steps forward.
I've found in Text+ properties on the tab with a cogwheel a lua script can be written into "Frame Render Script" field.
So after removing the expression from styled text field on "T" tab and pasting following lines int "Frame Render Script" :

varr = self:GetSourceTool("MetadataSource").ClipName
self.StyledText = varr

it works as is should.

Using string.gsub() function on any string works fine but strangely if I use it on varr variable it won't execute the script.
Is is because varr is not a string? Is there a way to convert it?
I'm confused

User avatar
SirEdric
Fusionator
Posts: 2074
Joined: Tue Aug 05, 2014 10:04 am
Answers: 4
Real name: Eric Westphal
Been thanked: 162 times
Contact:

Re: Display clip (file) name?

#13

Post by SirEdric » Mon Aug 05, 2019 5:24 am

It should work when supplying an index: varr = self:GetSourceTool("MetadataSource").Clip[1].Filename

User avatar
duofuan
Posts: 16
Joined: Sun May 27, 2018 3:18 am

Re: Display clip (file) name?

#14

Post by duofuan » Tue Aug 06, 2019 1:39 am

Sadly it doesn't work.

I found that the result of self:GetSourceTool("MetadataSource").ClipName is of type cdata.
Now I need to figure how to cast cdata object to string and I'm home

User avatar
SirEdric
Fusionator
Posts: 2074
Joined: Tue Aug 05, 2014 10:04 am
Answers: 4
Real name: Eric Westphal
Been thanked: 162 times
Contact:

Re: Display clip (file) name?

#15

Post by SirEdric » Tue Aug 06, 2019 10:09 am

As said before, I tested my last example and it works.