is there is any way of adding method in existing photoshop object model
Some examples...
var ArtLayer = function () {}
ArtLayer.prototype.showOpacity = function() {
alert(this.opacity);
};
File.prototype.readByte = function() {//aka unsigned byte
return this.read(1).charCodeAt(0);
};
String.prototype.trim = function() {
return this.replace(/^[\s]+|[\s]+$/g, '');
};
Math.__proto__.randomFromTo = function(from, to){
return Math.floor(Math.random() * (to - from + 1) + from);
};
You have two options:
Paul,
Does the
var ArtLayer = function () {}
trick work with all PS DOM objects?
And how long has this worked? I have a pile of code that needs to be backwards compatible, some to CS2. Extending the PS DOM like this would
be nice and simplify a lot of my code, but I'd probably have give up supporting older versions of PS.
I put in a request for a
$.loadClass("Document");
sort of API that would have made extending the PS DOM a lot easier, but it never was implemented.
Sorry X, I haven't done much testing as I leave all the good stuff to you and Mike. I just play at it. It does work as far back as Photoshop CS3 but that is the earliest version I have on this machine. I will have to dust off the G4 laptop to test with earlier versions.
Not tried with other DOM objects yet.
Sorry X, I haven't done much testing as I leave all the good stuff to you and Mike. I just play at it.
You've been doing an excellent job at supporting the community whereas I've kinda drifted away for a bit. Thanks for picking up the slack
. I'm going to try to get more involved after CS6 gets released. If the DOM extension trick works for other classes (especially Document) I may overhaul xtools. I'm already planning on a massive update to CSX so I should be a bit more active here and on ps-scripts.com.
x & paul thanks for your posts.I am using a sample plugin given in photoshop sdk(filters->dissolve) it is scriptable & i am able to record its event.Now the problem is where to add extra functionality(in which function of plugin) say have to display anything like hello through a pop up or number of documents opened. Please help
I am not sure what you are asking for?
From the scripting side...
To display information you can use alert, confirm or create your own UI...
alert("There are " + app.documents.length + " document(s) open");
UI_Info();
function UI_Info(){
var win = new Window( 'dialog', 'test' );
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
var Info = "There are " + app.documents.length + " document(s) open";
win.title = win.g1.add('statictext',undefined,Info);
win.title.graphics.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.exit = win.p1.add('button',undefined,'Ok');
win.show()
}
But if you are wanting to display information automatically you would need to look at File - Scripts - Script Events Manager...
So that it would trigger a script/action when a certain event occurs.
thanks for trying to help,but this is not what i am looking for.
if you implement a plugin that is full compliant with the PS Automation Framework (i.e. your plugin can be recorded and played back in an Action) then you are all set. It will not technically let you extend the PS DOM, but you can add whatever functionality you need and call it via Action Manager code.
I need to do above mentioned task facing problem in determining in which method of plugin i add functionality.Functionality could be anything
thanks paul for replying.Things you mentioned like recording are taking place .I am using sample plugin provided in photoshop sdk.Code to play again event i am getting from script listener.Do you want to say the extra functionality i want to implement i implement into script file(i.e the code copied from script listener log file) that is playing the event?
Only you can answer your questions.
You need to ask yourself what you are trying to do, no one else can tell you.
If you are only useing a script to display extra information why are you using a plug-in?
If this is a task from a college/school and you do not understand, you need to go back and clarify exactly what they want.
North America
Europe, Middle East and Africa
Asia Pacific