Scripting user defined transform
-
csuebele
Scripting user defined transform
I'm trying to run a script that creates a vector layer in CS6 to be used as a guide to crop portraits. I need to be able to let the user to a transform to scale and position the guide layer. When I try to run the transform, I can't change anything. I did a search on this site for this topic, and it looks like Mike posted a few examples of how to bring up transform, but the all don't allow me to actually change anything.
-
Mike Hale
Scripting user defined transform
This is old and I can't test now but I found it in my code lib. It should allow the user to transform the activeLayer.
Code: Select allfunction transformLayer(){
try{
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt') );
desc.putReference( app.charIDToTypeID('null'), ref );
executeAction( app.charIDToTypeID('Trnf'), desc, DialogModes.ALL );
}catch(e){
if (e.toString().match(/User cancelled/)) {
return -1;
}else{
throw e;
}
}
};
Code: Select allfunction transformLayer(){
try{
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt') );
desc.putReference( app.charIDToTypeID('null'), ref );
executeAction( app.charIDToTypeID('Trnf'), desc, DialogModes.ALL );
}catch(e){
if (e.toString().match(/User cancelled/)) {
return -1;
}else{
throw e;
}
}
};
-
Mike Hale
Scripting user defined transform
And it maybe that you have to do the transform in the options bar instead of using a mouse.
-
csuebele
Scripting user defined transform
Mike, I had found that script earlier, and it didn't work. The menu bar was also locked up. I also posted this in the Adobe forums. Paul asked about calling it from the UI, but the UI was closed and the function was called after the vector layer was created. I'm wondering if this is a CS6 thing, as it seem you've been able to to this with other versions.
-
Mike Hale
Scripting user defined transform
I have had time to test now and it works on CS5. I also stopped by somewhere that has CS6 and it worked on their system( Win 7 home ed ).
So it doesn't look like an version issue.
So it doesn't look like an version issue.
-
csuebele
Scripting user defined transform
That's odd, I'll have to play with it some more Monday when I go back to work.
-
csuebele
Scripting user defined transform
I figured out what the issue was:
On the onClick function for my okay button, I closed the UI then ran a function to run the rest of the program. I guess this kept it in the UI mode or whatever locks up the transform. I changed it from calling the runProgram function to an if statement. That allowed the UI to fully close and not run the rest of the program if the user canceled.
On the onClick function for my okay button, I closed the UI then ran a function to run the rest of the program. I guess this kept it in the UI mode or whatever locks up the transform. I changed it from calling the runProgram function to an if statement. That allowed the UI to fully close and not run the rest of the program if the user canceled.
-
Mike Hale
Scripting user defined transform
I wouldn't think anything that allows user interaction with the GUI would work in a window callback. Because the dialog is modal, the script can't pass the command to the app because the script is also modal.
I guess as the name ScriptUI implies, windows were designed as a interface for the script not the app. In other words to get the info the script needs from the user. I also guess that is why Adobe created custom panels, for people that need/want to allow the user to use the app and/or respond to user actions.
I find that doing anything other than working with the windows controls, such as hiding/showing, has problems.
I guess as the name ScriptUI implies, windows were designed as a interface for the script not the app. In other words to get the info the script needs from the user. I also guess that is why Adobe created custom panels, for people that need/want to allow the user to use the app and/or respond to user actions.
I find that doing anything other than working with the windows controls, such as hiding/showing, has problems.
-
csuebele
Scripting user defined transform
Well, it's working now, so I'm happy. The script is still a bit clunky in that the user has to transform the guide layer to crop the portrait, and if they don't hold down the shift key, the aspect ratio of the crop changes. A better solution would be to be able to set custom guide lines in the actual crop box. I put in a request for this, but I'm not holding my breath to see if Adobe does anything with it.