I have a vbscript that I use in Illustrator. In order to save my file as a TIFF I need to use JavaScript. With complete paths the JS script section works fine but when I try to change them to variables('NewState" and 'NewSection' via user input), it's a no go. Nubie to JS so how to insert those variables?
Here's is my latest attempt (FYI - in Illustrator, to use JS inside VBS one must execute it as a String as shown below).
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
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)
Related
I need to get the page number in order to extract text from that specific page in a .PDF document. I am using Excel VBA function that makes use of the JSObject from the Acrobat Type Library 10.0
Here is the code snippet and the code hicks up on when I am trying to reference the pageNum property from Doc object. I am trying to avoid the AV Layer and use the PD Layer only, so my macro runs in the background only and doesn't invoke Acrobat Application.
Function getTextFromPDF_JS(ByVal strFilename As String) As String
Dim pdDoc As New AcroPDDoc
Dim pdfPage As Acrobat.AcroPDPage
Dim pdfBookmark As Acrobat.AcroPDBookmark
Dim jso As Object
Dim BookMarkRoot As Object
Dim vBookmark As Variant
Dim objSelection As AcroPDTextSelect
Dim objHighlight As AcroHiliteList
Dim currPage As Integer
Dim strText As String
Dim BM_flag As Boolean
Dim count As Integer
Dim word As Variant
strText = ""
If (pdDoc.Open(strFilename)) Then
Set jso = pdDoc.GetJSObject
Set BookMarkRoot = jso.BookMarkRoot
vBookmark = jso.BookMarkRoot.Children
'Add a function call to see if a particular bookmark exists within the .PDF
Set pdfBookmark = CreateObject("AcroExch.PDBookmark")
BM_flag = pdfBookmark.GetByTitle(pdDoc, "Title Page")
If (BM_flag) Then
For i = 0 To UBound(vBookmark)
If vBookmark(i).Name = "Title Page" Then
vBookmark(i).Execute
jso.pageNum
Set pdfPage = pdDoc.AcquirePage(pageNum)
Set objHighlight = New AcroHiliteList
objHighlight.Add 0, 10000 ' Adjust this up if it's not getting all the text on the page
Set objSelection = pdfPage.CreatePageHilite(objHighlight)
If Not objSelection Is Nothing Then
For tCount = 0 To objSelection.GetNumText - 1
strText = strText & objSelection.GetText(tCount)
Next tCount
End If
Exit For
End If
pdDoc.Close
End If
End If
getTextFromPDF_JS = strText
End Function
jso.pageNum = 0; set a page number
pageNo = jso.pageNum; get a page number
edit: 3.3.19
Mmmh, it seems you have to work with AVDoc in order to get the current actual page via jso.pageNum . Also if you work with AVdoc the Acobat window stay hidden in the background. Example:
strFilename = "d:\Test2.pdf"
set avDoc = CreateObject("AcroExch.AVDoc")
If (avDoc.Open(strFilename,"")) Then
Set pdDoc = avDoc.getPDDoc()
Set jso = pdDoc.GetJSObject
pageNo = jso.pageNum
msgbox(pageNo)
end if
I'm trying to fix an old macro working with a function GetData that retrieve the whole page in the response string. (Can't give the real URL here)
Function getDataFor(tva As String) As String
' Early binding, set Tools - Reference - Microsoft XML,v6.0
Dim oDOM As New MSXML2.DOMDocument30
Dim oNodeList As IXMLDOMNodeList
Dim oReq As MSXML2.XMLHTTP
Set oReq = New MSXML2.XMLHTTP
oReq.Open "GET", "https://xxxxxxx.asp?name=" & tva, False
oReq.send
While oReq.readyState <> 4
Wend
Dim response As String
Dim name As String
Dim hasLoginBelspo As String
response = oReq.responseText
Dim token1 As Long
Dim token2 As Long
token1 = InStr(response, "company.name=")
token2 = InStr(response, "company.address=")
On Error GoTo Proceed
name = Mid(response, token1 + 14, token2 - (token1 + 16))
On Error GoTo 0
token1 = InStr(response, "parent.SetLoginInfo")
hasLoginBelspo = Replace(Mid(response, token1 + 28, 5), ",", "")
GoTo Proceed2
Proceed:
name = ""
hasLoginBelspo = ""
Proceed2:
getDataFor = name & "," & hasLoginBelspo
End Function
The concerned page is loaded and the needed data is written between javascript tags:
Here is a copy of what I can find in the source page when I paste the URL in a browser.
<script language="javascript">
var company=new Object();company.number="xxx";company.name="xxx";company.address="xxx";company.zip="xxx";company.city="xxx";parent.SetLoginInfo(company,false,true,"xxx","");
</script>
All the data replaced by xxx is what I need. In the browser, I get it, but with the macro, sometimes those xxx data are empty. It should be because the library used to load the javascript may not be the good one (MSXML2).
Do you have an idea of what I need the change, or what kind of library should I use to be sure the javascript data will be catch?
Thanks a lot
Going out on a limb here. Is there a way for a Photoshop VBScript to call a JavaScript file?
Or at least pass some user input (variable or return from function) from one script to another.
My reason for this? I've been having similar issues asked in this question and considered a VBScript UI to drive a photoshop-script. Re-writing the existing jsx into VBS isn't really an option.
Here's what I have. This simple VBScript asks for the user to type in their name which is then created as text in the second script.
VBScript
' Ask User for input
Dim appRef
Set appRef = CreateObject( "Photoshop.Application" )
Dim askName : askName = InputBox("Enter name: ")
JavaScript
// create a document to work with
var docRef = app.documents.add(200, 100, 72, "Hello");
// Create a new art layer containing text
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;
// Set the contents of the text layer.
var textItemRef = artLayerRef.textItem
textItemRef.contents = "Hello " + askName
What do I need to connect the two up?
I have no experience in scripting with Photoshop, did some research.
The following code has been tested with Adobe Photoshop® CS6.
PsJavaScriptExecutionMode enum constants are extracted from scriptingsupport.8li (Adobe Photoshop CS6 Object Library) by using Microsoft OLE/COM Object Viewer.
VBScript:
'PsJavaScriptExecutionMode Enums
Const psNeverShowDebugger = 1, psDebuggerOnError = 2, psBeforeRunning = 3
Dim appRef
Set appRef = CreateObject("Photoshop.Application")
Dim askName
askName = InputBox("Enter name: ")
appRef.DoJavaScriptFile "C:\scripts\myPSscript.jsx", Array(askName), psNeverShowDebugger
JavaScript (myPSscript.jsx):
// create a document to work with
var docRef = app.documents.add(200, 100, 72, "Hello");
// Create a new art layer containing text
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;
// Set the contents of the text layer.
var textItemRef = artLayerRef.textItem
var askName = arguments[0]; // first argument passed from VBScript
textItemRef.contents = "Hello " + askName;
Hope it helps.
Adobe® Creative Suite® 5 Photoshop® Scripting Guide
I am running an program that uni-directly copies from source to destination. The following script runs in conjunction and skips any files with a "date modified" equaling the same day the program is running.
I'd like to modify the script to skip any files with a "created" date equaling today's date and allow any other files regardless of "modified" date.
Essentially, If DateCreated=Today Then Skip
Below is the script I am currently using. I just can not get the right syntax to use creation time verses modified time.
Thank you in advance,
Function Description(ScriptType)
Description = "Ignores any source files modified today. Not used on Restore."
ScriptType = 2
End Function
Sub RunBeforeFileCompare(Filename, ByRef Skip)
' Ignore if this is a Restore
If SBRunning.Restore Then Exit Sub
' See if the file date is the same as todays date, skip if so
If DateDiff("d", SBRunning.GetFileDateTime(Filename, TRUE), Date) = 0 Then
Skip = TRUE
Else
Skip = FALSE
End If
End Sub
The following example illustrates the use of the GetFile method.
filespec: Required. The filespec is the path (absolute or relative) to a specific file.
An error occurs on GetFile method if the specified file does not exist.
JScript
function ShowFileAccessInfo(filespec)
{
var fso, fle, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
fle = fso.GetFile(filespec);
s = fle.Path.toUpperCase() + "<br>";
s += "Created: " + fle.DateCreated + "<br>";
s += "Last Accessed: " + fle.DateLastAccessed + "<br>";
s += "Last Modified: " + fle.DateLastModified
return(s);
}
VBScript
Function ShowFileAccessInfo(filespec)
Dim fso, fle, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set fle = fso.GetFile(filespec)
s = fle.Path & "<br>"
s = s & "Created: " & fle.DateCreated & "<br>"
s = s & "Last Accessed: " & fle.DateLastAccessed & "<br>"
s = s & "Last Modified: " & fle.DateLastModified
ShowFileAccessInfo = s
End Function
Using: vs'12 Razor asp.net MVC4 Internet App Template EF Code First
My Actionlink that i am trying to manipulate
#Html.ActionLink("Download", "ShowOpenAcreageSummaryReport", new { controller = "DataToExcel" }, new { id = "AddData" })
The script to attempt this
$('#AddData').click(function (e) {
var optVal = $("#OptionsDrop").val();
var Xpro = $("#Prospects").val()
var Xcnty = $("#Countys").val()
var Xtwn = $("#TownShips").val()
var Xrng = $("#Ranges").val()
var Xsct = $("#Sections").val()
var href = "/DataToExcel/ShowLPRStandardLeaseReport/" + Xpro + Xcnty + Xtwn + Xrng + Xsct;
this.href = ""; //clears out old href for reuse
this.href = href; //changes href value to currently slected dropdown value
}
The actionResult to accept these passed values
public ActionResult ShowLPRStandardLeaseReport(string pro, string cnty, string twn, string rng, string sec)
Now i know this works with 1 variable as i have this code running on another page, however it won't work with multiple.
I have also tried adding + "/" + between the Variables, which had no effect on the outcome.
How can i change my code to be able to pass all variables??
Have you tried with GET parameters such as some-url/?param1=test¶m2=test2 ? Also note that this points to the #AddData element in the click handler. If you want to change the current location, use window.location.href = 'someurl';
The ? is necessary to indicate the start of the query string parameters.
Also note that you should be encoding the values with encodeURIComponent to make sure that you are producing a valid URL.