Extract File name and path from image
Hello
I recorded a module which opened up an image. I wanted to then extract the filename and path so that this could be associated with analysis results when they are sent to excel but none of the variables appear to hold the filename except for the manually entered part which isn't really what I want as I need this to be automatic. The code is below:
Public Function NewMacro() As SimpleScript NewMacro = New SimpleScript Dim docList1 = New List(1), doc1 With Application.DocumentCommands.Open(NewMacro) .Filenames = New String() {"C:\Users\dkelly2\Desktop\NET47Chr19z_1_w2FITC.TIF"} .Run(docList1) End With With Application.DocumentCommands.Activate(NewMacro) .Run(docList1(0), doc1) End With End Function
I added a watch on docList1, docList(0), doc1, List1 and none of them appear to hold the info. Does anyone know how I would extract this
Regards
David
Best Answers
-
Hi David,FileName can be extracted from File operator of McImage, so you can get it using:
Public Function PrintImageFileName() As SimpleScript PrintImageFileName = New SimpleScript Dim docList1 = New List(1), doc1 With Application.DocumentCommands.OpenImage(PrintImageFileName) .Filenames = New String() {""} .Run(docList1) End With With Application.DocumentCommands.Activate(PrintImageFileName) .Run(docList1(0), doc1) End With With Automate.ScriptingCommands.CodeCommand(PrintImageFileName) If .Run() Then 'print file name' Dim im As McImage=doc1.Data Dim fileName As String=im.File.FullPathName Debug.Print (fileName) End If End With End Function
To have intellisense for File object in the scripting workbench you have to add reference to MediaCy.IQL.IO.dll.Regards,Yuri0 -
Dave,
If I leave Yuri's code exactly as supplied, it prompts me for the file to open, and if I open the file, the output gets printed out to the Immediate window in the Project Workbench. Note that if you are looking at your script in design mode, you won't by default see the Immediate window - I always switch to Code view, where the Immediate, Watch, etc. windows are displayed at the top.
BR,
John
0
Answers
Hello Yuri/Pierre,
Neither answer worked until I modified them as below. The If .run statements are always false so it never runs so I deleted this. The code below works but for reasons I can't follow it loops 3 times on the Dim im As McImage=doc1.Data then on the 4th loop it opens the image and goes on to print the filename.
Hello Yuri
How would you use CodeCommand I can't declare it in Public Function NewMacro and if you declare it anywhere else in the function it doesn't work or throws an error.
Regards
David
Hello Yuri
I've inserted the code as suggested (my code below) but it still loops 4 times before opening the image and then crashes when it attempts to find the file name.
Hello Yuri,
I was using that code when I posted this morning, it doesn't work at all if you leave the if statement in, it starts runs through once doesn't open anything and stops. When you remove the if statement it loops 4 times before opening the image and getting its filename for future use. It was at that point you suggested using With Automate ScriptingCommands CodeCommand to stop the looping which seems to have caused a bigger problem.
Regards
David
Dave,
The if statement is necessary to have your custom code in the CodeCommand execute ONCE and only once, at the right time. What exactly happens when you run it as Yuri originally supplied it?
BR,
John
Hello John
I was using it in code view and debug mode to try and figure out the scripting language which is when I noticed the looping and it didn't make sense to me. Running it in Design mode works but its slow so I suspect its still up to something in the background.
I'm putting this down to the very steep learning curve between swapping between Image Pro and Premier
Regards
David
The following IPP9 variables are the ones that I've found and used for tasks similar to the one that I think that you are working on:
ThisApplication.ActiveDocument.FileName
ThisApplication.ActiveDocument.DisplayName
ThisApplication.ActiveImage.Name
ThisApplication.ActiveWindow.Name
These variables and the values they produce are demonstrated in the FRED.IPX file that is attached to this contribution to this question. The BARNEY routine (within the WILMA module within the FRED project) sends various versions of the name of the current image to the PREMIER OUTPUT WINDOW.
I hope this information is helpful.
-- Matt