Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ExternalObject questions

Explorer ,
Jul 24, 2007 Jul 24, 2007
There doesn't appear to be an independent forum for using ESTK to extend CS3
apps, so I'll ask my questions here since the docs for ExternalObject were
bundled with Bridge.

1) I couldn't find any docs or sample code that would show me how to add class
methods and class properties. I can do instance methods/properties just fine.
Where's the docs for class methods/properties?

2) Once nice feature of JS is that you can dynamically add methods and
properties to (almost) any object. What is not clear is what is required to
support this behavior in SoObjectInterface.put/get/call. Do I just have those
callbacks ignore (return kESErrOK) or does something more need to be done?

-X
TOPICS
Scripting
908
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 24, 2007 Jul 24, 2007
1) Currently, there is no way to add class elements. If you decide to add some ExtendScript to your DLL, you may want to add class methods that wrap calls into your DLL.

2) I am afraid that I don't understand your question well enough. If you add JavaScript methods or properties to an ExternalObject instance, these elements will be visible to ExtendScript, but your DLL will not be called. I hope that I got my response right :)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 25, 2007 Jul 25, 2007
Michael_Daumling@adobeforums.com wrote:
> 1) Currently, there is no way to add class elements. If you decide to add some ExtendScript to your DLL, you may want to add class methods that wrap calls into your DLL.
So I could implement class methods as a bit of code that (in turn) makes a call
to a method defined on the external object. I guess I can live with that.
Hopefully the inability to do something similar for normal class variables (as
opposed to constants defined as class variable) won't be too much of a problem.

>
> 2) I am afraid that I don't understand your question well enough.

Let's say that I have defined a class via the ExternalObject framework called
XFile. The dll defines one property called 'name' and three methods called
'open', 'read', and 'close'.
Ex:
var f = new XFile();
f.name = "somename";
f.open();
var str = f.read();
f.close();
alert(str);

Now, let's say that in using this class in a script, I want to add new
properties and methods like this:
var f = new XFile();

f.readFromFile = function(fname) {
if (this.cachedName == fname && this.cachedStr) {
return this.cachedStr;
}
this.name = fname;
this.open();
var str = this.read();
this.close();
this.cachedStr = str;
this.cachedName = fname;
return str;
}

var str = f.readFromFile("somename");
alert(str);

Or like this:
XFile.prototype.readFromFile = function(fname) {
// etc....
}

var f = new XFile();
var str = f.readFromFile("somename");
alert(str);


Will my Call function be invoked when "readFromFile" is called? Will my Put and
Get functions be called when I access "cachedName" and "cachedStr"? If so, what
do I do?


There is also this problem. Assume we have the XFile class as originally
defined. Now, let's insert a shim function:

XFile.prototype._oldRead = XFile.prototype.read;
XFile.prototype.read = function() {
if (this.cachedStr) {
return this.cachedStr;
}
this.cachedStr = this._oldRead();
return this.cachedStr;
}

This is not an unreasonable thing to do and is actually quite necessary in cases
where built-in methods are busted (as Folder.getFiles() was in PS7).
Given the current definition of the ExternalObject framework, I don't see how my
Call function could be invoked with any expectation that the correct thing is
going to happen. There ultimately must be a way of defining a function/method
that corresponds to a single specific callback on the C/C++ side; going through
a centralized Call function will only work in the most rudimentary
situations/class definitions.


-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 25, 2007 Jul 25, 2007
BTW, what I am trying to do is implement a dll for xmd-sdk, ala XMPScript,
because the XMPScript dll that is provided only works for Bridge and ESTK2 as
far as I can tell. I kinda need the same capability in PS and ID.

The ExternalObject issues that I've come across are actually minor when compared
with the fact that I haven't even come close to getting a successful link of all
of the necessary parts.

-X
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 27, 2007 Jul 27, 2007
There isn't a way to create static methods/properties with the CClientLib interface. However CClientLib objects are generic and support the prototype mechanism.

The following will work, because the method readFromFile is local to the object f.

var f = new XFile();
f.readFromFile = function(fname) {
if (this.cachedName == fname && this.cachedStr) {
return this.cachedStr;
}
this.name = fname;
this.open();
var str = this.read();
this.close();
this.cachedStr = str;
this.cachedName = fname;
return str;
}


This will also work when you define readFromFile as a prototype method.


XFile.prototype.readFromFile = function(fname) {...}


And you can copy a method on an instance basis:


f.oldread = f.read ;
f.oldread() ; // does a call on f.read()


However if you cannot redefine a method/property of an object instance:


f.oldread = f.read ;
f.read = function() {
...
f.oldread() ;
}


f.read() remains tied to the ExternalObject. Attempting to use the prototype mechanism is equally ineffective:


XFile.prototype.read = function() { .... }


So the limitations are:



1) You can't define static methods/properties with the CClientLib interface. However you can define static methods on the DLL and call them.



Eg lib = new ExternalObject("lib:slslslsls") ;
lib.property = 'abc' ;
lib.method() ;


2) You can't redefine a property/method of a CClientLib object in JavaScript

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 29, 2007 Jul 29, 2007
LATEST
Robin_W_Mills@adobeforums.com wrote:
> There isn't a way to create static methods/properties with the CClientLib interface.

Ah, well. You can't have everything. But now that I've got a better idea what
the limitations are, I can work out ways around them.

Thanks for the info.

-X
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines