1 of 1 people found this helpful
Your best bet is to write the Document.FullName property to a text file when the Document.OnClosing event fires. Then, when the script runs on startup, read the path from the text file and use the OpenDocument method.
This is what I found and then wrote. But nothing happens. I had created another piece that when i click a button, it would write to the test file. I did that to make sure my code for writing to a file worked correct. However, when I added the, "Sub Document_OnClosing()" section, nothing happens. I can't seem to find much on this. Any help is appreciated.
Dim objFSO, objTextFile, objFile
Dim strDirectory, strFile, pcbfilename
strFile = "c:\temp\test.txt"
pcbfilename = ActiveDocument.FullName
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' OpenTextFile Method needs a Const value ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 2
Set objTextFile = objFSO.OpenTextFile (strFile, ForAppending, True)
' Writes pcbfilename every time you run this
I should add that I also found the perfect way to open the last pcb file. This is to use a function called "sendkeys". I can code what keys to push for whatever command. For instance, you can code in the alt+F to bring up the File pulldown and then code in 1, to open the last file. However Mentor scripting doesn't allow it even though it is a vbscript function.
You're on the right track, but your event setup needs some tweaking. Do something like this:
Set pcbApp = Application
Set pcbDoc = pcbApp.ActiveDocument
If (ValidateServer(pcbDoc)) Then
Call Scripting.AttachEvents(pcbDoc, "pcbDoc")
Scripting.DontExit = True
MsgBox "Error: Licensing failed"
''' Save to file here '''
'Ask Expedition's document for the key
keyInt = doc.Validate (0)
'Get license server
Set licenseServer = CreateObject ("MGCPCBAutomationLicensing.Application")
'Ask the license server for the license token
licenseTokenInt = licenseServer.GetToken (keyInt)
'Release license server
Set licenseServer = nothing
'Turn off error messages (validate may fail if the token is incorrect)
On Error Resume Next
'Ask the document to validate the license token
If Err Then
ValidateServer = 0
ValidateServer = 1
Yeah, I tried this approach (Application.Gui.ProcessKeyPressEvent) prior to posting my first answer. I couldn't get it to work. You need to use a tool like AutoIt/AutoHotKey that will send keys to any application.
When Expedition Application is running, do this