FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COM usage with Illustrator

 
Post new topic   Reply to topic     Forum Index -> Juno
View previous topic :: View next topic  
Author Message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Wed Aug 29, 2007 11:48 pm    Post subject: COM usage with Illustrator Reply with quote

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
View user's profile Send private message
John



Joined: 17 Jan 2006
Posts: 75

PostPosted: Thu Aug 30, 2007 1:36 am    Post subject: Reply with quote

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
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Thu Aug 30, 2007 10:05 am    Post subject: Reply with quote

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
View user's profile Send private message
John



Joined: 17 Jan 2006
Posts: 75

PostPosted: Thu Aug 30, 2007 4:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Thu Aug 30, 2007 11:45 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Thu Aug 30, 2007 11:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
John



Joined: 17 Jan 2006
Posts: 75

PostPosted: Fri Aug 31, 2007 1:49 am    Post subject: Reply with quote

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
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Fri Aug 31, 2007 8:40 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Juno All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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