Rotation issues

Hier diskutieren die Betatester von PhotoLine untereinander und mit den Entwicklern
Antworten
Benutzeravatar
russellcottrell
Mitglied
Beiträge: 251
Registriert: Sa 26 Jul 2014 10:13
Wohnort: California
Kontaktdaten:

Rotation issues

Beitrag von russellcottrell »

Hello; I am having trouble after rotating a layer. I am using:

matrix = pl.GetRotationMatrix(90, [0, 0]);
nLayer.MatrixToPage = nLayer.MatrixToPage.Concatenate(matrix);

After rotation, the origin and dimensions of the layer are based on the layer before it was rotated, so resetting the origin puts it in the wrong place, and width and height seem to be reversed. I tried running Fix Layer as an action; it resets the origin, but not the dimensions; and attempting to scale the layer after fixing it crashes PhotoLine. Is there a way to rotate a layer so the rotated layer has the new origin and dimensions?
Martin Huber
Entwickler
Entwickler
Beiträge: 4159
Registriert: Di 19 Nov 2002 15:49

Re: Rotation issues

Beitrag von Martin Huber »

russellcottrell hat geschrieben: So 09 Dez 2018 21:39 Hello; I am having trouble after rotating a layer. I am using:

matrix = pl.GetRotationMatrix(90, [0, 0]);
nLayer.MatrixToPage = nLayer.MatrixToPage.Concatenate(matrix);

After rotation, the origin and dimensions of the layer are based on the layer before it was rotated, so resetting the origin puts it in the wrong place, and width and height seem to be reversed.
Yes, this just transforms the layer and is similar to entering a rotation angle in the Layer Attributes.
russellcottrell hat geschrieben: So 09 Dez 2018 21:39I tried running Fix Layer as an action; it resets the origin, but not the dimensions;
Fixing it using the UI works fine.
russellcottrell hat geschrieben: So 09 Dez 2018 21:39and attempting to scale the layer after fixing it crashes PhotoLine.
Can you send us a sample script?
russellcottrell hat geschrieben: So 09 Dez 2018 21:39Is there a way to rotate a layer so the rotated layer has the new origin and dimensions?
Your way should work, but I will add a "Rotate" operation.

Martin
Benutzeravatar
russellcottrell
Mitglied
Beiträge: 251
Registriert: Sa 26 Jul 2014 10:13
Wohnort: California
Kontaktdaten:

Re: Rotation issues

Beitrag von russellcottrell »

Code: Alles auswählen

var pl = new ActiveXObject("PhotoLine.Application");
var doc = pl.ActiveDocument;

var nLayer = new ActiveXObject("PhotoLine.Image");
nLayer.InitPicture(1, [50, 100], [1, 0, 0]);
nLayer.Origin = [0, 0];
doc.RootLayer.Insert(nLayer, -1);
doc.ActiveLayer = nLayer;

var matrix = pl.GetRotationMatrix(90, [0, 0]);
nLayer.MatrixToPage = nLayer.MatrixToPage.Concatenate(matrix);

var fixLayer = "UGhvdG8gTGluZSBBY3Rpb25zAAAAAQAAAAABAP+bAAAAD0ZpeExheWVyQWN0aW9uAAIBAAAAAQAA" +
  "AAQAAAAB/////w==";
nLayer.DoOperation("Action", "Data", fixLayer);

nLayer.Origin = [10, 10]; // <== this happens BEFORE fix layer!

//nLayer.DoOperation("Scale", "Mode", 3, "ValueX", 50, "Interpolation", 1); // <== crashes PhotoLine

var nLayerSize = VBArray(nLayer.Size).toArray();
var objShell = new ActiveXObject("WScript.Shell");
objShell.Popup(nLayerSize[0]); // <== this is 50 even though it says 100 in the layer panel
Martin Huber
Entwickler
Entwickler
Beiträge: 4159
Registriert: Di 19 Nov 2002 15:49

Re: Rotation issues

Beitrag von Martin Huber »

russellcottrell hat geschrieben: Mo 10 Dez 2018 15:41

Code: Alles auswählen

(...)
var fixLayer = "UGhvdG8gTGluZSBBY3Rpb25zAAAAAQAAAAABAP+bAAAAD0ZpeExheWVyQWN0aW9uAAIBAAAAAQAA" +
  "AAQAAAAB/////w==";
nLayer.DoOperation("Action", "Data", fixLayer);
(...)
That's the problem. The action will create a fixed layer and replace nLayer by that. After that, nLayer is no longer part of doc.
Adding

Code: Alles auswählen

nLayer = doc.ActiveLayer;
will fix that.

I will modify DoOperation() so that it returns a newly created layer if there is one, or the original layer if not.

This way, you will be able to write:

Code: Alles auswählen

nLayer = nLayer.DoOperation("Action", "Data", fixLayer);
Setting nLayer as the active layer at the beginning will then be superfluous, too.

Martin
Benutzeravatar
russellcottrell
Mitglied
Beiträge: 251
Registriert: Sa 26 Jul 2014 10:13
Wohnort: California
Kontaktdaten:

Re: Rotation issues

Beitrag von russellcottrell »

Thank you very much for the support.
I would have to say that at this point, the impermanence of layer objects is the biggest scripting hurdle. I was thinking of making a jagged array representing all the layers, children, etc. and keeping track of named layer objects by assigning them a series of numbers like 2,1,2 for their path through the tree; but keeping up with it during layer creation, merges, etc. would be quite daunting. I don’t know if there is some other way of hanging on to layer objects like this.
Martin Huber
Entwickler
Entwickler
Beiträge: 4159
Registriert: Di 19 Nov 2002 15:49

Re: Rotation issues

Beitrag von Martin Huber »

russellcottrell hat geschrieben: Mo 10 Dez 2018 20:56I would have to say that at this point, the impermanence of layer objects is the biggest scripting hurdle.
I understand that this is a problem, but there is no way around. In its core COM is strictly typed, so if a command changes the type of a layer, the object has to change, too.
russellcottrell hat geschrieben: Mo 10 Dez 2018 20:56I was thinking of making a jagged array representing all the layers, children, etc. and keeping track of named layer objects by assigning them a series of numbers like 2,1,2 for their path through the tree; but keeping up with it during layer creation, merges, etc. would be quite daunting. I don’t know if there is some other way of hanging on to layer objects like this.
I don't fully understand what you want to achieve, but a jagged array is hard to update after inserting/deleting a layer.
It's probably easier to just keep an array of object references and update that after converting a layer. Deleted layers are easily identified by checking their page. NULL means deleted.

Martin
Benutzeravatar
russellcottrell
Mitglied
Beiträge: 251
Registriert: Sa 26 Jul 2014 10:13
Wohnort: California
Kontaktdaten:

Re: Rotation issues

Beitrag von russellcottrell »

Saves and restores layer objects before and after operations such as resize that remove them from the tree:

Code: Alles auswählen

var pl = new ActiveXObject("PhotoLine.Application");
var doc = pl.ActiveDocument;
var docSize = VBArray(doc.Size).toArray();

var layerObjects = [];

var aLayer = doc.ActiveLayer; // select a layer with a parent
layerObjects.push(["aLayer", null]); // need to save the layer by its variable name

aLayer.Parent.Name = "Hello";

var bgLayer = doc.RootLayer.First;
layerObjects.push(["bgLayer", null]);

saveLayerObjects(); // need to do these before and after any operation that removes layer objects from the tree
doc.DoOperation("Resize", "Size", [docSize[0] + 100, docSize[1] + 100], "Horizontal", 2, "Vertical", 2);
restoreLayerObjects();

doc.ActiveLayer = bgLayer;

var objShell = new ActiveXObject("WScript.Shell");
objShell.Popup(aLayer.Parent.Name);



function saveLayerObjects() {
for (var i=0; i<layerObjects.length; i++) {

  var layer = eval(layerObjects[i][0]);

  if (layer.Page) { // layer still exists
    var pArray = [];
    while (layer != doc.RootLayer) {
      pArray.unshift(layer.Position); // builds the position of the layer in the tree
      layer = layer.Parent;
    }
    layerObjects[i][1] = pArray;
  }

  else
    layerObjects.splice(i, 1); // have to remove it if it does not exist

}
}



function restoreLayerObjects() {
for (var i=0; i<layerObjects.length; i++) {

  var layer = doc.RootLayer;
  var pArray = layerObjects[i][1];

  for (var j=0; j<pArray.length; j++) {
    layer = layer.Item(pArray[j]); // walk through the tree to get the layer
    if (!layer) // just in case
      break;
  }

  if (layer)
    eval(layerObjects[i][0] + " = layer"); // reassign the original layer object
  else
    layerObjects.splice(i, 1);

}
}
[Edited]
Zuletzt geändert von russellcottrell am Fr 14 Dez 2018 18:16, insgesamt 2-mal geändert.
Martin Huber
Entwickler
Entwickler
Beiträge: 4159
Registriert: Di 19 Nov 2002 15:49

Re: Rotation issues

Beitrag von Martin Huber »

In saveLayerObjects(), the "layer still exists"-condition is "layer.Page", because you could delete the parent (or any other ancestor) of a layer and thus implicitly delete the layer itself. In that situation it still has a parent, but no page.
And restoreLayerObjects() should have a check whether layer is becoming NULL in the for loop.

I don't fully understand why you need that, though. There is no such code in PhotoLine.

Martin
Benutzeravatar
russellcottrell
Mitglied
Beiträge: 251
Registriert: Sa 26 Jul 2014 10:13
Wohnort: California
Kontaktdaten:

Re: Rotation issues

Beitrag von russellcottrell »

That is a good tip about layer.Page. I did not check for null in restoreLayerObjects() because it is intended to be run after saveLayerObjects(), and everything should still be there. The only thing intervening should be resize, rotate, fix, etc. that removes all layers from the tree.
I don't fully understand why you need that, though. There is no such code in PhotoLine.
I don't understand what you are referring to . . . .
Antworten