Pass vbscript variables to javascript string
Copy link to clipboard
Copied
Thx to this forum I can now save AI docs as a TIFF using JavaScript. With full paths I can run my script with no issues. Now I need to replace full paths with variables. So far no luck from what I have tried. How does one insert variables into a JS being executed inside a vbscript? Below is my latest attempt.
Also, according to the Illustrator reference guide one must run the JS code as a string when inside vbscript. No problem but that makes for one very-very long, single line JS. For "bonus points" , how does break that down the JS into a multi-line string? My various attempts have failed. Issue may have to do it while running inside a vbscript?
Set App = CreateObject("Illustrator.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim SourceFolder, DestFolder, NewState, NewSection
Call GetNewInputs()
Sub GetNewInputs()
NewState = UCase(InputBox("Current STATE or REGION to be processed.", _
"STATE or REGION", "SOCAL"))
NewSection = ("Section_" & InputBox("INPUT SECTION NUMBER: Section_YY", _
"Input Section", "32"))
Set SourceFolder = FSO.GetFolder("S:\" & NewState & "\" & NewSection & "\Road DXFs")
DestFolder = "S:\" & NewState & "\" & NewSection & "\Light TIFFs\"
End Sub
' now for the JS
App.DoJavaScript("function test(){var doc = app.activeDocument;var destFile = new File(""/s/" + <%=NewState%> + "/" + <%=NewSection%> + "/Light TIFFs/SOCAL_CN68_resx.tif"");var type = ExportType.TIFF;var opts = new ExportOptionsTIFF();opts.imageColorSpace=ImageColorSpace.GrayScale;opts.resolution=72;opts.antiAliasing=AntiAliasingMethod.ARTOPTIMIZED;opts.IZWCompression=false;opts.saveMultipleArtboards=true;opts.artboardRange=""1"";doc.exportFile(destFile, type, opts);}test();")
MyDoc.Close(2)
Explore related tutorials & articles
Copy link to clipboard
Copied
I thought the <% %> tags were for .asp web pages? Well, I think you can just put in your VB variables with the proper VB concatenation symbol (isn't it an & ?) and as far as your long javascript, I'd expect the underscore return method to work with splitting a long VB string of javascript.
Copy link to clipboard
Copied
Yea, that's what I originally tried and UI was not getting an error but the AI Window would open asking where to save it (which means it was not finding the path correctly). But I went back again just for laughs to the original '& xxx &' method and this time it works! Oh well, must had some blank space or syntax out-a-whack.

