View previous topic :: View next topic |
Author |
Message |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Wed Aug 29, 2007 11:48 pm Post subject: COM usage with Illustrator |
|
|
Greetings.
I have a bunch of scripts that I am converting to D. Here is a simple JScript that counts the frames in an Illustrator .eps file:
Code: |
var app = WScript.CreateObject("Illustrator.Application.3");
var doc = app.Open("myfile.eps");
var textFrames = doc.TextFrames;
var textFramesCount = textFrames.Count;
WScript.Echo(textFramesCount);
|
I have taken the same program and created a D program using Juno and following some of the examples in the dsource site for juno. Here is my code:
Code: |
import juno.com.core, juno.com.client;
import std.stdio;
void main()
{
//var app = WScript.CreateObject("Illustrator.Application.3");
scope auto app = new DispatchObject("Illustrator.Application.3");
//var doc = app.Open("myfile.eps");
scope auto doc = app.call("Open", "myfile.eps");
//var textFrames = doc.TextFrames;
scope auto textFrames = doc.get("TextFrames");
//var textFramesCount = textFrames.Count;
int textFramesCount = textFrames.get("Count");
//WScript.Echo(textFramesCount);
writefln(textFramesCount);
//Cleanup
textFrames.release();
doc.release();
app.release();
} |
Here is what I get when I compile it with D v1.020:
Quote: | AICOMtest.d(13): template juno.com.core.VARIANT.get(T) does not match any template declaration
AICOMtest.d(13): template juno.com.core.VARIANT.get(T) cannot deduce template function from argument types (char[10u])
AICOMtest.d(16): Error: no property 'get' for type 'int'
AICOMtest.d(16): Error: function expected before (), not 1 of type int
AICOMtest.d(22): Error: no property 'release' for type 'int'
AICOMtest.d(22): Error: function expected before (), not 1 of type int
AICOMtest.d(23): Error: no property 'release' for type 'VARIANT'
AICOMtest.d(23): Error: function expected before (), not 1 of type int
|
I know I am doing something wrong, but what is it? Any help would be greatly appreciated. I am using juno v0.3
thanks,
jic |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
John
Joined: 17 Jan 2006 Posts: 75
|
Posted: Thu Aug 30, 2007 1:36 am Post subject: |
|
|
textFrames is actually a VARIANT, which is why you get the errors about 'get' and 'release'.
Code: |
scope textFrames = new DispatchObject(doc.get("TextFrames"));
int textFramesCount = com_cast!(int)(textFrames.get("Count"));
|
(Also, if you apply 'scope' to a variable, 'release' will automatically get called.) |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Thu Aug 30, 2007 10:05 am Post subject: |
|
|
Thanks John.
Ok, so here is my new program: Code: | import juno.com.core, juno.com.client;
import std.stdio;
void main()
{
//var app = WScript.CreateObject("Illustrator.Application.3");
scope app = new DispatchObject("Illustrator.Application.3");
//var doc = app.Open("myfile.eps");
scope doc = app.call("Open", "myfile.eps");
//var textFrames = doc.TextFrames;
scope textFrames = new DispatchObject(doc.get("TextFrames"));
//var textFramesCount = textFrames.Count;
int textFramesCount = com_cast!(int)(textFrames.get("Count"));
//WScript.Echo(textFramesCount);
writefln(textFramesCount);
//Cleanup
//textFrames.release();
//doc.release();
//app.release();
} |
but here is what I get from the build, Quote: | AICOMtest.d(13): template juno.com.core.VARIANT.get(T) does not match any template declaration
AICOMtest.d(13): template juno.com.core.VARIANT.get(T) cannot deduce template function from argument types (char[10u])
AICOMtest.d(13): constructor juno.com.client.DispatchObject.this (char[]) does not match parameter types (int)
AICOMtest.d(13): class juno.com.client.DispatchObject member this is not accessible
AICOMtest.d(13): Error: cannot implicitly convert expression ((doc.get(T))("TextFrames")) of type int to juno.com.core.IDispatch |
Illustrator's Scripting Reference has the example as,
doc.TextFrames.Count
but I broke it down in pieces to make this work. Don't know if it is different or not.
Any ideas?
thanks,
jose |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
John
Joined: 17 Jan 2006 Posts: 75
|
Posted: Thu Aug 30, 2007 4:21 pm Post subject: |
|
|
OK - your 'doc' instance is a VARIANT too. DispatchObject's 'call' and 'get' methods both return a VARIANT. Try this:
Code: |
scope doc = new DispatchObject(app.call("Open", "myfile.eps"));
|
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Thu Aug 30, 2007 11:45 pm Post subject: |
|
|
thanks.
this is the new program now: Code: | import juno.com.core, juno.com.client;
import std.stdio;
void main()
{
//var app = WScript.CreateObject("Illustrator.Application.3");
scope app = new DispatchObject("Illustrator.Application.3");
//var doc = app.Open("myfile.eps");
scope doc = app.call("Open", "c:\\myfile.eps");
//var textFrames = doc.TextFrames;
scope textFrames = new DispatchObject(doc.get("TextFrames"));
//var textFramesCount = textFrames.Count;
int textFramesCount = com_cast!(int)(app.get("Documents","Count"));
//WScript.Echo(textFramesCount);
writefln(textFramesCount);
//app.call("Quit");
//Cleanup
//textFrames.release();
//doc.release();
//app.release();
} |
with the following compile errors: Quote: | AICOMtest.d(10): constructor juno.com.client.DispatchObject.this (char[]) does not match parameter types (VARIANT )
AICOMtest.d(10): class juno.com.client.DispatchObject member this is not accessible
AICOMtest.d(10): Error: cannot implicitly convert expression ((app.call)((& D13TypeInfo_B2Aa6__initZ),"Open","myfile.eps")) of type VARIANT to juno.com.core.IDispatch |
However, this program works: Code: | import juno.com.core, juno.com.client;
import std.stdio;
void main()
{
//var app = WScript.CreateObject("Illustrator.Application.3");
scope app = new DispatchObject("Illustrator.Application.3");
//var doc = app.Open("myfile.eps");
scope doc = app.call("Open", "c:\\myfile.eps");
} |
I can also use app.call("Quit") and it closes Illustrator, but I can not use doc.call("Close") which should close the opened EPS. So, somehow I can execute any head or top object, but not any sub-object.
Any ideas? ![Smile](images/smiles/icon_smile.gif) |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Thu Aug 30, 2007 11:54 pm Post subject: |
|
|
Sorry... this is the new program with the edition of John's suggestion: Code: | import juno.com.core, juno.com.client;
import std.stdio;
void main()
{
//var app = WScript.CreateObject("Illustrator.Application.3");
scope app = new DispatchObject("Illustrator.Application.3");
//var doc = app.Open("myfile.eps");
scope doc = new DispatchObject(app.call("Open", "myfile.eps"));
//var textFrames = doc.TextFrames;
scope textFrames = new DispatchObject(doc.get("TextFrames"));
//var textFramesCount = textFrames.Count;
int textFramesCount = com_cast!(int)(textFrames.get("Count"));
//WScript.Echo(textFramesCount);
writefln(textFramesCount);
//Cleanup
//textFrames.release();
//doc.release();
//app.release();
} |
and gives this error: Quote: | AICOMtest.d(10): constructor juno.com.client.DispatchObject.this (char[]) does not match parameter types (VARIANT )
AICOMtest.d(10): class juno.com.client.DispatchObject member this is not accessible
AICOMtest.d(10): Error: cannot implicitly convert expression ((app.call)((& D13TypeInfo_B2Aa6__initZ),"Open","myfile.eps")) of type VARIANT to juno.com.core.IDispatch |
Sorry about that. I was playing with some changes while looking at the COM object with a python COM browser and I was not able to get anything from it.
Any help would be greatly appreciated.
thanks,
jose |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
John
Joined: 17 Jan 2006 Posts: 75
|
Posted: Fri Aug 31, 2007 1:49 am Post subject: |
|
|
My fault - I changed the syntax for attaching to a VARIANT but forgot to upload the change! Sorry about that.
Download Juno 0.3 again and your code should work.
BTW, you can also do this, which does the com_cast step for you (and looks a bit cleaner):
Code: |
int textFramesCount = textFrames.get!(int)("Count");
|
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Fri Aug 31, 2007 8:40 am Post subject: |
|
|
Thanks John. After a few tries with downloading 0.3, it would still not work. And so I said, maybe he meant 0.3.5 and I downloaded it and TA-DAAAAH! It works. Here is the program now, for completion of thread:
Code: | import juno.com.core, juno.com.client;
import std.stdio;
void main()
{
//var app = WScript.CreateObject("Illustrator.Application.3");
scope app = new DispatchObject("Illustrator.Application.3");
//var doc = app.Open("myfile.eps");
scope doc = new DispatchObject(app.call("Open", "c:\\myfile.eps"));
//var textFrames = doc.TextFrames;
scope textFrames = new DispatchObject(doc.get("TextFrames"));
//var textFramesCount = textFrames.Count;
int textFramesCount = textFrames.get!(int)("Count");
//WScript.Echo(textFramesCount);
writefln(textFramesCount);
doc.call("Close", 2);
//Cleanup
app.call("Quit");
} |
Muchas gracias. And as a funny talking person once said, "I'll be back."
jose |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|