PDF Explorer > General

Custom script keywords for directory listing and loading text

<< < (3/3)

RTT:

--- Quote from: Padanges on August 31, 2016, 01:48:39 PM ---But can you get the list of current grid layout custom field column names?

--- End quote ---
No. You can get the list of all the available fields:

--- Code: ---var FieldsInfo = pdfe.MetadataFieldsInfo;
for (var fIndex = 0; fIndex < FieldsInfo.count; fIndex++) {
    pdfe.echo(FieldsInfo(fIndex).caption + ' : ' + FieldsInfo(fIndex).PropertyName);

--- End code ---
but there is no specific access to just the list of columns in the current grid layout, even because what changes when the script edits the metadata is the metadata stored in the DB and, eventually, in the file itself. The grid only reflects these changes.


--- Quote ---You also use Arguments property ("var Filename = pdfe.Arguments(i);") which in documentation is descibed as "Provides access to the entire collection of command-line parameters, in the order in which they were originally entered."

--- End quote ---
This property exists only for compatibility with the WSH WScript Object, and contains the list of selected files. This way you can drop many readily available WSH scripts, and they will run without major changes.


--- Quote ---while FileSummary ("var Summary = FileSummary.Read(Filename);") is undefined at all

--- End quote ---
You will find the implementation of the FileSummary object under the sample libraries, "File Summary Info" script. The main script links to that one, using the includes functionality.


--- Quote ---And finally, if I'm correct, to change an entry, you have to assign values and execute "FileMetadata.CommitChanges();". Could you help to find out how can we reference a specific column entry and the column name list?

--- End quote ---
As said above, there is no way to know just what columns are showing. Why do you need to know that, when you have access to all the fields?

--- Code: ---var FieldsInfo = pdfe.MetadataFieldsInfo;
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var file = pdfe.SelectedFiles(i);
    pdfe.echo(file.filename);
    var metadata = file.metadata;
    for (fIndex = 0; fIndex < FieldsInfo.count; fIndex++) {
        //by name:
        pdfe.echo('     ' + FieldsInfo(fIndex).caption + ' : ' + metadata[FieldsInfo(fIndex).PropertyName]);
        //by index:
        //pdfe.echo('     ' + FieldsInfo(fIndex).caption + ' : ' + metadata(fIndex));
    }
}

--- End code ---

Padanges:

--- Quote ---As said above, there is no way to know just what columns are showing. Why do you need to know that, when you have access to all the fields?
--- End quote ---
I was thinking about a combo-box which gives the list populated only by visible column names. Can we read visible column names from a layout grid data file?


--- Quote ---but there is no specific access to just the list of columns in the current grid layout, even because what changes when the script edits the metadata is the metadata stored in the DB
--- End quote ---
Please correct me if I'm wrong, but columns in PDFe are PDF object metadata fields (excluding: F,FS,AN,FP,DL,DS,FD,NP) appended with the Custom fields and
listed in the order of their creation? And if (saved) layout grids simply toggle their visibility then custom grid layout lists those columns which are real DB
fields - in other words, removing a custom field removes its column from all the grid layouts at the same time?


--- Quote ---You will find the implementation of the FileSummary object under the sample libraries, "File Summary Info" script.
--- End quote ---
Honestly, I still can't get my head around this... I need something like this:

--- Code: ---var rowId = 0; // that's PDF file entry in the grid
var columnId = 1; // that's field (column) entry
// get the db metadata entry value
var value = pdfe.SelectedFiles(rowId).Metadata.Item(columnId);
pdfe.echo(value);

--- End code ---
Could you help me a little with this?


P.S. try editing current grid layout while having deleted all custom fields ;) here be dragons.

RTT:

--- Quote from: Padanges on September 01, 2016, 04:19:14 PM ---Can we read visible column names from a layout grid data file?

--- End quote ---
The layouts definitions are kept in the registry, at: HKEY_CURRENT_USER\SOFTWARE\PDFExplorer\GridLayout


--- Quote ---Please correct me if I'm wrong, but columns in PDFe are PDF object metadata fields (excluding: F,FS,AN,FP,DL,DS,FD,NP) appended with the Custom fields and
listed in the order of their creation? And if (saved) layout grids simply toggle their visibility then custom grid layout lists those columns which are real DB
fields - in other words, removing a custom field removes its column from all the grid layouts at the same time?

--- End quote ---
Grid layouts just define how the full available metadata returned from a DB query is displayed.


--- Quote ---Honestly, I still can't get my head around this... I need something like this:

--- Code: ---var rowId = 0; // that's PDF file entry in the grid
var columnId = 1; // that's field (column) entry
// get the db metadata entry value
var value = pdfe.SelectedFiles(rowId).Metadata.Item(columnId);
pdfe.echo(value);

--- End code ---
Could you help me a little with this?

--- End quote ---
The My Scripts API doens't take into account anything related to the grid layout. Things are just not connected. If you explain better what you want to achieve, maybe I can give you some workaround ideas.
But here is a dirty hack script that uses the last running session grid layout information (there is no way to know what's the current session layout), to list the data. Have fun :D

--- Code: ---var WshShell = new ActiveXObject("WScript.Shell");
var LastSessionGridLayoutIndex = WshShell.RegRead("HKEY_CURRENT_USER\\SOFTWARE\\PDFExplorer\\GridLayout\\GridLayoutIndex");

//LastSessionGridLayoutIndex = 0;

if (LastSessionGridLayoutIndex > 3) {
    var layout = WshShell.RegRead("HKEY_CURRENT_USER\\SOFTWARE\\PDFExplorer\\GridLayout\\Custom\\str" + (LastSessionGridLayoutIndex - 4))
    layout = String.fromCharCode.apply(String, VB2JSArray(layout));
} else {
    var layout = WshShell.RegRead("HKEY_CURRENT_USER\\SOFTWARE\\PDFExplorer\\GridLayout\\Std\\S" + LastSessionGridLayoutIndex)
}

if (layout.indexOf('<column>') > 0) {
    var Columns = layout.match("<column>(.*?),</column>")[1].split(',')
} else {
    var Columns = layout.substr(layout.indexOf('=') + 1).split(',');
}

var ColumnNames = "Filename,File Path,Disk label,Disk serial,Size,Date,Title,Subject,Author,Keywords,Creator,Producer,Creation Date,Modification Date,Pages,Version,Security,Archive".split(',');
var FieldsInfo = pdfe.MetadataFieldsInfo;

var LayoutName = layout.substr(0, layout.indexOf('=<'));
for (var rowI = 0; rowI < pdfe.selectedfiles.count; rowI++) {
    var file = pdfe.selectedfiles(rowI);
    pdfe.echo(file.filename);
    var CalculatedIndex = 0;
    for (var columnI = 0; columnI < Columns.length; columnI++)
    if (Columns[columnI]) {
        if (Columns[columnI] > ColumnNames.length) {
            pdfe.echo('    ' + FieldsInfo(Columns[columnI] - 9).Caption + ' : ' + MetadataFromColmunIndex(file, Columns[columnI]));
        } else if (Columns[columnI] < 0) {
            pdfe.echo('    ' + 'Dynamic calculated' + ' : ' + MetadataFromColmunIndex(file, --CalculatedIndex));
        } else {
            pdfe.echo('    ' + ColumnNames[Columns[columnI] - 1] + ' : ' + MetadataFromColmunIndex(file, Columns[columnI]));
        }
    }
}

function MetadataFromColmunIndex(fileobj, index) {
    if (index < 0) {
        return fileobj.metadata.Calculated(Math.abs(index))
    } else switch (parseInt(index)) {
    case 1:
        return fileobj.filename.substr(fileobj.filename.lastIndexOf('\\') + 1);
    case 2:
        return fileobj.filename.substr(0, fileobj.filename.lastIndexOf('\\'));
    case 3:
    case 4:
        return "";
    case 5:
        return fileobj.FileSize
    case 6:
        return fileobj.DateLastModified;
    case 15:
        return fileobj.NumPages;
    case 16:
        return fileobj.metadata.version
    case 17:
        return fileobj.metadata.EncryptLevel
    case 18:
        {
            var archive = fileobj.filename.match("<(.*?)>");
            if (archive) {
                return archive[1].substr(archive[1].lastIndexOf('.'))
            } else return '';
        }
    default:
        {
            if (index < 14) {
                return fileobj.metadata(index - 7)
            } else if (index > 18) {
                return fileobj.MetaData.Custom(index - 18)
            }
        }
    }
}

function VB2JSArray(objVBArray) {
    return new VBArray(objVBArray).toArray();

}

--- End code ---

--- Quote ---P.S. try editing current grid layout while having deleted all custom fields ;) here be dragons.

--- End quote ---
This one was ugly! Shame on me  :-[

Padanges:

--- Quote ---The VBScript engine implements the InputBox and MsgBox (this one also directly available from pdfe.MessageBox) methods and here is a nice trick to make these available from JScript too.
--- End quote ---
I've been using and occasionally modifying this code for a while now, but I haven't found out how to change/remove the (msgbox/edit) window icon in the upper left corner. I think it should be dependent on the main app (icon set) which is our PDFe. Maybe you have had tried to sort this out?

RTT:
Probably not possible without WinAPI function calls, something not readily available from COM automation scripts.

Navigation

[0] Message Index

[*] Previous page

Reply

Go to full version