Start a new topic
Answered

New Picture path after migration to new machine - remap?

Maybe I just missed it but is there a chance to remap all picture paths? Simple explanation: On my old machine all pictures were stored in E:\abcd\pics Now on my new machine drive E is gone it is just D:\pics Of course setting the picture paths in options is possible but that seems not to effect all (existing) pictures. Any idea except creating a drive E? ;-)

Best Answer

You could do this with a script. Something like this should do it (please make sure you have a backup before executing this. I did try this before but it might not work equally well for others...)


using System;

using NeonScripting;

using System.Collections;

using System.Collections.Generic;

using System.IO;

using System.Text;

using System.Text.RegularExpressions;

using System.Linq;


public class Script

{

    public bool Run(INeonScriptHost host)

    {

        var oldPictureFolder = host.RemoteCalls.InputDialog("Please type in the old picture path.");

        var newPictureFolder = host.RemoteCalls.InputDialog("Please type in the new picture path.");

        

        if(string.IsNullOrEmpty(oldPictureFolder) || string.IsNullOrEmpty(newPictureFolder))

        {

            return false;

        }

        

        var albums = host.Database.Albums.ToList();

        var idx = 1;

        foreach (var album in albums)

        {

            host.UpdateProgress($"Updating album picture path for album {idx} of {albums.Count()}");


            if(album.AlbumPicturePath.StartsWith(oldPictureFolder)) 

            {

                var newAlbumPicturePath = album.AlbumPicturePath.Replace(oldPictureFolder, newPictureFolder);

                host.Database.UpdateAlbumPicture(album, newAlbumPicturePath);

            }

            idx++;

        }


        return true;

    }

}



Answer

You could do this with a script. Something like this should do it (please make sure you have a backup before executing this. I did try this before but it might not work equally well for others...)


using System;

using NeonScripting;

using System.Collections;

using System.Collections.Generic;

using System.IO;

using System.Text;

using System.Text.RegularExpressions;

using System.Linq;


public class Script

{

    public bool Run(INeonScriptHost host)

    {

        var oldPictureFolder = host.RemoteCalls.InputDialog("Please type in the old picture path.");

        var newPictureFolder = host.RemoteCalls.InputDialog("Please type in the new picture path.");

        

        if(string.IsNullOrEmpty(oldPictureFolder) || string.IsNullOrEmpty(newPictureFolder))

        {

            return false;

        }

        

        var albums = host.Database.Albums.ToList();

        var idx = 1;

        foreach (var album in albums)

        {

            host.UpdateProgress($"Updating album picture path for album {idx} of {albums.Count()}");


            if(album.AlbumPicturePath.StartsWith(oldPictureFolder)) 

            {

                var newAlbumPicturePath = album.AlbumPicturePath.Replace(oldPictureFolder, newPictureFolder);

                host.Database.UpdateAlbumPicture(album, newAlbumPicturePath);

            }

            idx++;

        }


        return true;

    }

}


Thanks, Fredrik!

I assumed this is a JSON script, so I entered the paths and saved it as *.json.

        var oldPictureFolder = host.RemoteCalls.InputDialog("E:\Helium13\pics\");
        var newPictureFolder = host.RemoteCalls.InputDialog("C:\Helium14\pics\");


When I tried to run it HMM crashes (with bug window).
I tried *.cs then. Doing this the script is not recognised by "run script" tool in HMM.

Ideas? Where's my error?

Hi Mathias,


You need both a JSON file (which contains only descriptions and meta data for the script) and a .cs file (which is the actual script).


Have a look at this guide:


https://imploded.freshdesk.com/support/solutions/articles/9000047881-scripting-basics 


And just let me know if there is something else that is unclear (I'm sure there is!).

Thanks...stupid me
I recognize a RTFM, when I see it ;-)
You are too patient!


I created a new folder in scripts "MT"

When I execute the script I get an error message:

File not found: C:\Users\Mathias\AppData\Roaming\Imploded Software\Helium 14\Scripts\MT\firstscriptfiletoexecute.cs

Strangely I cannot find the cs in any other folder in Scripts..


Do you have any example scripts under the ..\Scripts folder? Sounds like that folder is empty on your system?


I'm attaching a zip with the scripts that is shipped with Helium. There may be circumstances where these gets lost after an upgrade I think.

zip
(25.2 KB)

The important thing for a script to be able to execute is:


There should be two files in the same folder, e.g:


MYSCRIPT.cs

MYSCRIPT.json


The MYSSCRIPT.json file must have the exact filename of the MYSCRIPT.cs in the "EntryPoint" value.


Please look at one of the examples in the zip file (if you didn't already have them on your system).


If you still can't make it to work, please zip and attach your script and json file here and I'll have a look!

I had all the files and my files were named as you described.

I still get the error msg, then the script is executed ("1 of 1 script") but it's very fast -> too fast.


Which Item/Node do I have to select before starting the script? Or is this irrelevant?

zip
(980 Bytes)

I found the problem.


Open the ExchangeAlbumPicturePath.json in a text editor and change the:


"firstscriptfiletoexecute.cs"


to


"ExchangeAlbumPicturePath.cs"


that should do it.

Ah! Now we are a step further:


(19,64): error CS1009: Unrecognized escape sequence
(19,73): error CS1009: Unrecognized escape sequence
(19,61): error CS1010: Newline in constant
(19,82): error CS1003: Syntax error, ',' expected
(21,13): error CS1003: Syntax error, ',' expected
(21,64): error CS1009: Unrecognized escape sequence
(21,73): error CS1009: Unrecognized escape sequence
(21,61): error CS1010: Newline in constant
(21,82): error CS1026: ) expected
(21,82): error CS1026: ) expected
(21,82): error CS1002: ; expected
(21,9): error CS0103: The name 'var' does not exist in the current context
(21,13): error CS0103: The name 'newPictureFolder' does not exist in the current context
(25,75): error CS0103: The name 'newPictureFolder' does not exist in the current context
(50,92): error CS0103: The name 'newPictureFolder' does not exist in the current context



Strings in C# treats backslashes as an escape sequence which is not what we want here so please change these lines into this (notice the added @ sign)


        var oldPictureFolder = host.RemoteCalls.InputDialog(@"E:\Helium13\pics\");

        var newPictureFolder = host.RemoteCalls.InputDialog(@"C:\Helium14\pics\");


Now I get two windows after each other (first attached).
Just information? If I confirm both with ok the script is aborded...

msgWin.PNG
(5.28 KB)

my fault
I had some unavailable tracks in there... script has gone through
I still got he windows after that and an "abort" message but I think it worked!

Oh!


Looks like I misinterpreted my own script, haha.


The lines should look like this:


        var oldPictureFolder = host.RemoteCalls.InputDialog("Please type in the old picture path.");

        var newPictureFolder = host.RemoteCalls.InputDialog("Please type in the new picture path.");


The text that is sent to the InputDialog is the text that is shown in the two dialog boxes and here you should put in your own "old" and "new" paths when running the script. This is to make the script work in all environments since you shouldn't hard code anything.


1 person likes this

looks even better now ;-)
(4000 Albums processed)

thanks a lot!

Login or Signup to post a comment