// CompareImages // (c) 2024 Kundal // This is a script for Directory Opus. // See https://www.gpsoft.com.au/endpoints/redirect.php?page=scripts for development information. // v1.1 // - add some command line parameter handling // v1.0 // - initial version // Called by Directory Opus to initialize the script function OnInit(initData) { initData.name = "CompareImages"; initData.desc = "Zeigt eine in der Quelle ausgewählte Bilddatei gemeinsam mit der Datei gleichen " + "Namens im Ziel in einem Dialogfenster und bietet die Option, die Zieldatei mit der Quelldatei zu überschreiben."; initData.version = "1.1"; initData.copyright = "(c) 2024 Kundal"; initData.default_enable = true; initData.min_version = "13.0"; var cmd = initData.AddCommand; cmd.name = "CompareImages"; cmd.method = "OnCompareImages"; cmd.label = "CompareImages"; cmd.template = "SOURCEFILE/O,DESTFILE/O"; } /////////////////////////////////////////////////////////////////////////// String.prototype.getFilePart = function (){ return this.split("\\").slice(-1)[0]; } /////////////////////////////////////////////////////////////////////////// String.prototype.getParentPart = function (){ var arr = this.split("\\"); arr.pop(); //remove last element return arr.join("\\"); } /////////////////////////////////////////////////////////////////////////////// var COMMAND_FAILURE = true; var COMMAND_USERABORT = true; var COMMAND_BADPARAMS = true; var COMMAND_SUCCESS = false; // Funktion CompareImages function OnCompareImages(clickData) { var srcFilePath = ""; var dstFilePath = ""; if (clickData.func.args.got_arg["SOURCEFILE"] && clickData.func.args.got_arg["DESTFILE"]) { DOpus.Output("Using command line parameters."); srcFilePath = clickData.func.args["SOURCEFILE"]; dstFilePath = clickData.func.args["DESTFILE"]; } else { if (!clickData.func.sourcetab.selected.count){ DOpus.Output("No files selected and no files given on command line, aborting."); return COMMAND_FAILURE; } DOpus.Output("Using selected file(s) in src and/or dst tab(s)." + clickData.func.sourcetab.selected.count); if (0){;} else if (clickData.func.sourcetab.selected.count==2) { // using two files from source srcFilePath = ""+clickData.func.sourcetab.selected[0].realpath; //forcing toString() dstFilePath = ""+clickData.func.sourcetab.selected[1].realpath; //forcing toString() } else if (clickData.func.sourcetab.selected.count==1 && clickData.func.desttab.selected.count==1) { //using 1 file from source and 1 file from dest srcFilePath = ""+clickData.func.sourcetab.selected[0].realpath; //forcing toString() dstFilePath = ""+clickData.func.desttab.selected[0].realpath; //forcing toString() } else { //using file from source, expecting same file to exist in dest srcFilePath = ""+clickData.func.sourcetab.selected[0].realpath; //forcing toString() dstFilePath = clickData.func.desttab.path + "\\" + clickData.func.sourcetab.selected[0].name; } } DOpus.Output("srcFilePath: " + srcFilePath ); DOpus.Output("dstFilePath: " + dstFilePath ); var dlg = clickData.Func.Dlg; var cmd = DOpus.Create.Command; // Temporäre skalierte Kopien erzeugen. /* var tmpFilePathOne = "/temp\\tmp_one_"+srcFilePath.getFilePart();; var tmpFilePathTwo = "/temp\\tmp_two_"+dstFilePath.getFilePart(); var cmdLine = 'Image CONVERT FROM="'+srcFilePath+'" TO="'+tmpFilePathOne.getParentPart()+'" AS="'+tmpFilePathOne.getFilePart()+'" HEIGHT=1024 PRESERVEASPECTRATIO REPLACE=always'; DOpus.Output("cmd: " + cmdLine); cmd.RunCommand(cmdLine); var cmdLine = 'Image CONVERT FROM="'+dstFilePath+'" TO="'+tmpFilePathTwo.getParentPart()+'" AS="'+tmpFilePathTwo.getFilePart()+'" HEIGHT=1024 PRESERVEASPECTRATIO REPLACE=always'; DOpus.Output("cmd: " + cmdLine); cmd.RunCommand(cmdLine); */ // Hauptdialog dlg.template = "dialog1"; dlg.position = "parent"; dlg.want_resize = true; dlg.Create; dlg.Control("Bild1").label = DOpus.Loadimage(srcFilePath); dlg.Control("Bild2").label = DOpus.Loadimage(dstFilePath); dlg.Control("edit1").value = srcFilePath dlg.Control("edit2").value = dstFilePath //dlg.RunDlg; dlg.detach = true; dlg.Show(); while (true) { var Msg = dlg.GetMsg(); if (!Msg.result) break; DOpus.Output("Msg Event = " + Msg.event + " - " + dlg.cx + " - " ); //dlg.Control("Bild1").cx = dlg.Control("group1").cx; } DOpus.Output("Return code = " + dlg.result); //cmd.RunCommand('Delete FILE="'+tmpFilePathOne+'" Quiet'); //cmd.RunCommand('Delete FILE="'+tmpFilePathTwo+'" Quiet'); return COMMAND_SUCCESS; } ==SCRIPT RESOURCES