Skip to main content
November 6, 2010
Question

Can we get the keys of a descriptor?

  • November 6, 2010
  • 1 reply
  • 1506 views

Can we get a list of the names of keys of a descriptor?

Also, how can we get the value of the global alitude?

This topic has been closed for replies.

1 reply

Inspiring
November 6, 2010

In xtools/xlib/stdlib,.js, there are these functions:

Stdlib.getDescriptorKeys = function(desc) {
  var keys = [];

  for (var i = 0; i < desc.count; i++) {
    keys.push(desc.getKey(i));
  }
  return keys;
};
Stdlib.getDescriptorKeySyms = function(desc) {
  var keys = [];

  for (var i = 0; i < desc.count; i++) {
    keys.push(id2char(desc.getKey(i), "Key"));
  }
  return keys;
};

Stdlib.getDescriptorKeyNames = function(desc) {
  var keys = [];

  for (var i = 0; i < desc.count; i++) {
    keys.push(PSConstants.reverseNameLookup(desc.getKey(i), "Key"));
  }
  return keys;
};

The function 'id2char' is also in stdlib.js. It converts the type ID back into either 4 byte character ID or string ID. The function 'PSConstants.reverseNameLookup' is from xtools/xlib/PSConstants.js. It maps character and string IDs into human readable strings.

Also, how can we get the value of the global alitude?

function getGlobalAltitude() {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };

  var ref = new ActionReference();
  ref.putEnumerated(cTID("capp"), cTID("Ordn"), cTID("Trgt") );
  var desc = executeActionGet(ref);
  if (desc.hasKey(cTID('gblA'))) {
    var angDesc = desc.getObjectValue(cTID('gblA'));
    if (angDesc.hasKey(sTID('globalAltitude'))) {
      return angDesc.getUnitDoubleValue(sTID('globalAltitude'));
    }
  }

  return undefined;
};

$.writeln(getGlobalAltitude());

November 8, 2010

Hello, thanks for your reply.

Actually, I would like to get the altitude of a document, not the application's.

Inspiring
November 8, 2010

'globalAltitude' or 'globalAngle' is an app wide setting like rulerUnits or foregroundcolor. It is not part of a document's descriptor. You can find it in a layer's descriptor but it returns the same value as the app key.

function getGlobalAngle() {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };

  var ref = new ActionReference();
  ref.putEnumerated(cTID("Lyr "), cTID("Ordn"), cTID("Trgt") );
  var desc = executeActionGet(ref);
  if (desc.hasKey(sTID('globalAngle'))) {
        return desc.getInteger(sTID('globalAngle'));
  }
  return undefined;
};