Skip navigation
vaibhav4444
Currently Being Moderated

is it possible to add method in existing photoshop object model?if yes then pls tell how to add?pls

Mar 15, 2012 4:10 AM

is there is any way of adding method in existing  photoshop object model

 
Replies
  • Currently Being Moderated
    Mar 15, 2012 5:00 AM   in reply to vaibhav4444

    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);
    };

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 5:50 AM   in reply to vaibhav4444

    You are in the wrong forum then, you should be here...

    http://forums.adobe.com/community/photoshop/photoshop_sdk

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 5:57 AM   in reply to vaibhav4444

    You have two options:

    1. Look at the 'Integrating External Libraries' section of the JS Tools guide. Last time I checked, it was lacking (to put it nicely). I've implemented large C extensions to TCL and perl projects in the past; doing the same with  PS/JS was far more difficult, so much so that I gave up.
    2. 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.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 6:04 AM   in reply to Paul Riggott

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 6:15 AM   in reply to xbytor2

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 6:49 AM   in reply to xbytor2

    Hey my G4 still works! At least the Artlayer example works with Photoshop CS2 and Photoshop CS, I haven't got Photoshop 7 on any machines so can't test that version.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 7:07 AM   in reply to Paul Riggott

    I haven't got Photoshop 7 on any machines so can't test that version.

     

    I have it sitting in a VM somewhere but I stopped supporting it a couple of years ago. It's where I learned PS/JS and wrote a lot of early code but I never want to go there again.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 7:17 AM   in reply to Paul Riggott

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 7:31 AM   in reply to xbytor2

    Thanks for that X.

    By the way this seems to work....

     

     

    var Document = function() {}
    Document.prototype.nameNoExt = function(){
        alert(this.name.replace(/\.[^\.]+$/, ''));
        }
    app.activeDocument.nameNoExt();
    
    
     
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 16, 2012 1:47 AM   in reply to vaibhav4444

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 16, 2012 2:34 AM   in reply to vaibhav4444

    This site may be of use to you as there is source code available for some of thier plug-ins...

     

    http://www.telegraphics.com.au/sw/

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 16, 2012 3:49 AM   in reply to vaibhav4444

    In that case you need to write your plug-in first.

    Examples at the above site.

     

    Once you have written your plug-in then test it and see if can be recorded in an action.

     

    Then you can use scriptListener to do what you want with the resulting code.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 16, 2012 4:41 AM   in reply to vaibhav4444

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points