Talking to inDesign server with ColdFusion

I was trying to connect to inDesign server with ColdFusion today, realize there are no code examples in CFM. There are php, java and other language examples in adobe site, but not CFM. This is not the first time I noticed that. When adobe released Spry framework before CF 8, Adobe labs most graciously released php and .net examples, but there were no CFM either. That makes me wonder, is ColdFusion, Adobe's most unfortunate step-child with all the goodness and sweet temper, forced to labor all day in the dark cold kitchen behind the house, while her two sisters playing in the living room wearing pretty dressers all day and attend to most gorgeous balls at night, while coldfusion sat all alone on kitchen cinders with tears in her eyes.

Whatever the reason it may be, connecting to inDesign server with cfm is pretty easy anyway. All you have to do is, connect to inDesign server's WSDL interface. In this example, I'm using cfobject to connect to my inDesign server running in port 18380

Now the next step is build up the SOAP request envelop and send it to runScript() function. With ColdFution, it is as simple as providing correct variable names.

   1: <cfobject
   2:     name         = "ind"
   3:     webservice = "http://myserver:18383/service?wsdl"
   4:     type            = "webservice">
   5: <cfset RunScriptParameters    = StructNew()>
Show/Hide Line Numbers . Full Screen . Plain

We can provide the path to our inDesign script file

   1: <cfset RunScriptParameters.scriptFile    = "D:\dev\warehouse\1.jsx">

or we can provide inDesign script as a string

   1: <cfset RunScriptParameters.scriptText = "my inDesign script goes here...">
We have to tell inDesign, the script language we are using (javascript, applescript, visual basic)

   1: <cfset RunScriptParameters.scriptLanguage = "javascript">

If we want, we can send as many as variables you want from ColdFusion in to inDesign in a arrays (or completely ignore this part). Let's send two variables.

   1: <cfset RunScriptParameters.scriptArgs = ArrayNew(1)>
   2: <cfset arg.name = "arg1">
   3: <cfset arg.value= "Elephant">
   4: <cfset ArraySet(RunScriptParameters.scriptArgs,1,1,arg)>
   5: <cfset arg.name = "arg2">
   6: <cfset arg.value= "Salamander">
   7: <cfset ArraySet(RunScriptParameters.scriptArgs,2,2,arg)>
Show/Hide Line Numbers . Full Screen . Plain
and inside inDesign script, we can grab these variables using value = app.scriptArgs.getValue("arg1") and the value will be "Elephant" and value for app.scriptArgs.getValue("arg2") will be "Salamander".

Now we are ready to call runScript()

   1: <cfset ind.runScript(RunScriptParameters,"errornumber","errorfeedback", result)>

as you can see, there are 3 additional parameters I"m using in here.

errornumber  : This is a response variable name for, in any unfortunate case of an error in our inDesign script, for it to output error number in to.

errorfeedback : Same like above. This is for output error details.

result : This is the return value from inDesign script. Usually the last variable in the JavaScript inDesign script.

Here is everything together :

   1: <cfset RunScriptParameters=StructNew()>
   2: <cfset RunScriptParameters.scriptFile    = "D:\dev\warehouse\1.jsx">
   3: <cfset RunScriptParameters.scriptLanguage = "javascript">
   4: <cfset RunScriptParameters.scriptArgs = ArrayNew(1)>
   5: <cfset arg.name = "arg1">
   6: <cfset arg.value= "Elephant">
   7: <cfset ArraySet(RunScriptParameters.scriptArgs,1,1,arg)>
   8: <cfset arg.name = "arg2">
   9: <cfset arg.value= "Salamander">
  10: <cfset ArraySet(RunScriptParameters.scriptArgs,2,2,arg)>
  11: <cfobject
  12:     name = "ind"
  13:     webservice = "http://myserver:18383/service?wsdl"
  14:     type = "webservice">
  15: <cfset ind.runScript(RunScriptParameters,"errornumber","errorfeedback","result")>
  16: Result : <cfoutput>#result.getData()#</cfoutput><br />
  17: <cfif IsDefined("errorfeedback")>
  18: <cfoutput>
  19:     Error #errornumber# : #errorfeedback#
  20: </cfoutput>
  21: </cfif>
Show/Hide Line Numbers . Full Screen . Plain

7 Comments :
Sunday 07 December 2014 11:43 PM
The steps you've laid out look easy enough. Firewall, yes that looks like a viable solution, whenever you see connection refused, that's typically a tell tell sign.
Monday 15 September 2014 07:41 AM
I must appreciate the owner of this blog for collecting and sharing the rare and important script coding with us. I've almost visited all the pages of this blog and found very precious coding all over. Sites like these help many workers and students to learn about this. and the way you explained is so cool that every one can easily understand. Me, working at toronto seo company, collected many scripts from here. Thanks again for the share mate. Keep posting. Have a great day!
Nav
Monday 07 November 2011 12:29 PM
Sorry.. forgot to attach the entire error message:

The fault returned when invoking the web service operation is:

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Connection refused
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:149)
at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:120)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:190)
... ''


Any help would be appreciated.

Thanks
Nav
Monday 07 November 2011 12:13 PM
Thanks for this post. It really helped. But i am having a issue, i get this error: Cannot perform web service invocation runScript

Would you know what i'm doing wrong ?

Thanks.
Monday 07 November 2011 01:36 PM
This bit [http://myserver:18383/service?wsdl] Make sure that's running and accessible. Few things can happen. The port 18383 (that’s im using in here. you can use a deferent port) is blocked by the firewall. Or The indesign is running on a totally deferent port.
Wednesday 14 April 2010 09:36 AM
Exactly what I needed! Thanks. I agree about CF being Adobe's unfortunate Cinderella.
Friday 16 April 2010 07:42 PM
Glad to know that helps!