fix: persist native menus and validate every tool workflow
This commit is contained in:
1 parent
7a471fec24
commit
cd88a9950a
76 files changed
+4249
-264
No files matched your search
@@ -169,7 +169,7 @@ Function DxToolsProbePathMethod(comp)
|
||||
If comp Is Nothing Then Exit Function
|
||||
|
||||
On Error Resume Next
|
||||
ignored = CStr(comp.Parent) & "\" & CStr(comp.GetName(SHORT_NAME))
|
||||
ignored = CStr(comp.Parent.GetName(SHORT_NAME)) & "\" & CStr(comp.GetName(SHORT_NAME))
|
||||
If Err.Number = 0 Then DxToolsProbePathMethod = "Parent+GetName(SHORT_NAME)"
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
@@ -181,6 +181,14 @@ Function DxToolsProbePositionMethod(comp)
|
||||
DxToolsProbePositionMethod = ""
|
||||
If comp Is Nothing Then Exit Function
|
||||
|
||||
On Error Resume Next
|
||||
x = comp.GetLocation().X
|
||||
y = comp.GetLocation().Y
|
||||
If Err.Number = 0 Then DxToolsProbePositionMethod = "GetLocation().X/Y"
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If DxToolsProbePositionMethod <> "" Then Exit Function
|
||||
|
||||
On Error Resume Next
|
||||
x = comp.X
|
||||
y = comp.Y
|
||||
|
||||
@@ -17,8 +17,56 @@ If DxToolsHome = "" Then
|
||||
MsgBox DxToolsPathErrorMessage(), vbExclamation
|
||||
Else
|
||||
Call DxToolsInstallMenu()
|
||||
Call DxToolsAttachMenuEvents()
|
||||
End If
|
||||
|
||||
Sub DxToolsAttachMenuEvents()
|
||||
' Native startup scripts must remain alive to receive project/view events.
|
||||
On Error Resume Next
|
||||
Scripting.AttachEvents Application, "DxToolsHost"
|
||||
Scripting.DontExit = True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxToolsHost_ProjectChanged(projectData)
|
||||
Call DxToolsRestoreMenus()
|
||||
End Sub
|
||||
|
||||
Sub DxToolsHost_AfterDocumentOpened(dataType, name, path)
|
||||
Call DxToolsRestoreMenus()
|
||||
End Sub
|
||||
|
||||
Sub DxToolsHost_ActivateView()
|
||||
Call DxToolsRestoreMenus()
|
||||
End Sub
|
||||
|
||||
Sub DxToolsHost_ProjectClosed()
|
||||
Call DxToolsRestoreMenus()
|
||||
End Sub
|
||||
|
||||
Sub DxToolsRestoreMenus()
|
||||
Call DxToolsRestoreMenuBar("Main Menu Bar")
|
||||
Call DxToolsRestoreMenuBar("Sheet Menu Bar")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsRestoreMenuBar(barName)
|
||||
Dim menuBar, item, index
|
||||
On Error Resume Next
|
||||
Set menuBar = CommandBars(CStr(barName))
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
On Error GoTo 0
|
||||
For index = 1 To menuBar.Controls.Count
|
||||
Set item = menuBar.Controls.Item(index)
|
||||
If item.Caption = DxToolsSuiteCaption() Then Exit Sub
|
||||
Next
|
||||
Call DxToolsInstallMenuBar(barName)
|
||||
End Sub
|
||||
|
||||
Sub DxToolsInstallMenu()
|
||||
Call DxToolsInstallMenuBar("Main Menu Bar")
|
||||
Call DxToolsInstallMenuBar("Sheet Menu Bar")
|
||||
@@ -190,16 +238,10 @@ Sub DxToolsMaybeStartPdfListener()
|
||||
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)
|
||||
commandLine = DxToolsQuote(executablePath) & " pdf-export-listen --settings " & _
|
||||
DxToolsQuote(settingsPath)
|
||||
shell.Run commandLine, 0, False
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -30,13 +30,35 @@ Sub DxBridgeRenderBom(runRoot, claimedPath)
|
||||
End Sub
|
||||
|
||||
Sub DxBomRenderPayload(text, ByRef statusState, ByRef statusError)
|
||||
Dim excel
|
||||
Dim workbook
|
||||
Set excel = Nothing
|
||||
Set workbook = Nothing
|
||||
On Error Resume Next
|
||||
Set excel = CreateObject("Excel.Application")
|
||||
If Err.Number = 0 Then
|
||||
Call DxBomPopulateWorkbook(excel, workbook, text)
|
||||
End If
|
||||
If Err.Number <> 0 Then
|
||||
statusState = "failed"
|
||||
statusError = Err.Description
|
||||
Err.Clear
|
||||
If Not workbook Is Nothing Then workbook.Close False
|
||||
If Not excel Is Nothing Then excel.Quit
|
||||
Err.Clear
|
||||
Else
|
||||
statusState = "ok"
|
||||
statusError = ""
|
||||
End If
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxBomPopulateWorkbook(excel, ByRef workbook, text)
|
||||
Dim templatePath
|
||||
Dim outputPath
|
||||
Dim designName
|
||||
Dim descriptionHeader
|
||||
Dim excel
|
||||
Dim workbooks
|
||||
Dim workbook
|
||||
Dim sheet
|
||||
Dim saveFormat
|
||||
|
||||
@@ -45,7 +67,6 @@ Sub DxBomRenderPayload(text, ByRef statusState, ByRef statusError)
|
||||
Call DxBomField(text, "design_name", designName)
|
||||
Call DxBomField(text, "description_header", descriptionHeader)
|
||||
|
||||
Set excel = CreateObject("Excel.Application")
|
||||
excel.Visible = False
|
||||
excel.DisplayAlerts = False
|
||||
Set workbooks = excel.Workbooks
|
||||
@@ -68,20 +89,20 @@ Sub DxBomRenderPayload(text, ByRef statusState, ByRef statusError)
|
||||
Call workbook.SaveAs(CStr(outputPath), saveFormat)
|
||||
excel.Visible = True
|
||||
excel.DisplayAlerts = True
|
||||
statusState = "ok"
|
||||
statusError = ""
|
||||
End Sub
|
||||
|
||||
Sub DxBomWriteSections(excel, sheet, text)
|
||||
' Sections and rows are embedded as line-oriented records to keep the VBS
|
||||
' JSON reading trivial: S|<page> / R|<qty>|<refdes>|<pn>|<desc>|<flags>
|
||||
Dim lines
|
||||
Dim records
|
||||
Dim line
|
||||
Dim parts
|
||||
Dim rowIndex
|
||||
Dim flagParts
|
||||
rowIndex = 2
|
||||
lines = Split(Replace(CStr(text), vbCr, ""), vbLf)
|
||||
Call DxBomField(text, "records", records)
|
||||
lines = Split(Replace(CStr(records), vbCr, ""), vbLf)
|
||||
For Each line In lines
|
||||
If Left(line, 2) = "S|" Then
|
||||
sheet.Cells(rowIndex, 1).Value = Mid(line, 3)
|
||||
|
||||
@@ -10,6 +10,7 @@ Sub DxToolsDesignBridgeStart(featureKey)
|
||||
Dim snapshotId
|
||||
Dim process
|
||||
Dim state
|
||||
Dim messageStyle
|
||||
|
||||
Set objectMap = CreateObject("Scripting.Dictionary")
|
||||
Set originalMap = CreateObject("Scripting.Dictionary")
|
||||
@@ -22,8 +23,9 @@ Sub DxToolsDesignBridgeStart(featureKey)
|
||||
state = DxBridgeMailboxLoop(process, runRoot, runId, snapshotId, _
|
||||
objectMap, originalMap)
|
||||
If state <> "" Then
|
||||
MsgBox DxBridgeStateMessage(state), _
|
||||
IIf(state = "applied", vbInformation, vbExclamation)
|
||||
messageStyle = vbExclamation
|
||||
If state = "applied" Then messageStyle = vbInformation
|
||||
MsgBox DxBridgeStateMessage(state), messageStyle
|
||||
End If
|
||||
End Sub
|
||||
|
||||
@@ -184,7 +186,7 @@ Sub DxBridgeConsumeLocate(runRoot, objectMap)
|
||||
If Not fso.FileExists(locatePath) Then Exit Sub
|
||||
If Not DxBridgeClaimFile(fso, locatePath, processingPath) Then Exit Sub
|
||||
On Error Resume Next
|
||||
bridgeId = Trim(DxToolsReadUtf8(processingPath))
|
||||
bridgeId = Trim(Replace(Replace(DxToolsReadUtf8(processingPath), vbCr, ""), vbLf, ""))
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
@@ -211,6 +213,7 @@ Sub DxBridgeLocateNet(netName, pageNumber)
|
||||
Dim topBlock
|
||||
Dim net
|
||||
Dim found
|
||||
Dim page, pageIndex, sheetName
|
||||
On Error Resume Next
|
||||
Set projectData = Application.GetProjectData()
|
||||
If Err.Number <> 0 Then
|
||||
@@ -222,13 +225,22 @@ Sub DxBridgeLocateNet(netName, pageNumber)
|
||||
designId = CStr(designs.GetItem(1))
|
||||
topBlock = projectData.GetiCDBDesignRootBlock(designId)
|
||||
Err.Clear
|
||||
ActiveView.UnselectAll
|
||||
ActiveView.Block.DeSelectAll
|
||||
Err.Clear
|
||||
Application.PushPath topBlock, "", CLng(pageNumber)
|
||||
pageIndex = 0
|
||||
sheetName = CStr(pageNumber)
|
||||
For Each page In Application.QueryPages(topBlock)
|
||||
pageIndex = pageIndex + 1
|
||||
If pageIndex = CLng(pageNumber) Then
|
||||
sheetName = CStr(page.SheetNum)
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Application.PushPath topBlock, "", sheetName
|
||||
Err.Clear
|
||||
found = False
|
||||
For Each net In ActiveView.Query(VDM_NET, VD_ALL)
|
||||
If CStr(net.Name) = CStr(netName) Then
|
||||
If StrComp(DxBridgeNetName(net), CStr(netName), vbTextCompare) = 0 Then
|
||||
net.Selected = True
|
||||
If Err.Number <> 0 Then Err.Clear
|
||||
ActiveView.ZoomSelect
|
||||
@@ -254,15 +266,13 @@ End Function
|
||||
|
||||
Sub DxBridgeLocateComponent(component)
|
||||
On Error Resume Next
|
||||
ActiveView.UnselectAll
|
||||
Application.PushPath component.Parent.GetName(SHORT_NAME), "", CStr(component.Parent.SheetNum)
|
||||
Err.Clear
|
||||
ActiveView.Select component
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
ActiveView.SelectObject component
|
||||
End If
|
||||
ActiveView.Block.DeSelectAll
|
||||
Err.Clear
|
||||
ActiveView.ZoomTo component
|
||||
ActiveView.SelectByName component.GetName(SHORT_NAME)
|
||||
Err.Clear
|
||||
ActiveView.ZoomSelect
|
||||
Err.Clear
|
||||
ActiveView.Refresh
|
||||
Err.Clear
|
||||
|
||||
@@ -99,10 +99,11 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
|
||||
refdes = DxBridgeRefdes(component)
|
||||
symbolDefault = DxBridgeSymbolDefault(component, refdes)
|
||||
sheetNumber = DxBridgeSheetNumber(component)
|
||||
sheetName = CStr(sheetNumber)
|
||||
sheetName = CStr(component.Parent.SheetNum)
|
||||
identityKey = DxBridgeIdentityKey(stableUid, fullPath)
|
||||
selectedValue = selectedKeys.Exists(identityKey)
|
||||
currentSheetValue = (sheetNumber = DxBridgeCurrentSheetNumber())
|
||||
currentSheetValue = (LCase(DxBridgeBlockName(component.Parent)) = LCase(activeBlockName) _
|
||||
And LCase(sheetName) = LCase(DxBridgeCurrentSheetName()))
|
||||
attributesText = DxBridgeExportAttributes(component)
|
||||
|
||||
objectMap.Add bridgeId, component
|
||||
@@ -151,6 +152,7 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
|
||||
" ""active_block_name"": """ & _
|
||||
DxToolsJson(activeBlockName) & """," & vbCrLf & _
|
||||
" ""current_sheet_number"": " & currentSheetNumberJson & "," & vbCrLf & _
|
||||
" ""current_sheet_name"": """ & DxToolsJson(DxBridgeCurrentSheetName()) & """," & vbCrLf & _
|
||||
" ""nets"": " & netsText & "," & vbCrLf & _
|
||||
" ""selected_nets"": " & selectedNetsText & "," & vbCrLf & _
|
||||
" ""components"": [" & vbCrLf & componentText & vbCrLf & _
|
||||
@@ -215,12 +217,12 @@ Function DxBridgeExportNets(topBlock)
|
||||
For Each net In nets
|
||||
name = ""
|
||||
page = -1
|
||||
name = CStr(net.Name)
|
||||
name = DxBridgeNetName(net)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
name = ""
|
||||
End If
|
||||
page = CLng(net.SheetNum)
|
||||
page = DxBridgeBlockSheetNumber(net.Parent)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
page = DxBridgeCurrentSheetNumber()
|
||||
@@ -230,7 +232,7 @@ Function DxBridgeExportNets(topBlock)
|
||||
If Not names.Exists(nameText) Then
|
||||
names.Add nameText, name
|
||||
pages.Add nameText, CStr(page)
|
||||
ElseIf InStr(pages(nameText), CStr(page)) = 0 Then
|
||||
ElseIf InStr("," & Replace(pages(nameText), " ", "") & ",", "," & CStr(page) & ",") = 0 Then
|
||||
pages(nameText) = pages(nameText) & ", " & CStr(page)
|
||||
End If
|
||||
End If
|
||||
@@ -256,7 +258,7 @@ Function DxBridgeExportSelectedNets()
|
||||
text = ""
|
||||
On Error Resume Next
|
||||
For Each net In ActiveView.Query(VDM_NET, VD_SELECTED)
|
||||
name = CStr(net.Name)
|
||||
name = DxBridgeNetName(net)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
ElseIf name <> "" Then
|
||||
@@ -328,7 +330,7 @@ Function DxBridgeFullPath(component)
|
||||
parentName = ""
|
||||
componentName = ""
|
||||
On Error Resume Next
|
||||
parentName = CStr(component.Parent.Name)
|
||||
parentName = CStr(component.Parent.GetName(SHORT_NAME))
|
||||
componentName = CStr(component.GetName(SHORT_NAME))
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
@@ -369,28 +371,83 @@ Function DxBridgeRefdes(component)
|
||||
End Function
|
||||
|
||||
Function DxBridgeSymbolDefault(component, refdes)
|
||||
Dim symbolAttribute
|
||||
DxBridgeSymbolDefault = ""
|
||||
On Error Resume Next
|
||||
DxBridgeSymbolDefault = CStr(component.SymbolRefdesDefault)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If DxBridgeSymbolDefault = "" Then
|
||||
On Error Resume Next
|
||||
Set symbolAttribute = component.SymbolBlock.FindAttribute("Ref Designator")
|
||||
If Not symbolAttribute Is Nothing Then
|
||||
DxBridgeSymbolDefault = CStr(symbolAttribute.Value)
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End If
|
||||
If DxBridgeSymbolDefault = "" And InStr(CStr(refdes), "?") > 0 Then
|
||||
DxBridgeSymbolDefault = CStr(refdes)
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxBridgeSheetNumber(component)
|
||||
DxBridgeSheetNumber = DxBridgeCurrentSheetNumber()
|
||||
On Error Resume Next
|
||||
DxBridgeSheetNumber = CLng(component.Parent.SheetNum)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
DxBridgeSheetNumber = DxBridgeBlockSheetNumber(component.Parent)
|
||||
End Function
|
||||
|
||||
Function DxBridgeCurrentSheetNumber()
|
||||
DxBridgeCurrentSheetNumber = 0
|
||||
On Error Resume Next
|
||||
DxBridgeCurrentSheetNumber = CLng(ActiveView.Block.SheetNum)
|
||||
DxBridgeCurrentSheetNumber = DxBridgeBlockSheetNumber(ActiveView.Block)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeBlockSheetNumber(block)
|
||||
Dim rawName, page, index
|
||||
DxBridgeBlockSheetNumber = 0
|
||||
On Error Resume Next
|
||||
rawName = CStr(block.SheetNum)
|
||||
If IsNumeric(rawName) Then
|
||||
DxBridgeBlockSheetNumber = CLng(rawName)
|
||||
Else
|
||||
index = 0
|
||||
For Each page In Application.QueryPages(DxBridgeBlockName(block))
|
||||
index = index + 1
|
||||
If StrComp(CStr(page.SheetNum), rawName, vbTextCompare) = 0 Then
|
||||
DxBridgeBlockSheetNumber = index
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeBlockName(block)
|
||||
DxBridgeBlockName = ""
|
||||
On Error Resume Next
|
||||
DxBridgeBlockName = CStr(block.GetName(SHORT_NAME))
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeCurrentSheetName()
|
||||
DxBridgeCurrentSheetName = ""
|
||||
On Error Resume Next
|
||||
DxBridgeCurrentSheetName = CStr(ActiveView.Block.SheetNum)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeNetName(net)
|
||||
DxBridgeNetName = ""
|
||||
On Error Resume Next
|
||||
DxBridgeNetName = CStr(net.LogicalNetName)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
DxBridgeNetName = CStr(net.Name)
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
@@ -404,14 +461,13 @@ Function DxBridgeCurrentBlockName()
|
||||
End Function
|
||||
|
||||
Function DxBridgeCurrentSheetNumberJson()
|
||||
DxBridgeCurrentSheetNumberJson = "null"
|
||||
On Error Resume Next
|
||||
DxBridgeCurrentSheetNumberJson = CStr(CLng(ActiveView.Block.SheetNum))
|
||||
If Err.Number <> 0 Then
|
||||
Dim number
|
||||
number = DxBridgeCurrentSheetNumber()
|
||||
If number > 0 Then
|
||||
DxBridgeCurrentSheetNumberJson = CStr(number)
|
||||
Else
|
||||
DxBridgeCurrentSheetNumberJson = "null"
|
||||
Err.Clear
|
||||
End If
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeCoordinate(component, readX)
|
||||
@@ -419,16 +475,16 @@ Function DxBridgeCoordinate(component, readX)
|
||||
value = 0
|
||||
On Error Resume Next
|
||||
If CBool(readX) Then
|
||||
value = component.X
|
||||
value = component.GetLocation().X
|
||||
Else
|
||||
value = component.Y
|
||||
value = component.GetLocation().Y
|
||||
End If
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
If CBool(readX) Then
|
||||
value = component.PositionX
|
||||
value = component.X
|
||||
Else
|
||||
value = component.PositionY
|
||||
value = component.Y
|
||||
End If
|
||||
End If
|
||||
Err.Clear
|
||||
@@ -461,7 +517,7 @@ End Function
|
||||
Function DxBridgeAttribute(component, name)
|
||||
DxBridgeAttribute = ""
|
||||
On Error Resume Next
|
||||
DxBridgeAttribute = CStr(component.Attributes.Item(CStr(name)).Value)
|
||||
DxBridgeAttribute = CStr(component.FindAttribute(CStr(name)).Value)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
@@ -472,8 +528,9 @@ Function DxBridgeLocked(component)
|
||||
DxBridgeLocked = CBool(component.Locked)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
DxBridgeLocked = False
|
||||
DxBridgeLocked = CBool(component.Parent.IsReadOnly)
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
|
||||
@@ -49,18 +49,38 @@ Function DxPreflightApply(runRoot, runId, snapshotId, objectMap, _
|
||||
Dim projected
|
||||
Dim key
|
||||
Dim component
|
||||
Dim snapshotPath, snapshotText, snapshotDesignPath, currentProjectPath
|
||||
|
||||
DxPreflightApply = False
|
||||
errorText = ""
|
||||
backupPath = ""
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
requestPath = fso.BuildPath(runRoot, "apply-request.json")
|
||||
resultPath = fso.BuildPath(runRoot, "result.tsv")
|
||||
resultPath = fso.BuildPath(runRoot, "result.processing")
|
||||
If Not fso.FileExists(resultPath) Then resultPath = fso.BuildPath(runRoot, "result.tsv")
|
||||
If Not fso.FileExists(requestPath) Or Not fso.FileExists(resultPath) Then
|
||||
errorText = "Apply request is incomplete"
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
snapshotPath = fso.BuildPath(runRoot, "request.json")
|
||||
If fso.FileExists(snapshotPath) Then
|
||||
snapshotText = DxToolsReadUtf8(snapshotPath)
|
||||
If Not DxToolsJsonString(snapshotText, "design_path", snapshotDesignPath) Then
|
||||
errorText = "Design snapshot project path is invalid"
|
||||
Exit Function
|
||||
End If
|
||||
currentProjectPath = ""
|
||||
On Error Resume Next
|
||||
currentProjectPath = CStr(Application.GetProjectData().GetProjectFilePath())
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If currentProjectPath = "" Or StrComp(currentProjectPath, snapshotDesignPath, vbTextCompare) <> 0 Then
|
||||
errorText = "Design snapshot belongs to a different current project"
|
||||
Exit Function
|
||||
End If
|
||||
End If
|
||||
|
||||
requestText = DxToolsReadUtf8(requestPath)
|
||||
If InStr(requestText, """format_version"": 2,") = 0 Then
|
||||
errorText = "Unsupported apply request version"
|
||||
@@ -215,7 +235,7 @@ Function DxApplySchedule(resultText, objectMap, _
|
||||
touched, rollbackState, errorText)
|
||||
Exit Function
|
||||
End If
|
||||
finals.Add key, Array(CStr(op), CStr(propertyName), _
|
||||
finals(key) = Array(CStr(op), CStr(propertyName), _
|
||||
CStr(bridgeId), CStr(finalValue))
|
||||
End If
|
||||
Next
|
||||
@@ -331,7 +351,7 @@ Function DxBridgeReadOpValue(component, op, propertyName)
|
||||
DxBridgeReadOpValue = ""
|
||||
On Error Resume Next
|
||||
DxBridgeReadOpValue = CStr( _
|
||||
component.Attributes.Item(CStr(propertyName)).Value)
|
||||
component.FindAttribute(CStr(propertyName)).Value)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
DxBridgeReadOpValue = ""
|
||||
@@ -341,7 +361,7 @@ Function DxBridgeReadOpValue(component, op, propertyName)
|
||||
DxBridgeReadOpValue = ""
|
||||
On Error Resume Next
|
||||
DxBridgeReadOpValue = DxBridgeNormalizeVisible( _
|
||||
component.Attributes.Item(CStr(propertyName)).Visible)
|
||||
component.FindAttribute(CStr(propertyName)).Visible)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
DxBridgeReadOpValue = ""
|
||||
@@ -361,9 +381,9 @@ Function DxBridgeWriteOpValue(component, op, propertyName, value, _
|
||||
Case "refdes"
|
||||
component.Refdes = CStr(value)
|
||||
Case "property"
|
||||
component.Attributes.Item(CStr(propertyName)).Value = CStr(value)
|
||||
component.FindAttribute(CStr(propertyName)).Value = CStr(value)
|
||||
Case "visibility"
|
||||
component.Attributes.Item(CStr(propertyName)).Visible = _
|
||||
component.FindAttribute(CStr(propertyName)).Visible = _
|
||||
CBool(CStr(value))
|
||||
Case Else
|
||||
Err.Raise vbObjectError + 801, "DxBridgeWriteOpValue", _
|
||||
|
||||
@@ -4,6 +4,25 @@
|
||||
' host applies it inside one undoable transaction.
|
||||
|
||||
Dim DxToolsHome
|
||||
Dim DxExpeditionMenu
|
||||
|
||||
Call DxEpInitialize()
|
||||
|
||||
Sub DxEpInitialize()
|
||||
Dim host
|
||||
Set host = Nothing
|
||||
On Error Resume Next
|
||||
Set host = Application
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If host Is Nothing Then Exit Sub
|
||||
Call DxToolsInstallExpeditionMenu()
|
||||
If DxToolsHome = "" Then Exit Sub
|
||||
On Error Resume Next
|
||||
Scripting.DontExit = True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxToolsInstallExpeditionMenu()
|
||||
Dim menuBar
|
||||
@@ -14,13 +33,13 @@ Sub DxToolsInstallExpeditionMenu()
|
||||
|
||||
DxToolsHome = DxEpResolveRoot()
|
||||
If DxToolsHome = "" Then
|
||||
MsgBox "DxDesignerTools.exe not found next to this script.", _
|
||||
MsgBox "Run Start in DxDesignerTools.exe before importing this script.", _
|
||||
vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
caption = "Dx " & ChrW(&H6548) & ChrW(&H7387) & ChrW(&H5DE5) & ChrW(&H5177)
|
||||
Set menuBar = CommandBars("Document Menu Bar")
|
||||
Set menuBar = Application.Gui.CommandBars("Document Menu Bar")
|
||||
For i = menuBar.Controls.Count To 1 Step -1
|
||||
Set existing = menuBar.Controls.Item(i)
|
||||
If existing.Caption = caption Then
|
||||
@@ -31,14 +50,19 @@ Sub DxToolsInstallExpeditionMenu()
|
||||
End If
|
||||
Next
|
||||
|
||||
Set DxExpeditionMenu = menuBar.Controls.Add(10) ' cmdControlPopup
|
||||
Set DxExpeditionMenu = menuBar.Controls.Add(1) ' cmdControlPopup
|
||||
DxExpeditionMenu.Caption = caption
|
||||
|
||||
Set button = DxExpeditionMenu.Controls.Add
|
||||
button.Caption = ChrW(&H81EA) & ChrW(&H52A8) & ChrW(&H8C03) & _
|
||||
ChrW(&H6574) & ChrW(&H88C5) & ChrW(&H914D) & ChrW(&H5C42) & _
|
||||
ChrW(&H4F4D) & ChrW(&H53F7)
|
||||
button.OnAction = "DxExpeditionRunAssemblyRefdes"
|
||||
button.Target = ScriptEngine
|
||||
button.ExecuteMethod = "DxEpAssemblyMenuCommand"
|
||||
End Sub
|
||||
|
||||
Sub DxEpAssemblyMenuCommand(nID)
|
||||
Call DxExpeditionRunAssemblyRefdes()
|
||||
End Sub
|
||||
|
||||
Sub DxExpeditionRunAssemblyRefdes()
|
||||
@@ -66,9 +90,9 @@ Sub DxExpeditionRunAssemblyRefdes()
|
||||
|
||||
Dim exec
|
||||
Dim commandLine
|
||||
commandLine = DxToolsQuote(DxToolsHome & "\DxDesignerTools.exe") & _
|
||||
" compute assembly-refdes --request " & DxToolsQuote(requestPath) & _
|
||||
" --output " & DxToolsQuote(planPath)
|
||||
commandLine = DxEpQuote(DxToolsHome & "\DxDesignerTools.exe") & _
|
||||
" compute assembly-refdes --request " & DxEpQuote(requestPath) & _
|
||||
" --output " & DxEpQuote(planPath)
|
||||
On Error Resume Next
|
||||
Set exec = shell.Exec(commandLine)
|
||||
If Err.Number <> 0 Then
|
||||
@@ -109,6 +133,7 @@ Function DxEpExportRequest(docObj)
|
||||
Dim componentKey
|
||||
Dim orientation
|
||||
Dim hasComponent
|
||||
Dim assemblyFlag
|
||||
|
||||
Set spans = CreateObject("Scripting.Dictionary")
|
||||
lines = ""
|
||||
@@ -191,10 +216,12 @@ Function DxEpExportRequest(docObj)
|
||||
On Error GoTo 0
|
||||
|
||||
If lines <> "" Then lines = lines & vbCrLf
|
||||
assemblyFlag = "0"
|
||||
If fabtxt.Type = epcbFabAssembly Then assemblyFlag = "1"
|
||||
lines = lines & "T|" & textIndex & _
|
||||
"|" & CStr(fabtxt.TextType) & _
|
||||
"|" & CStr(fabtxt.Side) & _
|
||||
"|" & IIf(fabtxt.Type = epcbFabAssembly, "1", "0") & _
|
||||
"|" & assemblyFlag & _
|
||||
"|" & fabtxt.TextString & _
|
||||
"|" & orientation & _
|
||||
"|" & componentKey
|
||||
@@ -254,7 +281,11 @@ Sub DxEpApplyLine(line, fabtxt)
|
||||
fabtxt.Format.Height(epcbUnitMM) = CDbl(parts(5))
|
||||
End If
|
||||
fabtxt.Format.Orientation(epcbAngleUnitDegrees) = CDbl(parts(4))
|
||||
Call fabtxt.Move(CDbl(parts(2)), CDbl(parts(3)))
|
||||
' Blank height represents the legacy nonassembly/cardinal branch:
|
||||
' change text format while retaining the existing text position.
|
||||
If parts(5) <> "" Then
|
||||
Call fabtxt.Move(CDbl(parts(2)), CDbl(parts(3)))
|
||||
End If
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
@@ -268,6 +299,17 @@ Sub DxEpWriteAscii(path, text)
|
||||
stream.Close
|
||||
End Sub
|
||||
|
||||
Function DxEpQuote(value)
|
||||
Dim text, expression
|
||||
text = CStr(value)
|
||||
Set expression = CreateObject("VBScript.RegExp")
|
||||
expression.Pattern = "\\+$"
|
||||
expression.Global = False
|
||||
text = expression.Replace(text, "$&$&")
|
||||
DxEpQuote = Chr(34) & Replace(text, Chr(34), _
|
||||
Chr(92) & Chr(34)) & Chr(34)
|
||||
End Function
|
||||
|
||||
Function DxEpReadAscii(path)
|
||||
Dim stream
|
||||
Set stream = CreateObject("Scripting.FileSystemObject"). _
|
||||
@@ -285,28 +327,136 @@ Sub DxEpSleep(milliseconds)
|
||||
End Sub
|
||||
|
||||
Function DxEpResolveRoot()
|
||||
Dim fso
|
||||
Dim candidate
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
DxEpResolveRoot = ""
|
||||
On Error Resume Next
|
||||
candidate = CStr(WScript.ScriptFullName)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
DxEpResolveRoot = DxEpRootForScript(candidate)
|
||||
If DxEpResolveRoot <> "" Then Exit Function
|
||||
candidate = ""
|
||||
On Error Resume Next
|
||||
candidate = CStr(Scripting.CurrentScriptFullName)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
DxEpResolveRoot = DxEpRootForScript(candidate)
|
||||
If DxEpResolveRoot <> "" Then Exit Function
|
||||
candidate = ""
|
||||
On Error Resume Next
|
||||
candidate = CStr(Scripting.ScriptFullName)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
DxEpResolveRoot = DxEpRootForScript(candidate)
|
||||
If DxEpResolveRoot <> "" Then Exit Function
|
||||
DxEpResolveRoot = DxEpRegisteredRoot()
|
||||
End Function
|
||||
|
||||
Function DxEpRootForScript(path)
|
||||
Dim fso, root
|
||||
DxEpRootForScript = ""
|
||||
If CStr(path) = "" Then Exit Function
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
' expedition\<script> -> tool root is two levels up.
|
||||
root = fso.GetParentFolderName(fso.GetParentFolderName(CStr(path)))
|
||||
If fso.FileExists(fso.BuildPath(root, "DxDesignerTools.exe")) And _
|
||||
fso.FileExists(root & "\expedition\ExpeditionBridge.vbs") Then
|
||||
DxEpRootForScript = root
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxEpRegisteredRoot()
|
||||
Dim path
|
||||
path = CreateObject("WScript.Shell").ExpandEnvironmentStrings( _
|
||||
"%LOCALAPPDATA%\DxProductivity\startup-refactored\startup.json")
|
||||
DxEpRegisteredRoot = DxEpStartupRootFromFile(path)
|
||||
End Function
|
||||
|
||||
Function DxEpStartupRootFromFile(path)
|
||||
Dim fso, stream, text, root
|
||||
DxEpStartupRootFromFile = ""
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
If Not fso.FileExists(CStr(path)) Then Exit Function
|
||||
Set stream = Nothing
|
||||
On Error Resume Next
|
||||
Set stream = CreateObject("ADODB.Stream")
|
||||
stream.Type = 2
|
||||
stream.Charset = "utf-8"
|
||||
stream.Open
|
||||
stream.LoadFromFile CStr(path)
|
||||
text = stream.ReadText
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
candidate = CStr(Scripting.ScriptFullName)
|
||||
If Not stream Is Nothing Then stream.Close
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Function
|
||||
End If
|
||||
stream.Close
|
||||
On Error GoTo 0
|
||||
If candidate <> "" Then
|
||||
' expedition\<script> -> tool root is two levels up
|
||||
DxEpResolveRoot = fso.GetParentFolderName( _
|
||||
fso.GetParentFolderName(candidate))
|
||||
If Not fso.FileExists(fso.BuildPath( _
|
||||
DxEpResolveRoot, "DxDesignerTools.exe")) Then
|
||||
DxEpResolveRoot = ""
|
||||
End If
|
||||
If Not DxEpJsonString(text, "tool_root", root) Then Exit Function
|
||||
If fso.FileExists(fso.BuildPath(root, "DxDesignerTools.exe")) And _
|
||||
fso.FileExists(root & "\expedition\ExpeditionBridge.vbs") Then
|
||||
DxEpStartupRootFromFile = root
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxEpJsonString(jsonText, key, ByRef value)
|
||||
Dim marker, markerAt, colonAt, quoteAt, index, character, escaped
|
||||
Dim hexValue, expression
|
||||
DxEpJsonString = False
|
||||
marker = Chr(34) & CStr(key) & Chr(34)
|
||||
markerAt = InStr(1, CStr(jsonText), marker, vbBinaryCompare)
|
||||
If markerAt = 0 Then Exit Function
|
||||
colonAt = InStr(markerAt + Len(marker), CStr(jsonText), ":")
|
||||
If colonAt = 0 Then Exit Function
|
||||
quoteAt = colonAt + 1
|
||||
Do While quoteAt <= Len(CStr(jsonText))
|
||||
character = Mid(CStr(jsonText), quoteAt, 1)
|
||||
If InStr(" " & vbTab & vbCr & vbLf, character) = 0 Then Exit Do
|
||||
quoteAt = quoteAt + 1
|
||||
Loop
|
||||
If Mid(CStr(jsonText), quoteAt, 1) <> Chr(34) Then Exit Function
|
||||
escaped = False
|
||||
value = ""
|
||||
For index = quoteAt + 1 To Len(CStr(jsonText))
|
||||
character = Mid(CStr(jsonText), index, 1)
|
||||
If escaped Then
|
||||
Select Case character
|
||||
Case Chr(34), Chr(92), "/"
|
||||
value = value & character
|
||||
Case "r"
|
||||
value = value & vbCr
|
||||
Case "n"
|
||||
value = value & vbLf
|
||||
Case "t"
|
||||
value = value & vbTab
|
||||
Case "b"
|
||||
value = value & Chr(8)
|
||||
Case "f"
|
||||
value = value & Chr(12)
|
||||
Case "u"
|
||||
hexValue = Mid(CStr(jsonText), index + 1, 4)
|
||||
Set expression = CreateObject("VBScript.RegExp")
|
||||
expression.Pattern = "^[0-9A-Fa-f]{4}$"
|
||||
If Not expression.Test(hexValue) Then Exit Function
|
||||
value = value & ChrW(CLng("&H" & hexValue))
|
||||
index = index + 4
|
||||
Case Else
|
||||
Exit Function
|
||||
End Select
|
||||
escaped = False
|
||||
ElseIf character = Chr(92) Then
|
||||
escaped = True
|
||||
ElseIf character = Chr(34) Then
|
||||
DxEpJsonString = True
|
||||
Exit Function
|
||||
Else
|
||||
value = value & character
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function DxEpGetLicensedDoc(app)
|
||||
On Error Resume Next
|
||||
Dim key, licenseServer, licenseToken, docObj
|
||||
|
||||
Reference in new issue
Block a user