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

DoScript CS3 VB to VB

New Here ,
May 14, 2008 May 14, 2008
Can you give me an example (both for the script sending the parameters and for the script receiving the parameters) of using the DoScript command in VBscript to call another VBscript?

For an example, I need 16 scripts to do the same thing, the only difference is three parameters, myGroupCode, myTemplateForm and myPrintPercent.

The name of the 16 scripts will be the group code, (example CI.vbs, CO.vbs, etc.) They will contain the 3 parameters and each will call a script called CreateBatch.vbs (it displays a dialog to input the batch number, open the template, places the tagged text file, etc.)

Thanks,
Archie
TOPICS
Scripting
3.2K
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 ,
May 14, 2008 May 14, 2008
Hi Archie,

Here's an example:

Set myInDesign = CreateObject("InDesign.Application.CS3")
myVBScript = "myResult = msgbox(arguments(0), vbYesNo , arguments(1))" & vbCr
myVBScript = myVBScript & "If myResult = 6 Then" & vbCr
myVBScript = myVBScript & "myResult = ""Yes""" & vbCr
myVBScript = myVBScript & "Else" & vbCr
myVBScript = myVBScript & "myResult = ""No""" & vbCr
myVBScript = myVBScript & "End IF" & vbCr
myVBScript = myVBScript & "Set myInDesign = CreateObject(""InDesign.Application.CS3"")" & vbcr
myVBScript = myVBScript & "myInDesign.scriptArgs.SetValue ""Result"", myResult" & vbcr
myInDesign.DoScript myVBScript, idScriptLanguage.idVisualBasic, Array("Hello from DoScript", "Your message here.")
MsgBox "User clicked: " & myInDesign.ScriptArgs.GetValue("Result")

In theory, we're supposed to be able to get values back from a script run using DoScript directly, but I couldn't get it to work, so I used ScriptArgs.

Thanks,

Ole
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 ,
May 14, 2008 May 14, 2008
Thank you for your quick reply.

Sorry, but I'm still having a problem understanding this, or maybe the DoScript command doesn't function like think. I'm a business basic programmer, and I'm trying to relate this to that. With business basic you have one program call another using a call command, like CALL "PROGRAM_NAME",A$,B$,C$ and the program you call (the public program, like to select a printer) has a command like ENTER A$,B$,C$

So, if I have a script named PI.vbs calling CreateBatch.vbs with three variables named myGroupCode, myTemplateForm and myPrintPercent what would the section of code look like in PI.vbs & CreateBatch.vbs? In my case I don't need any info returned back to PI.vbs.

Thanks,
Archie
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 ,
May 14, 2008 May 14, 2008
Hi Archie,

It's the same thing, whether you use a script file or a string. The start of CreateBatch.vbs would look like this:

myGroupCode = arguments(0)
myTemplateForm = arguments(1)
myPrintPercent = arguments(2)

When you call CreateBatch from PI.vbs, the line would look like this:

Rem You'll have to fill in your own file path for CreateBatch.
Rem This assumes that you've already defined myGroupCode, myTemplateForm,
Rem and myPrintPercent.
myInDesign.DoScript "c:\CreateBatch.vbs", idScriptLanguage.idVisualBasic, Array(myGroupCode, myTemplateForm, myPrintPercent)

Thanks,

Ole
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
Community Beginner ,
May 14, 2008 May 14, 2008
hi Archie,

because you build script from scratch - you can insert arguments in script's code:

...
start = 5
stop = 10
...
myScript = myScript + "for a="+CStr(start)+" to " + CStr(stop)+vbcr
myScript = myScript + " myTF.Contents=CStr(a)" + vbcr
myScript = myScript + "next" + vbcr
...

so when script will be executed - it will looks like:

...
for a=5 to 10
myTF.Contents=CStr(a)
next
...

and in case you want to retrieve/return some values from compiled script - use .InsertLabel and .ExtractLabel

...
myScript = myScript + "myDocA.InsertLabel(""ResultA"",a)" + vbcr
...
ResultA = myDocB.ExtractLabel("ResultA")
...

where:
- myDocA is reference in compiled script
- myDocB is reference in main script

I hope this helps :)

robin

--
www.adobescripts.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 ,
May 14, 2008 May 14, 2008
Hi Archie, Robin,

Jonathan just reminded me--if you use a variable named "returnValue," you can send a value back to the original script (no need for ScriptArgs). So:

Set myInDesign = CreateObject("InDesign.Application.CS3")
myVBScript = "returnValue = msgbox(arguments(0), vbYesNo , arguments(1))" & vbCr
myResult = myInDesign.DoScript(myVBScript, idScriptLanguage.idVisualBasic, Array("Hello from DoScript", "Your message here."))
MsgBox "User clicked: " & myResult

Thanks,

Ole
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 ,
May 14, 2008 May 14, 2008
Great! That worked, I didn't need to return values. Just one more question, I hope. Below is the code for the program that calls CreateBatch.vbs. It there any good way to avoid having the path hard coded for CreateBatch.vbs?

Rem PI Script

Rem SCRIPT INFO
Rem -----------

Rem Description:
Rem Call CreateBatch.vbs

Rem SET VALUES
Rem ----------

Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.CS3")

Set FileSys = CreateObject("Scripting.FileSystemObject")

myGroupCode = "PI"
myTemplateForm = "SI_Page"
myPrintPercent = "100"

Rem CALL CREATEBATCH SCRIPT
Rem -----------------------

myInDesign.DoScript "C:\Program Files\Adobe\Adobe InDesign CS3\Scripts\Scripts Panel\CreateBatch.vbs",
idScriptLanguage.idVisualBasic, Array(myGroupCode,myTemplateForm,myPrintPercent)
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 ,
May 14, 2008 May 14, 2008
Hi Archie,

Sure. The Application object contains the property ActiveScript, which contains the path to the current script. So you can use the FileSystemObject to find other scripts relative to the VBScript.

Take a look at the myFindFile and myGetFileName functions in the FindChangeByList.vbs example script (it's installed by default with InDesign CS3). They show how to get a script or support file of a given name relative to the executing script.

Thanks,

Ole
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 ,
Aug 11, 2008 Aug 11, 2008
Hi Olav,
I have been using the DoScript command with great success with your help, but now I need to use the command to return parameters. I looked thru the prior emails and I still have not been able to understand how I would get the return value. Below is the section of code for the DoScript command. How would I get the values for myLabelPrinter, myManuscriptPrinter and myBatchFolder?
Thanks,
Archie

Rem DOSCRIPT ROUTINE
Rem ----------------

myMountLetter = "N"
myMountSize = "12"

myActiveScript = myInDesign.ActiveScript
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
myScriptPath = myFileSystemObject.GetFile(myActiveScript).ParentFolder.Path
myDoScript = myScriptPath + "\zLabelParameters.vbs"

myInDesign.DoScript myDoScript, idScriptLanguage.idVisualBasic, Array

(myMountLetter,myMountSize,myLabelPrinter,myManuscriptPrinter,myBatchFolder)
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
Community Beginner ,
Aug 11, 2008 Aug 11, 2008
instead of:

myInDesign.DoScript myDoScript, idScriptLanguage.idVisualBasic, Array

you need to write:

myResult = myInDesign.DoScript(myDoScript, idScriptLanguage.idVisualBasic, Array)

and in body (for example at end) of script you call:

returnValue = myTextFrame.Contents ' only example

robin

--
www.adobescripts.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
New Here ,
Aug 11, 2008 Aug 11, 2008
Thanks, I made the changes below and added returnValue = myLabelPrinter to the script zLabelParameters.vbs and that worked, but what if I need to return more than one varible?
Thanks,
Archie

Rem DOSCRIPT ROUTINE
Rem ----------------

myActiveScript = myInDesign.ActiveScript
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
myScriptPath = myFileSystemObject.GetFile(myActiveScript).ParentFolder.Path
myDoScript = myScriptPath + "\zLabelParameters.vbs"

myResult = myInDesign.DoScript(myDoScript, idScriptLanguage.idVisualBasic, Array

(myMountLetter,myMountSize,myLabelPrinter,myManuscriptPrinter,myBatchFolder))

MsgBox "myLabelPrinter=" & myResult
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
Community Beginner ,
Aug 11, 2008 Aug 11, 2008
it's easy 🙂 convert to text (numeric expressions) and join with TAB - and split ;)

in sub-script:

returnValue = CStr(res1) + vbTab + CStr(par2) + vbTab + CStr(par3)

in main-script:

Dim myRes as Variant
...
myResult = myInDesign.DoScript(...)

myRes = Split(myResult, vbTab)

and (if you don't set OPTION BASE 1):

myRes(0) <- res1
myRes(1) <- res2
myRes(2) <- res3

robin

--
www.adobescripts.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
New Here ,
Aug 11, 2008 Aug 11, 2008
Great! That worked. I'm listing the finished code to help anyone else that uses this post because I find code examples the best way to learn.
Thanks,
Archie

Rem DOSCRIPT ROUTINE
Rem ----------------

myActiveScript = myInDesign.ActiveScript
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
myScriptPath = myFileSystemObject.GetFile(myActiveScript).ParentFolder.Path
myDoScript = myScriptPath + "\zLabelParameters.vbs"

myResult = myInDesign.DoScript(myDoScript, idScriptLanguage.idVisualBasic, Array

(myMountLetter,myMountSize,myLabelPrinter,myManuscriptPrinter,myBatchFolder))

myResultArray = Split(myResult, vbTab)
myLabelPrinter = myResultArray(0)
myManuscriptPrinter = myResultArray(1)
myBatchFolder = myResultArray(2)

Line from zLabelParameters:
returnValue = cStr(myLabelPrinter) + vbTab + cStr(myManuscriptPrinter) + vbTab + cStr(myBatchFolder)
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 ,
Aug 15, 2008 Aug 15, 2008
Hi Robin,

How do you return array values using the DoScript command? Below is an example where myStampRows is an array.
Thanks,
Archie

myMountLetter = arguments(0)
myMountSize = arguments(1)
myMountNumber = arguments(2)
myLabelSize = arguments(3)
myStampCols = arguments(4)
myStampRows = arguments(5)

Rem SET VALUES
Rem ----------

Dim myStampRows(3)

If myMountLetter + myMountSize = "N10" Then
myMountNumber = 21
myLabelSize = "B"
myStampCols = 3
For I = 1 to 3
myStampsRows(I) = 7
Next
End If

Rem RETURN VALUES
Rem -------------
returnValue = cStr(myMountNumber) + vbTab + cStr(myLabelSize) + vbTab + cStr(myStampCols) + vbTab + cStr(myStampRows)
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
Community Beginner ,
Aug 16, 2008 Aug 16, 2008
you need to split array and add to "returnValue" - you should know what is the size of array ? ;)

if array size could be dynamic - add it as last argument - first you will read/decode known number of "regular" params - all remaing elements will be an array

robin

--
www.adobescripts.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
New Here ,
Aug 16, 2008 Aug 16, 2008
I was afraid you would say that. Below is the code I'm working to move to a DoScript. I will have over 30 different scripts so I'm trying to have one master script for all, then a doscript for the data. I will not need dynamic arrays, but as you can see below I will have a lot of values (the number of myStampCols could be as large as 8), is there a limit to the number of values passed? Also I'm getting an error on the Dim statement if I use a variable (see the 2nd line below) for the array number value, what am I doing wrong? Maybe I'm doing this the wrong way, only a few of the stamps sizes have a different value per column, but I thought using an array was the best solution.
Thanks again for all your help!
Archie

myStampCols = 2
Dim myStampRows(myStampCols)
Dim myStampStartX(3)
Dim myStampStartY(3)
Dim myStampWidth(3)
Dim myStampHeight(3)
Dim myStampHorizontalSpace(3)
Dim myStampVerticalSpace(3)
Dim myStampRotation(3)
For I = 1 to 2
If I = 1 Then
myStampRows(I) = 2
myStampStartX(I) = 52.035
myStampStartY(I) = 82.973
myStampWidth(I) = 38
myStampHeight(I) = 63
myStampHorizontalSpace(I) = 42.756
myStampVerticalSpace(I) = 67.997
myStampRotation(I) = -90
Else
myStampRows(I) = 3
myStampStartX(I) = 52.035
myStampStartY(I) = 91.211
myStampWidth(I) = 63
myStampHeight(I) = 38
myStampHorizontalSpace(I) = 42.756
myStampVerticalSpace(I) = 42.651
myStampRotation(I) = 0
End If
Next
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
Community Beginner ,
Aug 16, 2008 Aug 16, 2008
when you declare variable - bu using DIM - you need to specify number
if you need to change size of array - you need to use ReDim
when you join variables by converting to String - you build one item - string - but I don't know what is the limit of string passed as ReturnValue ;)

robin

--
www.adobescripts.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
Community Beginner ,
Aug 19, 2008 Aug 19, 2008
Archie, I don't entirely follow what you're doing, but if you're using a stand-alone VB app, it would probably be easier to automate InDesign directly through the VB app, than call VBSCripts within InDesign. Look at my recent post for an example of how I'm doing it, and if you have any questions, I'll see if I can help.
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 ,
Aug 19, 2008 Aug 19, 2008
I think I have it working now. I'm using the DoScript to store data. I'm not using VB, just VBscript. I got around the array issue by putting them in a string with the pipe character as a separator. Then I use the split command to put them into arrays. How would I look at your recent post?
Thanks,
Archie

If myMountLetter + myMountSize = "N16" Then
myMountNumber = "5"
myLabelSize = "A"
myLabelPercent =".48"
myStampCols = "2"
myStampRows = "0|2|3|"
myStampStartX = "0|52.035|52.035|"
myStampStartY = "0|82.973|91.211|"
myStampWidth = "0|38|63|"
myStampHeight = "0|63|38|"
myStampHorizontalSpace = "0|42.756|42.756|"
myStampVerticalSpace = "0|67.997|42.651|"
myStampRotation = "0|-90|0|"
End If

myResultArray = Split(myDoScriptResult, vbTab)
myMountNumber = myResultArray(0)
myLabelSize = myResultArray(1)
myLabelPercent = myResultArray(2)
myStampCols = cInt(myResultArray(3))
myStampRowsStr = myResultArray(4)
myStampStartXStr = myResultArray(5)
myStampStartYStr = myResultArray(6)
myStampWidthStr = myResultArray(7)
myStampHeightStr = myResultArray(8)
myStampHorizontalSpaceStr = myResultArray(9)
myStampVerticalSpaceStr = myResultArray(10)
myStampRotationStr = myResultArray(11)
myStampRows = Split(myStampRowsStr, "|")
myStampStartX = Split(myStampStartXStr, "|")
myStampStartY = Split(myStampStartYStr, "|")
myStampWidth = Split(myStampWidthStr, "|")
myStampHeight = Split(myStampHeightStr, "|")
myStampHorizontalSpace = Split(myStampHorizontalSpaceStr, "|")
myStampVerticalSpace = Split(myStampVerticalSpaceStr, "|")
myStampRotation = Split(myStampRotationStr, "|")
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
Community Beginner ,
Aug 21, 2008 Aug 21, 2008
LATEST
The subject of my post is "VB code for fitting graphics, deleting pages, updating TOC"
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