feat: add current-project PDF export
This commit is contained in:
1 parent
771d8efb87
commit
c8caaf8daf
22 files changed
+1959
-1
No files matched your search
@@ -61,6 +61,10 @@ Sub DxToolsInstallMenu()
|
||||
button.Caption = DxToolsBomCaption()
|
||||
button.OnAction = "DxToolsOpenBom"
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsPdfExportCaption()
|
||||
button.OnAction = "DxToolsOpenPdfExport"
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsCompatibilityCaption()
|
||||
button.OnAction = "DxToolsOpenCompatibility"
|
||||
@@ -68,6 +72,10 @@ Sub DxToolsInstallMenu()
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsGuideCaption()
|
||||
button.OnAction = "DxToolsOpenGuide"
|
||||
On Error Resume Next
|
||||
Call DxToolsMaybeStartPdfListener()
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenRefDes()
|
||||
@@ -90,6 +98,10 @@ Sub DxToolsOpenBom()
|
||||
Call DxToolsStartFeature("bom")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenPdfExport()
|
||||
Call DxToolsStartFeature("pdf-export")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsStartFeature(featureKey)
|
||||
If Not DxToolsEnsureRoot() Then Exit Sub
|
||||
Call DxToolsEnsureCommonLoaded()
|
||||
@@ -132,6 +144,59 @@ Sub DxToolsOpenGuide()
|
||||
shell.Run Chr(34) & guidePath & Chr(34), 1, False
|
||||
End Sub
|
||||
|
||||
Sub DxToolsMaybeStartPdfListener()
|
||||
Dim shell
|
||||
Dim fso
|
||||
Dim stream
|
||||
Dim settingsPath
|
||||
Dim settingsText
|
||||
Dim expression
|
||||
Dim listenerPath
|
||||
Dim executablePath
|
||||
Dim hostPath
|
||||
Dim commandLine
|
||||
|
||||
Call DxToolsEnsureCommonLoaded()
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
settingsPath = shell.ExpandEnvironmentStrings( _
|
||||
"%LOCALAPPDATA%\DxProductivity\pdf-export-settings.json")
|
||||
If Not fso.FileExists(settingsPath) Then Exit Sub
|
||||
|
||||
On Error Resume Next
|
||||
Set stream = CreateObject("ADODB.Stream")
|
||||
stream.Type = 2
|
||||
stream.Charset = "utf-8"
|
||||
stream.Open
|
||||
stream.LoadFromFile settingsPath
|
||||
settingsText = stream.ReadText
|
||||
stream.Close
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
On Error GoTo 0
|
||||
|
||||
Set expression = CreateObject("VBScript.RegExp")
|
||||
expression.Pattern = Chr(34) & "auto_export" & Chr(34) & "\s*:\s*true"
|
||||
expression.IgnoreCase = True
|
||||
expression.Global = False
|
||||
If Not expression.Test(settingsText) Then Exit Sub
|
||||
|
||||
listenerPath = fso.BuildPath(DxToolsHome, "PdfSaveListener.vbs")
|
||||
executablePath = fso.BuildPath(DxToolsHome, "DxDesignerTools.exe")
|
||||
hostPath = shell.ExpandEnvironmentStrings( _
|
||||
"%WINDIR%\SysWOW64\wscript.exe")
|
||||
If Not fso.FileExists(listenerPath) Then Exit Sub
|
||||
If Not fso.FileExists(executablePath) Then Exit Sub
|
||||
If Not fso.FileExists(hostPath) Then Exit Sub
|
||||
commandLine = DxToolsQuote(hostPath) & " //B //NoLogo " & _
|
||||
DxToolsQuote(listenerPath) & " " & DxToolsQuote(settingsPath) & " " & _
|
||||
DxToolsQuote(executablePath) & " exe " & DxToolsQuote(DxToolsHome)
|
||||
shell.Run commandLine, 0, False
|
||||
End Sub
|
||||
|
||||
Function DxToolsEnsureRoot()
|
||||
If DxToolsHome = "" Then DxToolsHome = DxToolsResolveRoot()
|
||||
DxToolsEnsureRoot = (DxToolsHome <> "")
|
||||
@@ -256,6 +321,10 @@ Function DxToolsBomCaption()
|
||||
DxToolsBomCaption = "BOM " & ChrW(&H5BFC) & ChrW(&H51FA)
|
||||
End Function
|
||||
|
||||
Function DxToolsPdfExportCaption()
|
||||
DxToolsPdfExportCaption = "PDF " & ChrW(&H5BFC) & ChrW(&H51FA)
|
||||
End Function
|
||||
|
||||
Function DxToolsCompatibilityCaption()
|
||||
DxToolsCompatibilityCaption = ChrW(&H517C) & ChrW(&H5BB9) & _
|
||||
ChrW(&H6027) & ChrW(&H68C0) & ChrW(&H6D4B)
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
' DxDesigner 7.9.5 save-event listener. Keep this file ASCII-only.
|
||||
Option Explicit
|
||||
|
||||
Const ForReading = 1
|
||||
Const ForWriting = 2
|
||||
Const TristateTrue = -1
|
||||
|
||||
Dim fso, shell, wmi, app
|
||||
Dim configPath, toolPath, launchMode, workingRoot, lockPath, statusPath, logPath
|
||||
Dim running, busyPid, pendingProject, pendingBlock, hasPending
|
||||
Dim lastEventKey, lastEventAt
|
||||
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
If WScript.Arguments.Count < 4 Then WScript.Quit 2
|
||||
|
||||
configPath = CStr(WScript.Arguments(0))
|
||||
toolPath = CStr(WScript.Arguments(1))
|
||||
launchMode = LCase(CStr(WScript.Arguments(2)))
|
||||
workingRoot = CStr(WScript.Arguments(3))
|
||||
lockPath = configPath & ".listener-lock"
|
||||
statusPath = configPath & ".last-status"
|
||||
logPath = fso.BuildPath(fso.GetParentFolderName(configPath), "pdf-listener.log")
|
||||
running = True
|
||||
busyPid = 0
|
||||
hasPending = False
|
||||
lastEventKey = ""
|
||||
lastEventAt = 0
|
||||
|
||||
If Not DxPdfAutoEnabled() Then WScript.Quit 0
|
||||
If Not DxPdfAcquireLock() Then WScript.Quit 0
|
||||
|
||||
On Error Resume Next
|
||||
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
|
||||
Set app = GetObject(, "ViewDraw.Application")
|
||||
If Err.Number <> 0 Then
|
||||
Call DxPdfLog("Could not connect to ViewDraw.Application: " & Err.Description)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Call DxPdfReleaseLock()
|
||||
WScript.Quit 0
|
||||
End If
|
||||
WScript.ConnectObject app, "DxPdf_"
|
||||
If Err.Number <> 0 Then
|
||||
Call DxPdfLog("Could not connect ViewDraw events: " & Err.Description)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Call DxPdfReleaseLock()
|
||||
WScript.Quit 0
|
||||
End If
|
||||
On Error GoTo 0
|
||||
|
||||
Do While running
|
||||
If Not DxPdfAutoEnabled() Then Exit Do
|
||||
If Not DxPdfHostAvailable() Then Exit Do
|
||||
Call DxPdfTouchLock()
|
||||
If busyPid > 0 Then
|
||||
If Not DxPdfProcessRunning(busyPid) Then
|
||||
Call DxPdfPublishStatus()
|
||||
busyPid = 0
|
||||
If hasPending Then
|
||||
Call DxPdfLaunch(pendingProject, pendingBlock)
|
||||
hasPending = False
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
WScript.Sleep 400
|
||||
Loop
|
||||
|
||||
On Error Resume Next
|
||||
WScript.DisconnectObject app
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Call DxPdfReleaseLock()
|
||||
WScript.Quit 0
|
||||
|
||||
Sub DxPdf_AfterDocumentSave(Doc)
|
||||
Dim projectPath, blockName, eventKey, eventTime
|
||||
If Not DxPdfAutoEnabled() Then Exit Sub
|
||||
projectPath = ""
|
||||
blockName = ""
|
||||
On Error Resume Next
|
||||
projectPath = CStr(app.ProjectPath)
|
||||
blockName = CStr(app.ActiveView.Block.GetName(1))
|
||||
If Err.Number <> 0 Then
|
||||
Call DxPdfLog("Could not read saved project or active Block: " & Err.Description)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
On Error GoTo 0
|
||||
If Len(projectPath) = 0 Then Exit Sub
|
||||
|
||||
eventKey = LCase(projectPath) & Chr(9) & LCase(blockName)
|
||||
eventTime = Timer
|
||||
If eventKey = lastEventKey Then
|
||||
If eventTime >= lastEventAt And eventTime - lastEventAt < 2 Then Exit Sub
|
||||
End If
|
||||
lastEventKey = eventKey
|
||||
lastEventAt = eventTime
|
||||
|
||||
If busyPid > 0 And DxPdfProcessRunning(busyPid) Then
|
||||
pendingProject = projectPath
|
||||
pendingBlock = blockName
|
||||
hasPending = True
|
||||
Call DxPdfSetStatus("PDF export queued")
|
||||
Exit Sub
|
||||
End If
|
||||
Call DxPdfLaunch(projectPath, blockName)
|
||||
End Sub
|
||||
|
||||
Sub DxPdf_Shutdown()
|
||||
running = False
|
||||
End Sub
|
||||
|
||||
Sub DxPdfLaunch(projectPath, blockName)
|
||||
Dim command, prefix
|
||||
On Error Resume Next
|
||||
If fso.FileExists(statusPath) Then fso.DeleteFile statusPath, True
|
||||
prefix = DxPdfQuote(toolPath)
|
||||
If launchMode = "module" Then prefix = prefix & " -m dx_productivity"
|
||||
command = prefix & " pdf-export-event" & _
|
||||
" --settings " & DxPdfQuote(configPath) & _
|
||||
" --project " & DxPdfQuote(projectPath) & _
|
||||
" --active-block " & DxPdfQuote(blockName) & _
|
||||
" --status-file " & DxPdfQuote(statusPath)
|
||||
shell.CurrentDirectory = workingRoot
|
||||
busyPid = CLng(shell.Run(command, 0, False))
|
||||
If Err.Number <> 0 Then
|
||||
Call DxPdfLog("Could not start PDF export: " & Err.Description)
|
||||
Err.Clear
|
||||
busyPid = 0
|
||||
Call DxPdfSetStatus("PDF auto-export could not start")
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
On Error GoTo 0
|
||||
Call DxPdfSetStatus("PDF auto-export started")
|
||||
End Sub
|
||||
|
||||
Sub DxPdfPublishStatus()
|
||||
Dim resultText
|
||||
resultText = "PDF auto-export finished; see local run records"
|
||||
On Error Resume Next
|
||||
If fso.FileExists(statusPath) Then
|
||||
resultText = DxPdfReadUtf8(statusPath)
|
||||
fso.DeleteFile statusPath, True
|
||||
End If
|
||||
If Err.Number <> 0 Then
|
||||
Call DxPdfLog("Could not read export status: " & Err.Description)
|
||||
Err.Clear
|
||||
End If
|
||||
On Error GoTo 0
|
||||
If Len(resultText) > 240 Then resultText = Left(resultText, 237) & "..."
|
||||
Call DxPdfSetStatus(Trim(resultText))
|
||||
End Sub
|
||||
|
||||
Sub DxPdfSetStatus(value)
|
||||
On Error Resume Next
|
||||
app.StatusBarText = CStr(value)
|
||||
If Err.Number <> 0 Then
|
||||
Call DxPdfLog("Could not update DxDesigner status bar: " & Err.Description)
|
||||
Err.Clear
|
||||
End If
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Function DxPdfAutoEnabled()
|
||||
Dim text, expression
|
||||
DxPdfAutoEnabled = False
|
||||
On Error Resume Next
|
||||
text = DxPdfReadUtf8(configPath)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Function
|
||||
End If
|
||||
Set expression = CreateObject("VBScript.RegExp")
|
||||
expression.Pattern = Chr(34) & "auto_export" & Chr(34) & "\s*:\s*true"
|
||||
expression.IgnoreCase = True
|
||||
expression.Global = False
|
||||
DxPdfAutoEnabled = expression.Test(text)
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxPdfReadUtf8(path)
|
||||
Dim stream
|
||||
Set stream = CreateObject("ADODB.Stream")
|
||||
stream.Type = 2
|
||||
stream.Charset = "utf-8"
|
||||
stream.Open
|
||||
stream.LoadFromFile CStr(path)
|
||||
DxPdfReadUtf8 = stream.ReadText
|
||||
stream.Close
|
||||
End Function
|
||||
|
||||
Function DxPdfProcessRunning(pid)
|
||||
Dim matches, process, commandLine
|
||||
DxPdfProcessRunning = False
|
||||
On Error Resume Next
|
||||
Set matches = wmi.ExecQuery("SELECT CommandLine FROM Win32_Process WHERE ProcessId=" & CLng(pid))
|
||||
If Err.Number = 0 Then
|
||||
For Each process In matches
|
||||
commandLine = ""
|
||||
If Not IsNull(process.CommandLine) Then commandLine = CStr(process.CommandLine)
|
||||
If InStr(1, commandLine, "pdf-export-event", vbTextCompare) > 0 Then
|
||||
DxPdfProcessRunning = True
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxPdfHostAvailable()
|
||||
Dim projectPath
|
||||
DxPdfHostAvailable = False
|
||||
On Error Resume Next
|
||||
projectPath = CStr(app.ProjectPath)
|
||||
DxPdfHostAvailable = (Err.Number = 0)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxPdfAcquireLock()
|
||||
Dim lockFile
|
||||
DxPdfAcquireLock = False
|
||||
On Error Resume Next
|
||||
If fso.FileExists(lockPath) Then
|
||||
If DateDiff("s", fso.GetFile(lockPath).DateLastModified, Now) < 15 Then
|
||||
On Error GoTo 0
|
||||
Exit Function
|
||||
End If
|
||||
fso.DeleteFile lockPath, True
|
||||
End If
|
||||
Set lockFile = fso.CreateTextFile(lockPath, False, True)
|
||||
If Err.Number = 0 Then
|
||||
lockFile.WriteLine CStr(Now)
|
||||
lockFile.Close
|
||||
DxPdfAcquireLock = True
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Sub DxPdfTouchLock()
|
||||
Dim lockFile
|
||||
On Error Resume Next
|
||||
If fso.FileExists(lockPath) Then
|
||||
Set lockFile = fso.OpenTextFile(lockPath, ForWriting, False, TristateTrue)
|
||||
lockFile.WriteLine CStr(Now)
|
||||
lockFile.Close
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxPdfReleaseLock()
|
||||
On Error Resume Next
|
||||
If fso.FileExists(lockPath) Then fso.DeleteFile lockPath, True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxPdfLog(value)
|
||||
Dim stream
|
||||
On Error Resume Next
|
||||
Set stream = fso.OpenTextFile(logPath, 8, True, TristateTrue)
|
||||
stream.WriteLine CStr(Now) & " " & CStr(value)
|
||||
stream.Close
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Function DxPdfQuote(value)
|
||||
Dim text, expression
|
||||
text = CStr(value)
|
||||
Set expression = CreateObject("VBScript.RegExp")
|
||||
expression.Pattern = "\\+$"
|
||||
expression.Global = False
|
||||
text = expression.Replace(text, "$&$&")
|
||||
DxPdfQuote = Chr(34) & Replace(text, Chr(34), Chr(92) & Chr(34)) & Chr(34)
|
||||
End Function
|
||||
@@ -45,6 +45,8 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
|
||||
Dim netsText
|
||||
Dim selectedNetsText
|
||||
Dim snapshotSequence
|
||||
Dim activeBlockName
|
||||
Dim currentSheetNumberJson
|
||||
|
||||
DxRefreshSnapshot = False
|
||||
Set selectedKeys = CreateObject("Scripting.Dictionary")
|
||||
@@ -71,6 +73,8 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
|
||||
designId = CStr(designs.GetItem(1))
|
||||
topBlock = projectData.GetiCDBDesignRootBlock(designId)
|
||||
designPath = DxBridgeDesignPath()
|
||||
activeBlockName = DxBridgeCurrentBlockName()
|
||||
currentSheetNumberJson = DxBridgeCurrentSheetNumberJson()
|
||||
componentCount = 0
|
||||
componentText = ""
|
||||
|
||||
@@ -141,6 +145,9 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
|
||||
" ""snapshot_id"": """ & DxToolsJson(snapshotId) & """," & vbCrLf & _
|
||||
" ""design_id"": """ & DxToolsJson(designId) & """," & vbCrLf & _
|
||||
" ""design_path"": """ & DxToolsJson(designPath) & """," & vbCrLf & _
|
||||
" ""active_block_name"": """ & _
|
||||
DxToolsJson(activeBlockName) & """," & vbCrLf & _
|
||||
" ""current_sheet_number"": " & currentSheetNumberJson & "," & vbCrLf & _
|
||||
" ""nets"": " & netsText & "," & vbCrLf & _
|
||||
" ""selected_nets"": " & selectedNetsText & "," & vbCrLf & _
|
||||
" ""components"": [" & vbCrLf & componentText & vbCrLf & _
|
||||
@@ -383,6 +390,25 @@ Function DxBridgeCurrentSheetNumber()
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeCurrentBlockName()
|
||||
DxBridgeCurrentBlockName = ""
|
||||
On Error Resume Next
|
||||
DxBridgeCurrentBlockName = CStr(ActiveView.Block.GetName(SHORT_NAME))
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeCurrentSheetNumberJson()
|
||||
DxBridgeCurrentSheetNumberJson = "null"
|
||||
On Error Resume Next
|
||||
DxBridgeCurrentSheetNumberJson = CStr(CLng(ActiveView.Block.SheetNum))
|
||||
If Err.Number <> 0 Then
|
||||
DxBridgeCurrentSheetNumberJson = "null"
|
||||
Err.Clear
|
||||
End If
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeCoordinate(component, readX)
|
||||
Dim value
|
||||
value = 0
|
||||
|
||||
Reference in new issue
Block a user