Rotation issues
-
- Mitglied
- Beiträge: 251
- Registriert: Sa 26 Jul 2014 10:13
- Wohnort: California
Rotation issues
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?
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?
-
- Entwickler
- Beiträge: 4171
- Registriert: Di 19 Nov 2002 15:49
Re: Rotation issues
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: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.
Fixing it using the UI works fine.russellcottrell hat geschrieben: ↑So 09 Dez 2018 21:39I tried running Fix Layer as an action; it resets the origin, but not the dimensions;
Can you send us a sample script?russellcottrell hat geschrieben: ↑So 09 Dez 2018 21:39and attempting to scale the layer after fixing it crashes PhotoLine.
Your way should work, but I will add a "Rotate" operation.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?
Martin
-
- Mitglied
- Beiträge: 251
- Registriert: Sa 26 Jul 2014 10:13
- Wohnort: California
Re: Rotation issues
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
-
- Entwickler
- Beiträge: 4171
- Registriert: Di 19 Nov 2002 15:49
Re: Rotation issues
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.russellcottrell hat geschrieben: ↑Mo 10 Dez 2018 15:41Code: Alles auswählen
(...) var fixLayer = "UGhvdG8gTGluZSBBY3Rpb25zAAAAAQAAAAABAP+bAAAAD0ZpeExheWVyQWN0aW9uAAIBAAAAAQAA" + "AAQAAAAB/////w=="; nLayer.DoOperation("Action", "Data", fixLayer); (...)
Adding
Code: Alles auswählen
nLayer = doc.ActiveLayer;
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);
Martin
-
- Mitglied
- Beiträge: 251
- Registriert: Sa 26 Jul 2014 10:13
- Wohnort: California
Re: Rotation issues
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.
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.
-
- Entwickler
- Beiträge: 4171
- Registriert: Di 19 Nov 2002 15:49
Re: Rotation issues
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 would have to say that at this point, the impermanence of layer objects is the biggest scripting hurdle.
I don't fully understand what you want to achieve, but a jagged array is hard to update after inserting/deleting a layer.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.
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
-
- Mitglied
- Beiträge: 251
- Registriert: Sa 26 Jul 2014 10:13
- Wohnort: California
Re: Rotation issues
Saves and restores layer objects before and after operations such as resize that remove them from the tree:
[Edited]
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);
}
}
Zuletzt geändert von russellcottrell am Fr 14 Dez 2018 18:16, insgesamt 2-mal geändert.
-
- Entwickler
- Beiträge: 4171
- Registriert: Di 19 Nov 2002 15:49
Re: Rotation issues
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
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
-
- Mitglied
- Beiträge: 251
- Registriert: Sa 26 Jul 2014 10:13
- Wohnort: California
Re: Rotation issues
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 understand what you are referring to . . . .I don't fully understand why you need that, though. There is no such code in PhotoLine.