Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Executing VBS from SQL Server Stored Procedure

$
0
0

The VBS script works outside of SQL server but not when executed from within a SQL Server Stored Procedure using this code:      

SET @VBSCommandLine ='cscript.exe C:\PrintLabels\TestVBS.vbs //H:CScript //Nologo'

 

 

 

 

 

 

EXEC master..xp_cmdshell @VBSCommandLine

 

The VBS code dies when it gets to the appRef.Open("C:\PrintLabels\PLT.ait") statement saying the the server has thrown an exception.

The VBS Script File

'PrintLabel.vbs
'This script opens an ai template, plays some actions to import two images, prints the file,
' and quits ai without saving the file
'
Wscript.echo("Before Illustrator")
Set appRef = CreateObject("Illustrator.Application.CS5.1")
Set fileSystemObject = CreateObject("Scripting.FileSystemObject")

'Suppresses user input
appRef.UserInteractionLevel = -1

' Open input doc
appRef.Open("C:\PrintLabels\PLT.ait")
Set docRef = appRef.ActiveDocument
inputFileName = docRef.Name
Wscript.echo("Before Place files")

'Places the files
set sDirName = "C:\PrintLabels\PSDFiles"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\PrintLabels\PSDFiles")
Set fls = fldr.Files

Dim fileNames(2)
i = 1
num = 0
Dim aFile
        For each aFile in fls
  ' Ignore system files. 
  If not aFile.attributes and 4 Then  
   num = num + 1
             fileNames(num) = CStr(aFile) 
  End If
        Next

dim imageLeft
dim imageTop
dim imageSize

' Place the first image
imageLeft = 18
imageTop = -423
imageSize = 5.0

Call AddRasterItemToPage(docRef, fileNames(1), imageLeft, imageTop, (imageSize) )

 

' Place the second image
imageLeft = 18
imageTop = -31
imageSize = 5.0

Call AddRasterItemToPage(docRef, fileNames(2), imageLeft, imageTop, (imageSize) )

myOutputFile = "C:\PrintLabels\TempAIFile\TempLabelAutoTest.ai"
docRef.SaveAS (myOutputFile)
Wscript.echo("After save file")

Set jobOptionsRef = CreateObject("Illustrator.PrintJobOptions")
Set printOpts = CreateObject("Illustrator.printOptions")


jobOptionsRef.Designation = 0 'aiVisiblePrintableLayers
jobOptionsRef.Copies = 1
printOpts.JobOptions = jobOptionsRef
printOpts.PrinterName = "OCIO-CapGal-4071A-1"
printOpts.PrintPreset = "3/4 Sticker Print"
Wscript.echo("Before print")
docRef.PrintOut printOpts

docRef.Close()
Set docRef = Nothing
Wscript.echo("just before exit")

'Exits Adobe Illustrator

appRef.Quit

Wscript.echo("just after exit")

' This routine adds all images in the folder as RasterItems
' to the Document

Sub AddRasterItemToPage(aDocument, theFile, imageLeft, imageTop, imageSize)
       
        ' Create a new raster item and link it to the image file
        Set aPlacedItem = aDocument.PlacedItems.Add
    aPlacedItem.File = theFile
       
       
        ' Move the raster item
        aPlacedItem.Position = Array(imageLeft,imageTop)
       
        Exit Sub

End Sub

 


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>