Copy link to clipboard
Copied
Anyone know how to do this?
$.writeln('result:\r' + app.doScript('wsh.echo "test"', ScriptLanguage.VISUAL_BASIC));
Both wsh and wscript give an 'Object Required' error. Same script works fine as vbs file.
It sounds like those objects just aren't available when running from doScript, but is there some other way to return a value?
Justin Putney wrote:
Harbs. wrote:
FWIW, to return a value from VB using doScript, you need returnValue = SomeValue at the end of your VB script.
I know that's the case with a Sub or a Function...is that how it works at the end of a script as well?
To answer your questions, here's a working snippet I have which gets the current file from Excel:
...var vbs = 'Set MyXL = GetObject(, "Excel.Application")\r' +
'Set ActiveXL = MyXL.activeworkbook\r'+
'returnValue = ActiveXL.Path';
var path = app.
Copy link to clipboard
Copied
I remember struggling with a similar problem a long time ago, but I don't remember details.
Did you try GetObject()?
Harbs
Copy link to clipboard
Copied
FWIW, to return a value from VB using doScript, you need returnValue = SomeValue at the end of your VB script.
Copy link to clipboard
Copied
Harbs. wrote:
FWIW, to return a value from VB using doScript, you need returnValue = SomeValue at the end of your VB script.
I know that's the case with a Sub or a Function...is that how it works at the end of a script as well?
Harbs. wrote:
Did you try GetObject()?
Interesting. Hadn't heard of that before. I can't quite tell how it would apply from the documentation so far.
Copy link to clipboard
Copied
Justin Putney wrote:
Harbs. wrote:
FWIW, to return a value from VB using doScript, you need returnValue = SomeValue at the end of your VB script.
I know that's the case with a Sub or a Function...is that how it works at the end of a script as well?
To answer your questions, here's a working snippet I have which gets the current file from Excel:
var vbs = 'Set MyXL = GetObject(, "Excel.Application")\r' +
'Set ActiveXL = MyXL.activeworkbook\r'+
'returnValue = ActiveXL.Path';
var path = app.doScript(vbs,ScriptLanguage.VISUAL_BASIC);
Copy link to clipboard
Copied
Harbs. wrote:
Justin Putney wrote:
Harbs. wrote:
FWIW, to return a value from VB using doScript, you need returnValue = SomeValue at the end of your VB script.
I know that's the case with a Sub or a Function...is that how it works at the end of a script as well?
To answer your questions, here's a working snippet I have which gets the current file from Excel:
var vbs = 'Set MyXL = GetObject(, "Excel.Application")\r' + 'Set ActiveXL = MyXL.activeworkbook\r'+ 'returnValue = ActiveXL.Path'; var path = app.doScript(vbs,ScriptLanguage.VISUAL_BASIC);
Ah, I thought returnValue was a hypothetical, but it has to be exactly "returnValue". Thanks for the example, Harbs! Is that documented anywhere? I couldn't seem to find it.
Copy link to clipboard
Copied
Justin Putney wrote:
Ah, I thought returnValue was a hypothetical, but it has to be exactly "returnValue". Thanks for the example, Harbs! Is that documented anywhere? I couldn't seem to find it.
To tell you the truth, I do not remember where I got that from. It might have been trial and error. I do remember going crazy trying to figure it out...
Copy link to clipboard
Copied
I can imagine.
Thanks for sharing it!
Copy link to clipboard
Copied
it has to be returnValue !
thanks for sharing.
stole me also one hour #headbanging
Copy link to clipboard
Copied
Why isn't that documented?? In case someone doesn't figure out herself: Obviously returnValue needs to be declared inside the vbs, like
dim resultValue
Copy link to clipboard
Copied
It looks like this will work:
var scriptArr = [
'Set myInDesign = CreateObject("InDesign.Application")',
'myInDesign.insertLabel "myLabel", "text msg goes here" '];
app.doScript(scriptArr.join('\r'), ScriptLanguage.VISUAL_BASIC);
$.writeln('stored value: ' + app.extractLabel('myLabel'));
//result = stored value: text msg goes here
Run the vb code, set a script label there, then retrieve it in extendscript.
My only concern with this solution is the uncertainty about which version of InDesign the vbscript is targeting.
I'm going to look through the vbscript documentation to see if there's way to target a specific version of InDesign (didn't see it on first glance), but I'd welcome suggestions.
Copy link to clipboard
Copied
This seems to work just as well:
var scriptArr = [
'Set myInDesign = CreateObject("InDesign.Application")',
'myInDesign.ScriptArgs.SetValue "myLabel", "text msg goes here" '];
app.doScript(scriptArr.join('\r'), ScriptLanguage.VISUAL_BASIC);
$.writeln('stored value: ' + app.scriptArgs.getValue('myLabel'));
Still have the issue about targeting the exact version of InDesign (in case more than one version is open). The documentation says this will target the last version ID that was launched. It seems there's a way to use InDesign.Application.CS6, but I haven't found an equivalent for CC versions.
Copy link to clipboard
Copied
InDesign.Application.CS6
InDesign.Application.CC
InDesign.Application.CC.2014
InDesign.Application.CC.2015
And 'myInDesign.ScriptArgs.SetValue' is the proper way to go.
Copy link to clipboard
Copied
Perfect. Tested and it works on my end. Thanks, Vamitual!
Vamitul wrote:
InDesign.Application.CS6
InDesign.Application.CC
InDesign.Application.CC.2014
InDesign.Application.CC.2015
And 'myInDesign.ScriptArgs.SetValue' is the proper way to go.