feat: add complete yiyezhqiu productivity suite
This commit is contained in:
commit
e422ca8b2a
155 files changed
+18959
No files matched your search
@@ -0,0 +1,228 @@
|
||||
' Shared DxDesigner 7.9.5 bridge helpers. Keep this file ASCII-only.
|
||||
|
||||
Function DxToolsQuote(value)
|
||||
Dim text
|
||||
Dim expression
|
||||
text = CStr(value)
|
||||
' Double any trailing backslashes so they cannot escape the closing quote.
|
||||
Set expression = CreateObject("VBScript.RegExp")
|
||||
expression.Pattern = "\\+$"
|
||||
expression.Global = False
|
||||
text = expression.Replace(text, "$&$&")
|
||||
DxToolsQuote = Chr(34) & Replace(text, Chr(34), _
|
||||
Chr(92) & Chr(34)) & Chr(34)
|
||||
End Function
|
||||
|
||||
Function DxToolsJson(value)
|
||||
Dim text
|
||||
text = CStr(value)
|
||||
text = Replace(text, Chr(92), Chr(92) & Chr(92))
|
||||
text = Replace(text, Chr(34), Chr(92) & Chr(34))
|
||||
text = Replace(text, vbCr, Chr(92) & "r")
|
||||
text = Replace(text, vbLf, Chr(92) & "n")
|
||||
text = Replace(text, vbTab, Chr(92) & "t")
|
||||
DxToolsJson = text
|
||||
End Function
|
||||
|
||||
Function DxToolsReadUtf8(path)
|
||||
Dim stream
|
||||
Set stream = CreateObject("ADODB.Stream")
|
||||
stream.Type = 2
|
||||
stream.Charset = "utf-8"
|
||||
stream.Open
|
||||
stream.LoadFromFile CStr(path)
|
||||
DxToolsReadUtf8 = stream.ReadText
|
||||
stream.Close
|
||||
End Function
|
||||
|
||||
Sub DxToolsWriteUtf8Atomic(path, text)
|
||||
Dim stream
|
||||
Dim temporaryPath
|
||||
Dim shell
|
||||
Dim commandLine
|
||||
Dim exitCode
|
||||
|
||||
temporaryPath = CStr(path) & ".tmp"
|
||||
Set stream = CreateObject("ADODB.Stream")
|
||||
stream.Type = 2
|
||||
stream.Charset = "utf-8"
|
||||
stream.Open
|
||||
stream.WriteText CStr(text)
|
||||
stream.SaveToFile temporaryPath, 2
|
||||
stream.Close
|
||||
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
commandLine = DxToolsQuote(shell.ExpandEnvironmentStrings("%ComSpec%")) & _
|
||||
" /d /s /c " & Chr(34) & "move /y " & _
|
||||
DxToolsQuote(temporaryPath) & " " & DxToolsQuote(path) & _
|
||||
" >nul" & Chr(34)
|
||||
exitCode = shell.Run(commandLine, 0, True)
|
||||
If exitCode <> 0 Then
|
||||
Err.Raise vbObjectError + 795, "DxToolsWriteUtf8Atomic", _
|
||||
"Cannot replace bridge file: " & CStr(path)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Function DxToolsParseScheduleRow(line, ByRef sequence, ByRef op, _
|
||||
ByRef bridgeId, ByRef propertyName, ByRef expectedValue, _
|
||||
ByRef newValue, ByRef finalValue)
|
||||
Dim fields
|
||||
Dim field
|
||||
|
||||
DxToolsParseScheduleRow = False
|
||||
fields = Split(CStr(line), vbTab)
|
||||
If UBound(fields) <> 6 Then Exit Function
|
||||
If Not IsNumeric(fields(0)) Then Exit Function
|
||||
If CLng(fields(0)) < 1 Then Exit Function
|
||||
If Len(fields(2)) = 0 Then Exit Function
|
||||
For Each field In fields
|
||||
If InStr(field, vbCr) > 0 Or InStr(field, vbLf) > 0 Then Exit Function
|
||||
Next
|
||||
|
||||
sequence = CLng(fields(0))
|
||||
op = CStr(fields(1))
|
||||
bridgeId = CStr(fields(2))
|
||||
propertyName = CStr(fields(3))
|
||||
expectedValue = CStr(fields(4))
|
||||
newValue = CStr(fields(5))
|
||||
finalValue = CStr(fields(6))
|
||||
DxToolsParseScheduleRow = True
|
||||
End Function
|
||||
|
||||
Function DxToolsSha256File(path)
|
||||
Dim shell
|
||||
Dim fso
|
||||
Dim certutilPath
|
||||
Dim outputPath
|
||||
Dim commandLine
|
||||
Dim exitCode
|
||||
Dim output
|
||||
Dim expression
|
||||
Dim matches
|
||||
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
certutilPath = shell.ExpandEnvironmentStrings( _
|
||||
"%SystemRoot%\System32\certutil.exe")
|
||||
outputPath = CStr(path) & ".sha256.txt"
|
||||
commandLine = DxToolsQuote(certutilPath) & " -hashfile " & _
|
||||
DxToolsQuote(path) & " SHA256 > " & DxToolsQuote(outputPath)
|
||||
exitCode = shell.Run(DxToolsQuote( _
|
||||
shell.ExpandEnvironmentStrings("%ComSpec%")) & _
|
||||
" /d /s /c " & Chr(34) & commandLine & Chr(34), 0, True)
|
||||
If exitCode <> 0 Then
|
||||
Err.Raise vbObjectError + 796, "DxToolsSha256File", _
|
||||
"Cannot calculate result digest"
|
||||
End If
|
||||
|
||||
output = fso.OpenTextFile(outputPath, 1, False, 0).ReadAll
|
||||
fso.DeleteFile outputPath, True
|
||||
Set expression = CreateObject("VBScript.RegExp")
|
||||
expression.Pattern = "[0-9A-Fa-f]{64}"
|
||||
expression.Global = False
|
||||
Set matches = expression.Execute(output)
|
||||
If matches.Count <> 1 Then
|
||||
Err.Raise vbObjectError + 797, "DxToolsSha256File", _
|
||||
"SHA-256 output is invalid"
|
||||
End If
|
||||
DxToolsSha256File = LCase(matches.Item(0).Value)
|
||||
End Function
|
||||
|
||||
Function DxToolsJsonString(jsonText, key, ByRef value)
|
||||
Dim marker
|
||||
Dim markerAt
|
||||
Dim colonAt
|
||||
Dim quoteAt
|
||||
Dim index
|
||||
Dim character
|
||||
Dim escaped
|
||||
|
||||
DxToolsJsonString = 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 = InStr(colonAt + 1, CStr(jsonText), Chr(34))
|
||||
If quoteAt = 0 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 Else
|
||||
Exit Function
|
||||
End Select
|
||||
escaped = False
|
||||
ElseIf character = Chr(92) Then
|
||||
escaped = True
|
||||
ElseIf character = Chr(34) Then
|
||||
DxToolsJsonString = True
|
||||
Exit Function
|
||||
Else
|
||||
value = value & character
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
Sub DxBridgeEnsureFolder(path)
|
||||
Dim fso
|
||||
Dim parent
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
If fso.FolderExists(CStr(path)) Then Exit Sub
|
||||
parent = fso.GetParentFolderName(CStr(path))
|
||||
If parent <> "" And Not fso.FolderExists(parent) Then
|
||||
Call DxBridgeEnsureFolder(parent)
|
||||
End If
|
||||
On Error Resume Next
|
||||
fso.CreateFolder CStr(path)
|
||||
If Err.Number <> 0 And Err.Number <> 58 Then
|
||||
On Error GoTo 0
|
||||
Err.Raise vbObjectError + 798, "DxBridgeEnsureFolder", _
|
||||
"Cannot create folder: " & CStr(path)
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Function DxBridgeNormalizeVisible(value)
|
||||
Dim text
|
||||
If IsEmpty(value) Or IsNull(value) Then
|
||||
DxBridgeNormalizeVisible = "0"
|
||||
Exit Function
|
||||
End If
|
||||
If VarType(value) = vbBoolean Then
|
||||
If CBool(value) Then
|
||||
DxBridgeNormalizeVisible = "1"
|
||||
Else
|
||||
DxBridgeNormalizeVisible = "0"
|
||||
End If
|
||||
Exit Function
|
||||
End If
|
||||
text = LCase(Trim(CStr(value)))
|
||||
If text = "0" Or text = "" Or text = "false" Then
|
||||
DxBridgeNormalizeVisible = "0"
|
||||
Else
|
||||
DxBridgeNormalizeVisible = "1"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Sub DxBridgeIdleWait()
|
||||
Dim shell
|
||||
On Error Resume Next
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
shell.Run "%ComSpec% /d /s /c ping -n 2 -w 400 127.0.0.1 > nul", 0, True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Call DxBridgeYield()
|
||||
End Sub
|
||||
@@ -0,0 +1,295 @@
|
||||
' DxDesigner 7.9.5 read-only compatibility probe. Keep this file ASCII-only.
|
||||
|
||||
Sub DxToolsRunCompatibilityProbe()
|
||||
Call DxToolsProbeExecute("named")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsProbeExecute(routeName)
|
||||
Dim payload
|
||||
Dim outputPath
|
||||
Dim shell
|
||||
Dim process
|
||||
Dim commandLine
|
||||
Dim yieldMethod
|
||||
Dim retainedComponent
|
||||
Dim retainedOk
|
||||
Dim executablePath
|
||||
|
||||
payload = DxToolsProbeCapabilities(retainedComponent)
|
||||
outputPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings( _
|
||||
"%LOCALAPPDATA%\DxProductivity\compatibility.json")
|
||||
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
executablePath = DxToolsHome & "\DxDesignerTools.exe"
|
||||
commandLine = DxToolsProbeQuote(executablePath) & " probe" & _
|
||||
" --output " & DxToolsProbeQuote(outputPath) & _
|
||||
" --route " & routeName & _
|
||||
" --payload-json " & DxToolsProbeQuote(payload) & _
|
||||
" --hold-seconds 1.5"
|
||||
|
||||
On Error Resume Next
|
||||
Set process = shell.Exec(commandLine)
|
||||
If Err.Number <> 0 Then
|
||||
Dim launchError
|
||||
launchError = Err.Description
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
MsgBox DxToolsProbePythonError() & vbCrLf & launchError, vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
On Error GoTo 0
|
||||
|
||||
yieldMethod = DxToolsProbePumpWhileRunning(process)
|
||||
retainedOk = DxToolsProbeRetainedReferenceReadable(retainedComponent)
|
||||
payload = DxToolsProbeAppendResult(payload, yieldMethod, retainedOk)
|
||||
|
||||
commandLine = DxToolsProbeQuote(executablePath) & " probe" & _
|
||||
" --output " & DxToolsProbeQuote(outputPath) & _
|
||||
" --route " & routeName & _
|
||||
" --payload-json " & DxToolsProbeQuote(payload)
|
||||
Set process = shell.Exec(commandLine)
|
||||
Call DxToolsProbeWait(process, yieldMethod)
|
||||
|
||||
If process.ExitCode = 0 Then
|
||||
MsgBox DxToolsProbeCompleteMessage() & vbCrLf & outputPath, vbInformation
|
||||
Else
|
||||
MsgBox DxToolsProbePythonError(), vbExclamation
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Function DxToolsProbeCapabilities(ByRef retainedComponent)
|
||||
Dim selectedOk
|
||||
Dim selectedCount
|
||||
Dim fullOk
|
||||
Dim fullCount
|
||||
Dim refdesOk
|
||||
Dim uidOk
|
||||
Dim attributesOk
|
||||
Dim sheetOk
|
||||
Dim pathMethod
|
||||
Dim positionMethod
|
||||
Dim sample
|
||||
|
||||
selectedOk = DxToolsProbeSelected(sample, selectedCount)
|
||||
fullOk = DxToolsProbeFullDesign(retainedComponent, fullCount)
|
||||
If sample Is Nothing Then Set sample = retainedComponent
|
||||
|
||||
refdesOk = DxToolsProbeProperty(sample, "refdes")
|
||||
uidOk = DxToolsProbeProperty(sample, "uid")
|
||||
attributesOk = DxToolsProbeProperty(sample, "attributes")
|
||||
sheetOk = DxToolsProbeSheetNumber()
|
||||
pathMethod = DxToolsProbePathMethod(sample)
|
||||
positionMethod = DxToolsProbePositionMethod(sample)
|
||||
|
||||
DxToolsProbeCapabilities = "{" & _
|
||||
"""script_path_source"":""" & _
|
||||
DxToolsProbeJson(DxToolsScriptPathSource) & """," & _
|
||||
"""script_path"":""" & DxToolsProbeJson(DxToolsScriptFullName) & _
|
||||
"""," & _
|
||||
"""portable_root_valid"":" & _
|
||||
DxToolsProbeBoolean(DxToolsHome <> "") & "," & _
|
||||
"""selected_query"":" & DxToolsProbeBoolean(selectedOk) & "," & _
|
||||
"""selected_count"":" & CStr(selectedCount) & "," & _
|
||||
"""full_design_enumeration"":" & DxToolsProbeBoolean(fullOk) & "," & _
|
||||
"""full_design_count"":" & CStr(fullCount) & "," & _
|
||||
"""refdes_readable"":" & DxToolsProbeBoolean(refdesOk) & "," & _
|
||||
"""uid_readable"":" & DxToolsProbeBoolean(uidOk) & "," & _
|
||||
"""attributes_readable"":" & DxToolsProbeBoolean(attributesOk) & "," & _
|
||||
"""sheet_number_readable"":" & DxToolsProbeBoolean(sheetOk) & "," & _
|
||||
"""path_method"":""" & DxToolsProbeJson(pathMethod) & """," & _
|
||||
"""position_method"":""" & DxToolsProbeJson(positionMethod) & """}"
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeSelected(ByRef sample, ByRef count)
|
||||
Dim comp
|
||||
count = 0
|
||||
Set sample = Nothing
|
||||
On Error Resume Next
|
||||
For Each comp In ActiveView.Query(VDM_COMP, VD_SELECTED)
|
||||
count = count + 1
|
||||
If sample Is Nothing Then Set sample = comp
|
||||
Next
|
||||
DxToolsProbeSelected = (Err.Number = 0)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeFullDesign(ByRef sample, ByRef count)
|
||||
Dim projectData
|
||||
Dim designs
|
||||
Dim designName
|
||||
Dim topBlock
|
||||
Dim comp
|
||||
count = 0
|
||||
Set sample = Nothing
|
||||
On Error Resume Next
|
||||
Set projectData = Application.GetProjectData()
|
||||
Set designs = projectData.GetiCDBDesigns()
|
||||
designName = designs.GetItem(1)
|
||||
topBlock = projectData.GetiCDBDesignRootBlock(designName)
|
||||
For Each comp In Application.DesignComponents("", topBlock, "-1", "STD", True)
|
||||
count = count + 1
|
||||
If sample Is Nothing Then Set sample = comp
|
||||
Next
|
||||
DxToolsProbeFullDesign = (Err.Number = 0)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeProperty(comp, propertyName)
|
||||
Dim ignored
|
||||
DxToolsProbeProperty = False
|
||||
If comp Is Nothing Then Exit Function
|
||||
On Error Resume Next
|
||||
Select Case propertyName
|
||||
Case "refdes"
|
||||
ignored = CStr(comp.Refdes)
|
||||
Case "uid"
|
||||
ignored = CStr(comp.UID)
|
||||
Case "attributes"
|
||||
ignored = comp.Attributes.Count
|
||||
End Select
|
||||
DxToolsProbeProperty = (Err.Number = 0)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeSheetNumber()
|
||||
Dim ignored
|
||||
On Error Resume Next
|
||||
ignored = CStr(ActiveView.Block.SheetNum)
|
||||
DxToolsProbeSheetNumber = (Err.Number = 0)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsProbePathMethod(comp)
|
||||
Dim ignored
|
||||
DxToolsProbePathMethod = ""
|
||||
If comp Is Nothing Then Exit Function
|
||||
|
||||
On Error Resume Next
|
||||
ignored = CStr(comp.Parent) & "\" & CStr(comp.GetName(SHORT_NAME))
|
||||
If Err.Number = 0 Then DxToolsProbePathMethod = "Parent+GetName(SHORT_NAME)"
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsProbePositionMethod(comp)
|
||||
Dim x
|
||||
Dim y
|
||||
DxToolsProbePositionMethod = ""
|
||||
If comp Is Nothing Then Exit Function
|
||||
|
||||
On Error Resume Next
|
||||
x = comp.X
|
||||
y = comp.Y
|
||||
If Err.Number = 0 Then DxToolsProbePositionMethod = "X/Y"
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If DxToolsProbePositionMethod <> "" Then Exit Function
|
||||
|
||||
On Error Resume Next
|
||||
x = comp.PositionX
|
||||
y = comp.PositionY
|
||||
If Err.Number = 0 Then DxToolsProbePositionMethod = "PositionX/PositionY"
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsProbePumpWhileRunning(process)
|
||||
Dim methodName
|
||||
methodName = DxToolsProbeFindYieldMethod()
|
||||
Do While process.Status = 0
|
||||
Call DxToolsProbeYield(methodName)
|
||||
Loop
|
||||
DxToolsProbePumpWhileRunning = methodName
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeFindYieldMethod()
|
||||
If DxToolsProbeTryYield("Scripting.DoEvents") Then
|
||||
DxToolsProbeFindYieldMethod = "Scripting.DoEvents"
|
||||
ElseIf DxToolsProbeTryYield("Application.DoEvents") Then
|
||||
DxToolsProbeFindYieldMethod = "Application.DoEvents"
|
||||
ElseIf DxToolsProbeTryYield("ActiveView.Refresh") Then
|
||||
DxToolsProbeFindYieldMethod = "ActiveView.Refresh"
|
||||
Else
|
||||
DxToolsProbeFindYieldMethod = ""
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeTryYield(methodName)
|
||||
On Error Resume Next
|
||||
Call DxToolsProbeYield(methodName)
|
||||
DxToolsProbeTryYield = (Err.Number = 0)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Sub DxToolsProbeYield(methodName)
|
||||
Select Case methodName
|
||||
Case "Scripting.DoEvents"
|
||||
Scripting.DoEvents
|
||||
Case "Application.DoEvents"
|
||||
Application.DoEvents
|
||||
Case "ActiveView.Refresh"
|
||||
ActiveView.Refresh
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Sub DxToolsProbeWait(process, methodName)
|
||||
Do While process.Status = 0
|
||||
Call DxToolsProbeYield(methodName)
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
Function DxToolsProbeRetainedReferenceReadable(comp)
|
||||
Dim ignored
|
||||
DxToolsProbeRetainedReferenceReadable = False
|
||||
If comp Is Nothing Then Exit Function
|
||||
On Error Resume Next
|
||||
ignored = CStr(comp.Refdes)
|
||||
DxToolsProbeRetainedReferenceReadable = (Err.Number = 0)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeAppendResult(payload, yieldMethod, retainedOk)
|
||||
DxToolsProbeAppendResult = Left(payload, Len(payload) - 1) & "," & _
|
||||
"""yield_method"":""" & DxToolsProbeJson(yieldMethod) & """," & _
|
||||
"""retained_reference"":" & DxToolsProbeBoolean(retainedOk) & "}"
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeBoolean(value)
|
||||
If CBool(value) Then
|
||||
DxToolsProbeBoolean = "true"
|
||||
Else
|
||||
DxToolsProbeBoolean = "false"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeJson(value)
|
||||
Dim text
|
||||
text = CStr(value)
|
||||
text = Replace(text, Chr(92), Chr(92) & Chr(92))
|
||||
text = Replace(text, Chr(34), Chr(92) & Chr(34))
|
||||
text = Replace(text, vbCr, Chr(92) & "r")
|
||||
text = Replace(text, vbLf, Chr(92) & "n")
|
||||
DxToolsProbeJson = text
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeQuote(value)
|
||||
DxToolsProbeQuote = Chr(34) & Replace(CStr(value), Chr(34), _
|
||||
Chr(92) & Chr(34)) & Chr(34)
|
||||
End Function
|
||||
|
||||
Function DxToolsProbeCompleteMessage()
|
||||
DxToolsProbeCompleteMessage = ChrW(&H517C) & ChrW(&H5BB9) & _
|
||||
ChrW(&H6027) & ChrW(&H68C0) & ChrW(&H6D4B) & ChrW(&H5B8C) & _
|
||||
ChrW(&H6210)
|
||||
End Function
|
||||
|
||||
Function DxToolsProbePythonError()
|
||||
DxToolsProbePythonError = ChrW(&H5DE5) & ChrW(&H5177) & _
|
||||
ChrW(&H542F) & ChrW(&H52A8) & ChrW(&H5931) & ChrW(&H8D25)
|
||||
End Function
|
||||
@@ -0,0 +1,46 @@
|
||||
' Unified design-bridge entry for DxDesigner 7.9.5. Keep this file ASCII-only.
|
||||
' Loaded by MenuAdd.vbs through ExecuteGlobal; relies on the DxToolsHome
|
||||
' global that MenuAdd resolves before any menu action runs.
|
||||
|
||||
Sub DxToolsDesignBridgeEnsureCore()
|
||||
If Not IsEmpty(DxToolsDesignBridgeCoreLoaded) Then Exit Sub
|
||||
If DxToolsHome = "" Then
|
||||
MsgBox DxToolsPathErrorMessage(), vbExclamation
|
||||
Err.Raise vbObjectError + 799, "DxToolsDesignBridgeEnsureCore", _
|
||||
"DxToolsHome is not resolved"
|
||||
End If
|
||||
Dim fso
|
||||
Dim coreRoot
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
coreRoot = fso.BuildPath(DxToolsHome, "_runtime\vbs")
|
||||
If Not fso.FolderExists(coreRoot) Then
|
||||
coreRoot = fso.BuildPath(DxToolsHome, "core")
|
||||
End If
|
||||
Call DxToolsLoadScript(fso.BuildPath(coreRoot, "Snapshot.vbs"))
|
||||
Call DxToolsLoadScript(fso.BuildPath(coreRoot, "Transaction.vbs"))
|
||||
Call DxToolsLoadScript(fso.BuildPath(coreRoot, "Mailbox.vbs"))
|
||||
Call DxToolsLoadScript(fso.BuildPath(coreRoot, "BomExport.vbs"))
|
||||
DxToolsDesignBridgeCoreLoaded = True
|
||||
End Sub
|
||||
|
||||
Sub DxToolsRunDesignBridge(featureKey)
|
||||
If DxToolsHome = "" Then
|
||||
MsgBox DxToolsPathErrorMessage(), vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
On Error Resume Next
|
||||
Call DxToolsDesignBridgeEnsureCore()
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
On Error GoTo 0
|
||||
Call DxToolsDesignBridgeStart(CStr(featureKey))
|
||||
End Sub
|
||||
|
||||
Function DxToolsPathErrorMessage()
|
||||
DxToolsPathErrorMessage = ChrW(&H65E0) & ChrW(&H6CD5) & _
|
||||
ChrW(&H786E) & ChrW(&H5B9A) & ChrW(&H5DE5) & ChrW(&H5177) & _
|
||||
ChrW(&H76EE) & ChrW(&H5F55)
|
||||
End Function
|
||||
@@ -0,0 +1,279 @@
|
||||
' DxDesigner 7.9.5 portable startup menu. Keep this file ASCII-only.
|
||||
|
||||
Dim DxToolsHome
|
||||
Dim DxToolsScriptFullName
|
||||
Dim DxToolsScriptPathSource
|
||||
Dim DxToolsMenu
|
||||
Dim DxToolsCommonLoaded
|
||||
Dim DxToolsDesignBridgeLoaded
|
||||
Dim DxToolsProbeLoaded
|
||||
|
||||
DxToolsCommonLoaded = False
|
||||
DxToolsDesignBridgeLoaded = False
|
||||
DxToolsProbeLoaded = False
|
||||
|
||||
DxToolsHome = DxToolsResolveRoot()
|
||||
If DxToolsHome = "" Then
|
||||
MsgBox DxToolsPathErrorMessage(), vbExclamation
|
||||
Else
|
||||
Call DxToolsInstallMenu()
|
||||
End If
|
||||
|
||||
Sub DxToolsInstallMenu()
|
||||
Dim menuBar
|
||||
Dim existing
|
||||
Dim button
|
||||
Dim i
|
||||
Dim caption
|
||||
|
||||
caption = DxToolsSuiteCaption()
|
||||
Set menuBar = CommandBars("Sheet Menu Bar")
|
||||
For i = menuBar.Controls.Count To 1 Step -1
|
||||
Set existing = menuBar.Controls.Item(i)
|
||||
If existing.Caption = caption Then
|
||||
On Error Resume Next
|
||||
existing.Delete
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End If
|
||||
Next
|
||||
|
||||
Set DxToolsMenu = menuBar.Controls.Add(cmdControlPopup)
|
||||
DxToolsMenu.Caption = caption
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsRefDesCaption()
|
||||
button.OnAction = "DxToolsOpenRefDes"
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsPropertyChangeCaption()
|
||||
button.OnAction = "DxToolsOpenPropertyChange"
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsPropertyVisibilityCaption()
|
||||
button.OnAction = "DxToolsOpenPropertyVisibility"
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsInspectionCaption()
|
||||
button.OnAction = "DxToolsOpenInspection"
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsBomCaption()
|
||||
button.OnAction = "DxToolsOpenBom"
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsCompatibilityCaption()
|
||||
button.OnAction = "DxToolsOpenCompatibility"
|
||||
|
||||
Set button = DxToolsMenu.Controls.Add
|
||||
button.Caption = DxToolsGuideCaption()
|
||||
button.OnAction = "DxToolsOpenGuide"
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenRefDes()
|
||||
Call DxToolsStartFeature("refdes")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenPropertyChange()
|
||||
Call DxToolsStartFeature("property-change")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenPropertyVisibility()
|
||||
Call DxToolsStartFeature("property-visibility")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenInspection()
|
||||
Call DxToolsStartFeature("inspection")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenBom()
|
||||
Call DxToolsStartFeature("bom")
|
||||
End Sub
|
||||
|
||||
Sub DxToolsStartFeature(featureKey)
|
||||
If Not DxToolsEnsureRoot() Then Exit Sub
|
||||
Call DxToolsEnsureCommonLoaded()
|
||||
If Not DxToolsDesignBridgeLoaded Then
|
||||
Call DxToolsLoadScript(DxToolsHome & "\DesignBridge.vbs")
|
||||
DxToolsDesignBridgeLoaded = True
|
||||
End If
|
||||
Call DxToolsRunDesignBridge(CStr(featureKey))
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenCompatibility()
|
||||
If Not DxToolsEnsureRoot() Then Exit Sub
|
||||
Call DxToolsEnsureCommonLoaded()
|
||||
If Not DxToolsProbeLoaded Then
|
||||
Call DxToolsLoadScript(DxToolsHome & "\CompatibilityProbe.vbs")
|
||||
DxToolsProbeLoaded = True
|
||||
End If
|
||||
Call DxToolsRunCompatibilityProbe()
|
||||
End Sub
|
||||
|
||||
Sub DxToolsEnsureCommonLoaded()
|
||||
If DxToolsCommonLoaded Then Exit Sub
|
||||
Call DxToolsLoadScript(DxToolsHome & "\_runtime\vbs\BridgeCommon.vbs")
|
||||
DxToolsCommonLoaded = True
|
||||
End Sub
|
||||
|
||||
Sub DxToolsOpenGuide()
|
||||
Dim guidePath
|
||||
Dim shell
|
||||
If Not DxToolsEnsureRoot() Then Exit Sub
|
||||
guidePath = DxToolsHome & "\docs\DxDesigner_7.9.5_" & _
|
||||
ChrW(&H81EA) & ChrW(&H52A8) & ChrW(&H4F4D) & ChrW(&H53F7) & _
|
||||
ChrW(&H5DE5) & ChrW(&H5177) & ChrW(&H4F7F) & ChrW(&H7528) & _
|
||||
ChrW(&H8BF4) & ChrW(&H660E) & ".docx"
|
||||
If Not CreateObject("Scripting.FileSystemObject").FileExists(guidePath) Then
|
||||
MsgBox DxToolsGuideMissingMessage(), vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
shell.Run Chr(34) & guidePath & Chr(34), 1, False
|
||||
End Sub
|
||||
|
||||
Function DxToolsEnsureRoot()
|
||||
If DxToolsHome = "" Then DxToolsHome = DxToolsResolveRoot()
|
||||
DxToolsEnsureRoot = (DxToolsHome <> "")
|
||||
If Not DxToolsEnsureRoot Then
|
||||
MsgBox DxToolsPathErrorMessage(), vbExclamation
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxToolsResolveRoot()
|
||||
Dim candidate
|
||||
|
||||
DxToolsResolveRoot = ""
|
||||
DxToolsScriptFullName = ""
|
||||
DxToolsScriptPathSource = ""
|
||||
|
||||
candidate = DxToolsWScriptFullName()
|
||||
If DxToolsAcceptScriptPath(candidate, "WScript.ScriptFullName") Then
|
||||
DxToolsResolveRoot = DxToolsParentFolder(candidate)
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
candidate = DxToolsCurrentScriptFullName()
|
||||
If DxToolsAcceptScriptPath(candidate, _
|
||||
"Scripting.CurrentScriptFullName") Then
|
||||
DxToolsResolveRoot = DxToolsParentFolder(candidate)
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
candidate = DxToolsScriptingScriptFullName()
|
||||
If DxToolsAcceptScriptPath(candidate, "Scripting.ScriptFullName") Then
|
||||
DxToolsResolveRoot = DxToolsParentFolder(candidate)
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxToolsWScriptFullName()
|
||||
DxToolsWScriptFullName = ""
|
||||
On Error Resume Next
|
||||
DxToolsWScriptFullName = CStr(WScript.ScriptFullName)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsCurrentScriptFullName()
|
||||
DxToolsCurrentScriptFullName = ""
|
||||
On Error Resume Next
|
||||
DxToolsCurrentScriptFullName = CStr(Scripting.CurrentScriptFullName)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsScriptingScriptFullName()
|
||||
DxToolsScriptingScriptFullName = ""
|
||||
On Error Resume Next
|
||||
DxToolsScriptingScriptFullName = CStr(Scripting.ScriptFullName)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxToolsAcceptScriptPath(path, sourceName)
|
||||
Dim root
|
||||
Dim fso
|
||||
DxToolsAcceptScriptPath = False
|
||||
If Len(CStr(path)) = 0 Then Exit Function
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
If Not fso.FileExists(CStr(path)) Then Exit Function
|
||||
root = fso.GetParentFolderName(CStr(path))
|
||||
If Not fso.FileExists(fso.BuildPath(root, "DxDesignerTools.exe")) Then _
|
||||
Exit Function
|
||||
If Not fso.FileExists(fso.BuildPath(root, "DesignBridge.vbs")) Then _
|
||||
Exit Function
|
||||
DxToolsScriptFullName = CStr(path)
|
||||
DxToolsScriptPathSource = CStr(sourceName)
|
||||
DxToolsAcceptScriptPath = True
|
||||
End Function
|
||||
|
||||
Function DxToolsParentFolder(path)
|
||||
DxToolsParentFolder = CreateObject( _
|
||||
"Scripting.FileSystemObject").GetParentFolderName(CStr(path))
|
||||
End Function
|
||||
|
||||
Sub DxToolsLoadScript(path)
|
||||
Dim fso
|
||||
Dim stream
|
||||
Dim text
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
If Not fso.FileExists(CStr(path)) Then
|
||||
Err.Raise vbObjectError + 795, "DxToolsLoadScript", _
|
||||
"Missing script: " & CStr(path)
|
||||
End If
|
||||
Set stream = fso.OpenTextFile(CStr(path), 1, False, 0)
|
||||
text = stream.ReadAll
|
||||
stream.Close
|
||||
ExecuteGlobal text
|
||||
End Sub
|
||||
|
||||
Function DxToolsSuiteCaption()
|
||||
DxToolsSuiteCaption = "Dx " & ChrW(&H6548) & ChrW(&H7387) & _
|
||||
ChrW(&H5DE5) & ChrW(&H5177)
|
||||
End Function
|
||||
|
||||
Function DxToolsRefDesCaption()
|
||||
DxToolsRefDesCaption = ChrW(&H81EA) & ChrW(&H52A8) & ChrW(&H4F4D) & _
|
||||
ChrW(&H53F7)
|
||||
End Function
|
||||
|
||||
Function DxToolsPropertyChangeCaption()
|
||||
DxToolsPropertyChangeCaption = ChrW(&H5C5E) & ChrW(&H6027) & _
|
||||
ChrW(&H6279) & ChrW(&H6539)
|
||||
End Function
|
||||
|
||||
Function DxToolsPropertyVisibilityCaption()
|
||||
DxToolsPropertyVisibilityCaption = ChrW(&H5C5E) & ChrW(&H6027) & _
|
||||
ChrW(&H663E) & ChrW(&H793A)
|
||||
End Function
|
||||
|
||||
Function DxToolsInspectionCaption()
|
||||
DxToolsInspectionCaption = ChrW(&H8BBE) & ChrW(&H8BA1) & _
|
||||
ChrW(&H68C0) & ChrW(&H67E5)
|
||||
End Function
|
||||
|
||||
Function DxToolsBomCaption()
|
||||
DxToolsBomCaption = "BOM " & ChrW(&H5BFC) & ChrW(&H51FA)
|
||||
End Function
|
||||
|
||||
Function DxToolsCompatibilityCaption()
|
||||
DxToolsCompatibilityCaption = ChrW(&H517C) & ChrW(&H5BB9) & _
|
||||
ChrW(&H6027) & ChrW(&H68C0) & ChrW(&H6D4B)
|
||||
End Function
|
||||
|
||||
Function DxToolsGuideCaption()
|
||||
DxToolsGuideCaption = ChrW(&H4F7F) & ChrW(&H7528) & ChrW(&H8BF4) & _
|
||||
ChrW(&H660E)
|
||||
End Function
|
||||
|
||||
Function DxToolsPathErrorMessage()
|
||||
DxToolsPathErrorMessage = ChrW(&H65E0) & ChrW(&H6CD5) & _
|
||||
ChrW(&H786E) & ChrW(&H5B9A) & ChrW(&H5DE5) & ChrW(&H5177) & _
|
||||
ChrW(&H76EE) & ChrW(&H5F55)
|
||||
End Function
|
||||
|
||||
Function DxToolsGuideMissingMessage()
|
||||
DxToolsGuideMissingMessage = ChrW(&H4F7F) & ChrW(&H7528) & _
|
||||
ChrW(&H8BF4) & ChrW(&H660E) & ChrW(&H6587) & ChrW(&H4EF6) & _
|
||||
ChrW(&H4E0D) & ChrW(&H5B58) & ChrW(&H5728)
|
||||
End Function
|
||||
@@ -0,0 +1,2 @@
|
||||
' DxDesigner 7.9.5 Run-route trampoline. Keep this file ASCII-only.
|
||||
Call DxToolsProbeExecute("run")
|
||||
@@ -0,0 +1,125 @@
|
||||
' BOM Excel renderer for the DxDesigner 7.9.5 bridge. Keep this file ASCII-only.
|
||||
' Reads a claimed bom-export.json payload, drives Excel COM exactly like the
|
||||
' legacy PLBOM form did (template + colors + save-as), and writes
|
||||
' bom-export-status.json for the GUI.
|
||||
|
||||
Sub DxBridgeRenderBom(runRoot, claimedPath)
|
||||
Dim text
|
||||
Dim payload
|
||||
Dim statusState
|
||||
Dim statusError
|
||||
|
||||
statusState = "ok"
|
||||
statusError = ""
|
||||
On Error Resume Next
|
||||
text = DxToolsReadUtf8(claimedPath)
|
||||
If Err.Number <> 0 Then
|
||||
statusState = "failed"
|
||||
statusError = "cannot read export payload"
|
||||
Err.Clear
|
||||
Else
|
||||
Call DxBomRenderPayload(text, statusState, statusError)
|
||||
End If
|
||||
If Err.Number <> 0 Then
|
||||
statusState = "failed"
|
||||
statusError = Err.Description
|
||||
Err.Clear
|
||||
End If
|
||||
On Error GoTo 0
|
||||
Call DxBomWriteStatus(runRoot, statusState, statusError)
|
||||
End Sub
|
||||
|
||||
Sub DxBomRenderPayload(text, ByRef statusState, ByRef statusError)
|
||||
Dim templatePath
|
||||
Dim outputPath
|
||||
Dim designName
|
||||
Dim descriptionHeader
|
||||
Dim excel
|
||||
Dim workbooks
|
||||
Dim workbook
|
||||
Dim sheet
|
||||
Dim saveFormat
|
||||
|
||||
Call DxBomField(text, "template_path", templatePath)
|
||||
Call DxBomField(text, "output_path", outputPath)
|
||||
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
|
||||
Set workbook = workbooks.Open(CStr(templatePath), 3, True)
|
||||
Set sheet = workbook.Sheets("Sheet1")
|
||||
|
||||
sheet.Cells(1, 1).Value = designName
|
||||
sheet.Cells(1, 2).Value = "QTY"
|
||||
sheet.Cells(1, 3).Value = "REFDES"
|
||||
sheet.Cells(1, 4).Value = "PART NUMBER"
|
||||
sheet.Cells(1, 5).Value = UCase(descriptionHeader)
|
||||
|
||||
Call DxBomWriteSections(excel, sheet, text)
|
||||
|
||||
If LCase(Right(CStr(outputPath), 5)) = ".xlsx" Then
|
||||
saveFormat = 51
|
||||
Else
|
||||
saveFormat = 56
|
||||
End If
|
||||
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 line
|
||||
Dim parts
|
||||
Dim rowIndex
|
||||
Dim flagParts
|
||||
rowIndex = 2
|
||||
lines = Split(Replace(CStr(text), vbCr, ""), vbLf)
|
||||
For Each line In lines
|
||||
If Left(line, 2) = "S|" Then
|
||||
sheet.Cells(rowIndex, 1).Value = Mid(line, 3)
|
||||
sheet.Cells(rowIndex, 1).Font.Bold = True
|
||||
rowIndex = rowIndex + 1
|
||||
ElseIf Left(line, 2) = "R|" Then
|
||||
parts = Split(line, "|")
|
||||
sheet.Cells(rowIndex, 2).Value = CLng(parts(1))
|
||||
sheet.Cells(rowIndex, 3).Value = parts(2)
|
||||
sheet.Cells(rowIndex, 4).Value = "'" & parts(3)
|
||||
sheet.Cells(rowIndex, 5).Value = "'" & parts(4)
|
||||
If InStr(parts(5), "D") > 0 Then
|
||||
sheet.Cells(rowIndex, 3).Interior.ColorIndex = 3
|
||||
End If
|
||||
If InStr(parts(5), "M") > 0 Then
|
||||
sheet.Cells(rowIndex, 4).Interior.ColorIndex = 44
|
||||
End If
|
||||
rowIndex = rowIndex + 1
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Sub DxBomField(text, key, ByRef value)
|
||||
If DxToolsJsonString(text, key, value) Then Exit Sub
|
||||
value = ""
|
||||
End Sub
|
||||
|
||||
Sub DxBomWriteStatus(runRoot, state, errorText)
|
||||
Dim errorValue
|
||||
If errorText = "" Then
|
||||
errorValue = "null"
|
||||
Else
|
||||
errorValue = """" & DxToolsJson(errorText) & """"
|
||||
End If
|
||||
Call DxToolsWriteUtf8Atomic(runRoot & "\bom-export-status.json", _
|
||||
"{" & vbCrLf & _
|
||||
" ""format_version"": 2," & vbCrLf & _
|
||||
" ""state"": """ & DxToolsJson(state) & """," & vbCrLf & _
|
||||
" ""error"": " & errorValue & vbCrLf & _
|
||||
"}" & vbCrLf)
|
||||
End Sub
|
||||
@@ -0,0 +1,373 @@
|
||||
' Mailbox pump for the DxDesigner 7.9.5 bridge: multi-consume apply loop,
|
||||
' locate navigation, snapshot refresh requests, heartbeat, and run cleanup.
|
||||
' Keep this file ASCII-only.
|
||||
|
||||
Sub DxToolsDesignBridgeStart(featureKey)
|
||||
Dim objectMap
|
||||
Dim originalMap
|
||||
Dim runRoot
|
||||
Dim runId
|
||||
Dim snapshotId
|
||||
Dim process
|
||||
Dim state
|
||||
|
||||
Set objectMap = CreateObject("Scripting.Dictionary")
|
||||
Set originalMap = CreateObject("Scripting.Dictionary")
|
||||
If Not DxExportSnapshot(objectMap, originalMap, runRoot, runId, _
|
||||
snapshotId) Then Exit Sub
|
||||
Call DxBridgeCleanupRuns(DxBridgeRunsRoot(), CStr(runId))
|
||||
Set process = DxLaunchUi(runRoot, featureKey)
|
||||
If process Is Nothing Then Exit Sub
|
||||
Call DxWriteProgress(runRoot, "waiting")
|
||||
state = DxBridgeMailboxLoop(process, runRoot, runId, snapshotId, _
|
||||
objectMap, originalMap)
|
||||
If state <> "" Then
|
||||
MsgBox DxBridgeStateMessage(state), _
|
||||
IIf(state = "applied", vbInformation, vbExclamation)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Function DxBridgeRunsRoot()
|
||||
Dim shell
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
DxBridgeRunsRoot = shell.ExpandEnvironmentStrings( _
|
||||
"%LOCALAPPDATA%\DxProductivity\runs")
|
||||
End Function
|
||||
|
||||
Function DxLaunchUi(runRoot, featureKey)
|
||||
Dim fso
|
||||
Dim shell
|
||||
Dim process
|
||||
Dim executablePath
|
||||
Dim launchError
|
||||
|
||||
Set DxLaunchUi = Nothing
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
executablePath = DxToolsHome & "\DxDesignerTools.exe"
|
||||
If Not fso.FileExists(executablePath) Then
|
||||
MsgBox DxBridgeMissingExecutableMessage() & vbCrLf & _
|
||||
executablePath, vbExclamation
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
launchError = ""
|
||||
On Error Resume Next
|
||||
Set process = shell.Exec(DxBridgeUiCommand(runRoot, featureKey))
|
||||
If Err.Number <> 0 Then launchError = Err.Description
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If launchError <> "" Then
|
||||
MsgBox DxBridgeLaunchErrorMessage() & vbCrLf & launchError, _
|
||||
vbExclamation
|
||||
Exit Function
|
||||
End If
|
||||
Set DxLaunchUi = process
|
||||
End Function
|
||||
|
||||
Function DxBridgeUiCommand(runRoot, featureKey)
|
||||
Dim featureSuffix
|
||||
featureSuffix = ""
|
||||
If CStr(featureKey) <> "" Then
|
||||
featureSuffix = " --feature " & DxToolsQuote(CStr(featureKey))
|
||||
End If
|
||||
DxBridgeUiCommand = DxToolsQuote( _
|
||||
DxToolsHome & "\DxDesignerTools.exe") & _
|
||||
" ui --request " & DxToolsQuote(runRoot & "\request.json") & _
|
||||
featureSuffix
|
||||
End Function
|
||||
|
||||
Function DxBridgeMailboxLoop(process, runRoot, runId, snapshotId, _
|
||||
objectMap, originalMap)
|
||||
Dim fso
|
||||
Dim resultPath
|
||||
Dim claimPath
|
||||
Dim state
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
resultPath = fso.BuildPath(runRoot, "result.tsv")
|
||||
claimPath = fso.BuildPath(runRoot, "result.processing")
|
||||
state = ""
|
||||
|
||||
Do While process.Status = 0
|
||||
Call DxBridgeConsumeLocate(runRoot, objectMap)
|
||||
Call DxBridgePumpRefresh(runRoot, runId, objectMap, originalMap, _
|
||||
snapshotId)
|
||||
Call DxBridgePumpBomExport(runRoot)
|
||||
Call DxBridgeWriteProgress(runRoot, "waiting")
|
||||
If fso.FileExists(resultPath) Then
|
||||
If DxBridgeClaimFile(fso, resultPath, claimPath) Then
|
||||
Call DxWriteProgress(runRoot, "processing")
|
||||
state = DxProcessApply(runRoot, runId, snapshotId, _
|
||||
objectMap, originalMap)
|
||||
Call DxWriteProgress(runRoot, "waiting")
|
||||
End If
|
||||
End If
|
||||
Call DxBridgeIdleWait()
|
||||
Loop
|
||||
If fso.FileExists(resultPath) Then
|
||||
If DxBridgeClaimFile(fso, resultPath, claimPath) Then
|
||||
state = DxProcessApply(runRoot, runId, snapshotId, _
|
||||
objectMap, originalMap)
|
||||
End If
|
||||
End If
|
||||
DxBridgeMailboxLoop = state
|
||||
End Function
|
||||
|
||||
Function DxBridgeClaimFile(fso, sourcePath, claimPath)
|
||||
DxBridgeClaimFile = False
|
||||
If fso.FileExists(claimPath) Then
|
||||
On Error Resume Next
|
||||
fso.DeleteFile claimPath, True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End If
|
||||
On Error Resume Next
|
||||
fso.MoveFile sourcePath, claimPath
|
||||
If Err.Number = 0 Then DxBridgeClaimFile = True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Sub DxBridgePumpRefresh(runRoot, runId, objectMap, originalMap, _
|
||||
ByRef snapshotId)
|
||||
Dim fso
|
||||
Dim refreshPath
|
||||
Dim claimPath
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
refreshPath = fso.BuildPath(runRoot, "refresh.request")
|
||||
If Not fso.FileExists(refreshPath) Then Exit Sub
|
||||
claimPath = fso.BuildPath(runRoot, "refresh.processing")
|
||||
If Not DxBridgeClaimFile(fso, refreshPath, claimPath) Then Exit Sub
|
||||
Call DxWriteProgress(runRoot, "processing")
|
||||
If DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
|
||||
snapshotId) Then
|
||||
Call DxWriteProgress(runRoot, "waiting")
|
||||
End If
|
||||
On Error Resume Next
|
||||
fso.DeleteFile claimPath, True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxBridgePumpBomExport(runRoot)
|
||||
Dim fso
|
||||
Dim bomPath
|
||||
Dim claimPath
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
bomPath = fso.BuildPath(runRoot, "bom-export.json")
|
||||
If Not fso.FileExists(bomPath) Then Exit Sub
|
||||
claimPath = fso.BuildPath(runRoot, "bom-export.processing")
|
||||
If Not DxBridgeClaimFile(fso, bomPath, claimPath) Then Exit Sub
|
||||
Call DxBridgeRenderBom(runRoot, claimPath)
|
||||
On Error Resume Next
|
||||
fso.DeleteFile claimPath, True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxBridgeConsumeLocate(runRoot, objectMap)
|
||||
Dim fso
|
||||
Dim locatePath
|
||||
Dim processingPath
|
||||
Dim bridgeId
|
||||
Dim parts
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
locatePath = fso.BuildPath(runRoot, "locate.tsv")
|
||||
processingPath = fso.BuildPath(runRoot, "locate.processing")
|
||||
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))
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
fso.DeleteFile processingPath, True
|
||||
Exit Sub
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
fso.DeleteFile processingPath, True
|
||||
If InStr(bridgeId, "net|") = 1 Then
|
||||
parts = Split(bridgeId, "|")
|
||||
If UBound(parts) >= 2 Then
|
||||
Call DxBridgeLocateNet(parts(1), parts(2))
|
||||
End If
|
||||
ElseIf objectMap.Exists(bridgeId) Then
|
||||
Call DxBridgeLocateComponent(objectMap(bridgeId))
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub DxBridgeLocateNet(netName, pageNumber)
|
||||
Dim projectData
|
||||
Dim designs
|
||||
Dim designId
|
||||
Dim topBlock
|
||||
Dim net
|
||||
Dim found
|
||||
On Error Resume Next
|
||||
Set projectData = Application.GetProjectData()
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
Set designs = projectData.GetiCDBDesigns()
|
||||
designId = CStr(designs.GetItem(1))
|
||||
topBlock = projectData.GetiCDBDesignRootBlock(designId)
|
||||
Err.Clear
|
||||
ActiveView.UnselectAll
|
||||
Err.Clear
|
||||
Application.PushPath topBlock, "", CLng(pageNumber)
|
||||
Err.Clear
|
||||
found = False
|
||||
For Each net In ActiveView.Query(VDM_NET, VD_ALL)
|
||||
If CStr(net.Name) = CStr(netName) Then
|
||||
net.Selected = True
|
||||
If Err.Number <> 0 Then Err.Clear
|
||||
ActiveView.ZoomSelect
|
||||
Err.Clear
|
||||
found = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Err.Clear
|
||||
ActiveView.Refresh
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If Not found Then
|
||||
MsgBox DxBridgeNetNotFoundMessage() & vbCrLf & CStr(netName), _
|
||||
vbInformation
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Function DxBridgeNetNotFoundMessage()
|
||||
DxBridgeNetNotFoundMessage = ChrW(&H672A) & ChrW(&H627E) & _
|
||||
ChrW(&H5230) & ChrW(&H7F51) & ChrW(&H7EDC)
|
||||
End Function
|
||||
|
||||
Sub DxBridgeLocateComponent(component)
|
||||
On Error Resume Next
|
||||
ActiveView.UnselectAll
|
||||
Err.Clear
|
||||
ActiveView.Select component
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
ActiveView.SelectObject component
|
||||
End If
|
||||
Err.Clear
|
||||
ActiveView.ZoomTo component
|
||||
Err.Clear
|
||||
ActiveView.Refresh
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxBridgeCleanupRuns(runsRoot, currentRunId)
|
||||
Dim fso
|
||||
Dim folder
|
||||
Dim item
|
||||
Dim names
|
||||
Dim index
|
||||
Dim inner
|
||||
Dim temp
|
||||
Const KEEP_RUNS = 20
|
||||
|
||||
On Error Resume Next
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
If Not fso.FolderExists(CStr(runsRoot)) Then Exit Sub
|
||||
Set folder = fso.GetFolder(CStr(runsRoot))
|
||||
If folder.SubFolders.Count <= KEEP_RUNS Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
names = Array()
|
||||
ReDim names(folder.SubFolders.Count - 1)
|
||||
index = 0
|
||||
For Each item In folder.SubFolders
|
||||
names(index) = CStr(item.Name)
|
||||
index = index + 1
|
||||
Next
|
||||
For index = 0 To UBound(names)
|
||||
For inner = index + 1 To UBound(names)
|
||||
If StrComp(names(inner), names(index), vbTextCompare) > 0 Then
|
||||
temp = names(index)
|
||||
names(index) = names(inner)
|
||||
names(inner) = temp
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
For index = KEEP_RUNS To UBound(names)
|
||||
If names(index) <> CStr(currentRunId) Then
|
||||
fso.DeleteFolder fso.BuildPath(CStr(runsRoot), names(index)), True
|
||||
Err.Clear
|
||||
End If
|
||||
Next
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxBridgeYield()
|
||||
On Error Resume Next
|
||||
Scripting.DoEvents
|
||||
If Err.Number = 0 Then
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
Err.Clear
|
||||
Application.DoEvents
|
||||
If Err.Number = 0 Then
|
||||
On Error GoTo 0
|
||||
Exit Sub
|
||||
End If
|
||||
Err.Clear
|
||||
ActiveView.Refresh
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Function DxBridgeStateMessage(state)
|
||||
Select Case CStr(state)
|
||||
Case "applied"
|
||||
DxBridgeStateMessage = DxBridgeTextApplied()
|
||||
Case "rolled-back"
|
||||
DxBridgeStateMessage = DxBridgeTextRolledBack()
|
||||
Case "rejected"
|
||||
DxBridgeStateMessage = DxBridgeTextRejected()
|
||||
Case Else
|
||||
DxBridgeStateMessage = DxBridgeTextRollbackFailed()
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Function DxBridgeTextApplied()
|
||||
DxBridgeTextApplied = ChrW(&H5E94) & ChrW(&H7528) & ChrW(&H5B8C) & _
|
||||
ChrW(&H6210)
|
||||
End Function
|
||||
|
||||
Function DxBridgeTextRolledBack()
|
||||
DxBridgeTextRolledBack = ChrW(&H5DF2) & ChrW(&H56DE) & ChrW(&H6EDA)
|
||||
End Function
|
||||
|
||||
Function DxBridgeTextRejected()
|
||||
DxBridgeTextRejected = ChrW(&H5DF2) & ChrW(&H62D2) & ChrW(&H7EDD) & _
|
||||
ChrW(&HFF1A) & ChrW(&H8BBE) & ChrW(&H8BA1) & ChrW(&H72B6) & _
|
||||
ChrW(&H6001) & ChrW(&H4E0E) & ChrW(&H9884) & ChrW(&H89C8) & _
|
||||
ChrW(&H4E0D) & ChrW(&H4E00) & ChrW(&H81F4)
|
||||
End Function
|
||||
|
||||
Function DxBridgeTextRollbackFailed()
|
||||
DxBridgeTextRollbackFailed = ChrW(&H56DE) & ChrW(&H6EDA) & _
|
||||
ChrW(&H5931) & ChrW(&H8D25) & ChrW(&HFF0C) & ChrW(&H8BF7) & _
|
||||
ChrW(&H68C0) & ChrW(&H67E5) & ChrW(&H8BBE) & ChrW(&H8BA1)
|
||||
End Function
|
||||
|
||||
Function DxBridgeMissingExecutableMessage()
|
||||
DxBridgeMissingExecutableMessage = ChrW(&H627E) & ChrW(&H4E0D) & _
|
||||
ChrW(&H5230) & ChrW(&H5DE5) & ChrW(&H5177) & _
|
||||
ChrW(&H4E3B) & ChrW(&H7A0B) & ChrW(&H5E8F)
|
||||
End Function
|
||||
|
||||
Function DxBridgeLaunchErrorMessage()
|
||||
DxBridgeLaunchErrorMessage = ChrW(&H5DE5) & ChrW(&H5177) & _
|
||||
ChrW(&H542F) & ChrW(&H52A8) & ChrW(&H5931) & ChrW(&H8D25)
|
||||
End Function
|
||||
@@ -0,0 +1,495 @@
|
||||
' Design snapshot export for the DxDesigner 7.9.5 bridge (protocol v2).
|
||||
' Keep this file ASCII-only.
|
||||
|
||||
Function DxExportSnapshot(objectMap, originalMap, ByRef runRoot, _
|
||||
ByRef runId, ByRef snapshotId)
|
||||
Dim shell
|
||||
Dim runsRoot
|
||||
|
||||
DxExportSnapshot = False
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
runId = DxBridgeCreateRunId()
|
||||
runsRoot = shell.ExpandEnvironmentStrings( _
|
||||
"%LOCALAPPDATA%\DxProductivity\runs")
|
||||
runRoot = fsoBuildPath(runsRoot, CStr(runId))
|
||||
Call DxBridgeEnsureFolder(runRoot)
|
||||
DxExportSnapshot = DxRefreshSnapshot(runRoot, runId, objectMap, _
|
||||
originalMap, snapshotId)
|
||||
End Function
|
||||
|
||||
Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
|
||||
ByRef snapshotId)
|
||||
Dim projectData
|
||||
Dim designs
|
||||
Dim designId
|
||||
Dim topBlock
|
||||
Dim component
|
||||
Dim selected
|
||||
Dim selectedKeys
|
||||
Dim componentCount
|
||||
Dim bridgeId
|
||||
Dim stableUid
|
||||
Dim fullPath
|
||||
Dim logicalKey
|
||||
Dim sheetNumber
|
||||
Dim sheetName
|
||||
Dim refdes
|
||||
Dim symbolDefault
|
||||
Dim requestText
|
||||
Dim componentText
|
||||
Dim designPath
|
||||
Dim selectedValue
|
||||
Dim currentSheetValue
|
||||
Dim identityKey
|
||||
Dim attributesText
|
||||
Dim netsText
|
||||
Dim selectedNetsText
|
||||
Dim snapshotSequence
|
||||
|
||||
DxRefreshSnapshot = False
|
||||
Set selectedKeys = CreateObject("Scripting.Dictionary")
|
||||
On Error Resume Next
|
||||
For Each selected In ActiveView.Query(VDM_COMP, VD_SELECTED)
|
||||
identityKey = DxBridgeComponentIdentity(selected)
|
||||
If identityKey <> "" And Not selectedKeys.Exists(identityKey) Then
|
||||
selectedKeys.Add identityKey, True
|
||||
End If
|
||||
Next
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
|
||||
On Error Resume Next
|
||||
Set projectData = Application.GetProjectData()
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Call DxBridgeExportFailed(DxBridgeProjectUnavailableMessage())
|
||||
Exit Function
|
||||
End If
|
||||
On Error GoTo 0
|
||||
Set designs = projectData.GetiCDBDesigns()
|
||||
designId = CStr(designs.GetItem(1))
|
||||
topBlock = projectData.GetiCDBDesignRootBlock(designId)
|
||||
designPath = DxBridgeDesignPath()
|
||||
componentCount = 0
|
||||
componentText = ""
|
||||
|
||||
For Each component In Application.DesignComponents( _
|
||||
"", topBlock, "-1", "STD", True)
|
||||
componentCount = componentCount + 1
|
||||
bridgeId = "c" & DxBridgePad(componentCount, 6)
|
||||
stableUid = DxBridgeStableUid(component)
|
||||
fullPath = DxBridgeFullPath(component)
|
||||
If stableUid = "" And fullPath = "" Then
|
||||
Call DxBridgeExportFailed(DxBridgeIdentityUnavailableMessage())
|
||||
Exit Function
|
||||
End If
|
||||
If stableUid <> "" Then
|
||||
logicalKey = stableUid
|
||||
Else
|
||||
logicalKey = fullPath
|
||||
End If
|
||||
refdes = DxBridgeRefdes(component)
|
||||
symbolDefault = DxBridgeSymbolDefault(component, refdes)
|
||||
sheetNumber = DxBridgeSheetNumber(component)
|
||||
sheetName = CStr(sheetNumber)
|
||||
identityKey = DxBridgeIdentityKey(stableUid, fullPath)
|
||||
selectedValue = selectedKeys.Exists(identityKey)
|
||||
currentSheetValue = (sheetNumber = DxBridgeCurrentSheetNumber())
|
||||
attributesText = DxBridgeExportAttributes(component)
|
||||
|
||||
objectMap.Add bridgeId, component
|
||||
If componentText <> "" Then componentText = componentText & "," & vbCrLf
|
||||
componentText = componentText & _
|
||||
" {" & vbCrLf & _
|
||||
" ""bridge_id"": """ & DxToolsJson(bridgeId) & """," & vbCrLf & _
|
||||
" ""stable_uid"": " & DxBridgeNullable(stableUid) & "," & vbCrLf & _
|
||||
" ""full_path"": """ & DxToolsJson(fullPath) & """," & vbCrLf & _
|
||||
" ""logical_group_key"": """ & DxToolsJson(logicalKey) & """," & vbCrLf & _
|
||||
" ""sheet_name"": """ & DxToolsJson(sheetName) & """," & vbCrLf & _
|
||||
" ""sheet_number"": " & CStr(sheetNumber) & "," & vbCrLf & _
|
||||
" ""x"": """ & DxBridgeCoordinate(component, True) & """," & vbCrLf & _
|
||||
" ""y"": """ & DxBridgeCoordinate(component, False) & """," & vbCrLf & _
|
||||
" ""y_axis_up"": true," & vbCrLf & _
|
||||
" ""refdes"": """ & DxToolsJson(refdes) & """," & vbCrLf & _
|
||||
" ""symbol_refdes_default"": " & _
|
||||
DxBridgeNullable(symbolDefault) & "," & vbCrLf & _
|
||||
" ""selected"": " & DxBridgeBoolean(selectedValue) & "," & vbCrLf & _
|
||||
" ""current_sheet"": " & _
|
||||
DxBridgeBoolean(currentSheetValue) & "," & vbCrLf & _
|
||||
" ""part_number"": """ & _
|
||||
DxToolsJson(DxBridgePartNumber(component)) & """," & vbCrLf & _
|
||||
" ""value"": """ & _
|
||||
DxToolsJson(DxBridgeValue(component)) & """," & vbCrLf & _
|
||||
" ""locked"": " & DxBridgeBoolean(DxBridgeLocked(component)) & "," & vbCrLf & _
|
||||
" ""attributes"": " & attributesText & vbCrLf & _
|
||||
" }"
|
||||
Next
|
||||
If componentCount = 0 Then
|
||||
Call DxBridgeExportFailed(DxBridgeEmptyDesignMessage())
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
netsText = DxBridgeExportNets(topBlock)
|
||||
selectedNetsText = DxBridgeExportSelectedNets()
|
||||
snapshotSequence = DxBridgeNextSnapshotSequence(runRoot)
|
||||
snapshotId = "snapshot-" & CStr(runId) & "-" & CStr(snapshotSequence)
|
||||
|
||||
requestText = "{" & vbCrLf & _
|
||||
" ""format_version"": 2," & vbCrLf & _
|
||||
" ""run_id"": """ & DxToolsJson(runId) & """," & vbCrLf & _
|
||||
" ""snapshot_id"": """ & DxToolsJson(snapshotId) & """," & vbCrLf & _
|
||||
" ""design_id"": """ & DxToolsJson(designId) & """," & vbCrLf & _
|
||||
" ""design_path"": """ & DxToolsJson(designPath) & """," & vbCrLf & _
|
||||
" ""nets"": " & netsText & "," & vbCrLf & _
|
||||
" ""selected_nets"": " & selectedNetsText & "," & vbCrLf & _
|
||||
" ""components"": [" & vbCrLf & componentText & vbCrLf & _
|
||||
" ]" & vbCrLf & "}" & vbCrLf
|
||||
Call DxToolsWriteUtf8Atomic(fsoBuildPath(runRoot, "request.json"), _
|
||||
requestText)
|
||||
DxRefreshSnapshot = True
|
||||
End Function
|
||||
|
||||
Function DxBridgeExportAttributes(component)
|
||||
Dim attribute
|
||||
Dim text
|
||||
Dim count
|
||||
Dim name
|
||||
Dim value
|
||||
Dim visible
|
||||
|
||||
text = ""
|
||||
count = 0
|
||||
On Error Resume Next
|
||||
For Each attribute In component.Attributes
|
||||
name = CStr(attribute.Name)
|
||||
value = CStr(attribute.Value)
|
||||
visible = DxBridgeNormalizeVisible(attribute.Visible)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
ElseIf name <> "" Then
|
||||
If text <> "" Then text = text & ", "
|
||||
text = text & _
|
||||
"{""name"": """ & DxToolsJson(name) & """" & _
|
||||
", ""value"": """ & DxToolsJson(value) & """" & _
|
||||
", ""visible"": " & DxBridgeBoolean(visible) & "}"
|
||||
count = count + 1
|
||||
End If
|
||||
Next
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
DxBridgeExportAttributes = "[" & text & "]"
|
||||
End Function
|
||||
|
||||
Function DxBridgeExportNets(topBlock)
|
||||
Dim nets
|
||||
Dim net
|
||||
Dim name
|
||||
Dim page
|
||||
Dim pages
|
||||
Dim names
|
||||
Dim text
|
||||
Dim nameText
|
||||
|
||||
DxBridgeExportNets = "[]"
|
||||
On Error Resume Next
|
||||
Set nets = Application.DesignNets("", topBlock, "-1", "STD", True)
|
||||
If Err.Number <> 0 Or nets Is Nothing Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Function
|
||||
End If
|
||||
Set pages = CreateObject("Scripting.Dictionary")
|
||||
Set names = CreateObject("Scripting.Dictionary")
|
||||
For Each net In nets
|
||||
name = ""
|
||||
page = -1
|
||||
name = CStr(net.Name)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
name = ""
|
||||
End If
|
||||
page = CLng(net.SheetNum)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
page = DxBridgeCurrentSheetNumber()
|
||||
End If
|
||||
If name <> "" And page >= 0 Then
|
||||
nameText = LCase(name)
|
||||
If Not names.Exists(nameText) Then
|
||||
names.Add nameText, name
|
||||
pages.Add nameText, CStr(page)
|
||||
ElseIf InStr(pages(nameText), CStr(page)) = 0 Then
|
||||
pages(nameText) = pages(nameText) & ", " & CStr(page)
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
|
||||
For Each nameText In names.Keys
|
||||
If text <> "" Then text = text & ", "
|
||||
text = text & _
|
||||
"{""name"": """ & DxToolsJson(names(nameText)) & """" & _
|
||||
", ""pages"": [" & pages(nameText) & "]}"
|
||||
Next
|
||||
DxBridgeExportNets = "[" & text & "]"
|
||||
End Function
|
||||
|
||||
Function DxBridgeExportSelectedNets()
|
||||
Dim net
|
||||
Dim name
|
||||
Dim text
|
||||
|
||||
DxBridgeExportSelectedNets = "[]"
|
||||
text = ""
|
||||
On Error Resume Next
|
||||
For Each net In ActiveView.Query(VDM_NET, VD_SELECTED)
|
||||
name = CStr(net.Name)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
ElseIf name <> "" Then
|
||||
If text <> "" Then text = text & ", "
|
||||
text = text & """" & DxToolsJson(name) & """"
|
||||
End If
|
||||
Next
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
DxBridgeExportSelectedNets = "[" & text & "]"
|
||||
End Function
|
||||
|
||||
Function DxBridgeNextSnapshotSequence(runRoot)
|
||||
Dim fso
|
||||
Dim sequencePath
|
||||
Dim text
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
sequencePath = fsoBuildPath(runRoot, "snapshot.seq")
|
||||
DxBridgeNextSnapshotSequence = 1
|
||||
On Error Resume Next
|
||||
If fso.FileExists(sequencePath) Then
|
||||
text = Trim(DxToolsReadUtf8(sequencePath))
|
||||
If IsNumeric(text) Then
|
||||
DxBridgeNextSnapshotSequence = CLng(text) + 1
|
||||
End If
|
||||
End If
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
DxBridgeNextSnapshotSequence = 1
|
||||
End If
|
||||
On Error GoTo 0
|
||||
Call DxToolsWriteUtf8Atomic(sequencePath, _
|
||||
CStr(DxBridgeNextSnapshotSequence) & vbCrLf)
|
||||
End Function
|
||||
|
||||
Sub DxBridgeExportFailed(message)
|
||||
MsgBox DxBridgeExportFailedPrefix() & vbCrLf & message, vbExclamation
|
||||
End Sub
|
||||
|
||||
Function fsoBuildPath(parent, child)
|
||||
fsoBuildPath = CreateObject("Scripting.FileSystemObject").BuildPath( _
|
||||
CStr(parent), CStr(child))
|
||||
End Function
|
||||
|
||||
Function DxBridgeCreateRunId()
|
||||
Randomize
|
||||
DxBridgeCreateRunId = CStr(Year(Now)) & DxBridgePad(Month(Now), 2) & _
|
||||
DxBridgePad(Day(Now), 2) & "T" & DxBridgePad(Hour(Now), 2) & _
|
||||
DxBridgePad(Minute(Now), 2) & DxBridgePad(Second(Now), 2) & "-" & _
|
||||
DxBridgePad(Hex(CLng(Rnd * 2147483647)), 8)
|
||||
End Function
|
||||
|
||||
Function DxBridgePad(value, width)
|
||||
DxBridgePad = Right(String(CLng(width), "0") & CStr(value), CLng(width))
|
||||
End Function
|
||||
|
||||
Function DxBridgeStableUid(component)
|
||||
DxBridgeStableUid = ""
|
||||
On Error Resume Next
|
||||
DxBridgeStableUid = CStr(component.UID)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeFullPath(component)
|
||||
Dim parentName
|
||||
Dim componentName
|
||||
parentName = ""
|
||||
componentName = ""
|
||||
On Error Resume Next
|
||||
parentName = CStr(component.Parent.Name)
|
||||
componentName = CStr(component.GetName(SHORT_NAME))
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If componentName = "" Then
|
||||
On Error Resume Next
|
||||
componentName = CStr(component.Name)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End If
|
||||
If parentName <> "" And componentName <> "" Then
|
||||
DxBridgeFullPath = parentName & "\" & componentName
|
||||
Else
|
||||
DxBridgeFullPath = componentName
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxBridgeIdentityKey(stableUid, fullPath)
|
||||
If CStr(stableUid) <> "" Then
|
||||
DxBridgeIdentityKey = "uid:" & LCase(CStr(stableUid))
|
||||
ElseIf CStr(fullPath) <> "" Then
|
||||
DxBridgeIdentityKey = "path:" & LCase(CStr(fullPath))
|
||||
Else
|
||||
DxBridgeIdentityKey = ""
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxBridgeComponentIdentity(component)
|
||||
DxBridgeComponentIdentity = DxBridgeIdentityKey( _
|
||||
DxBridgeStableUid(component), DxBridgeFullPath(component))
|
||||
End Function
|
||||
|
||||
Function DxBridgeRefdes(component)
|
||||
DxBridgeRefdes = ""
|
||||
On Error Resume Next
|
||||
DxBridgeRefdes = CStr(component.Refdes)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeSymbolDefault(component, refdes)
|
||||
DxBridgeSymbolDefault = ""
|
||||
On Error Resume Next
|
||||
DxBridgeSymbolDefault = CStr(component.SymbolRefdesDefault)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
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
|
||||
End Function
|
||||
|
||||
Function DxBridgeCurrentSheetNumber()
|
||||
DxBridgeCurrentSheetNumber = 0
|
||||
On Error Resume Next
|
||||
DxBridgeCurrentSheetNumber = CLng(ActiveView.Block.SheetNum)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeCoordinate(component, readX)
|
||||
Dim value
|
||||
value = 0
|
||||
On Error Resume Next
|
||||
If CBool(readX) Then
|
||||
value = component.X
|
||||
Else
|
||||
value = component.Y
|
||||
End If
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
If CBool(readX) Then
|
||||
value = component.PositionX
|
||||
Else
|
||||
value = component.PositionY
|
||||
End If
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
DxBridgeCoordinate = Replace(CStr(value), ",", ".")
|
||||
End Function
|
||||
|
||||
Function DxBridgePartNumber(component)
|
||||
DxBridgePartNumber = ""
|
||||
On Error Resume Next
|
||||
DxBridgePartNumber = CStr(component.PartNumber)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If DxBridgePartNumber = "" Then
|
||||
DxBridgePartNumber = DxBridgeAttribute(component, "Part Number")
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxBridgeValue(component)
|
||||
DxBridgeValue = ""
|
||||
On Error Resume Next
|
||||
DxBridgeValue = CStr(component.Value)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
If DxBridgeValue = "" Then
|
||||
DxBridgeValue = DxBridgeAttribute(component, "Value")
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxBridgeAttribute(component, name)
|
||||
DxBridgeAttribute = ""
|
||||
On Error Resume Next
|
||||
DxBridgeAttribute = CStr(component.Attributes.Item(CStr(name)).Value)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeLocked(component)
|
||||
DxBridgeLocked = False
|
||||
On Error Resume Next
|
||||
DxBridgeLocked = CBool(component.Locked)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
DxBridgeLocked = False
|
||||
End If
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeDesignPath()
|
||||
DxBridgeDesignPath = ""
|
||||
On Error Resume Next
|
||||
DxBridgeDesignPath = CStr(Application.ProjectPath)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
|
||||
Function DxBridgeNullable(value)
|
||||
If CStr(value) = "" Then
|
||||
DxBridgeNullable = "null"
|
||||
Else
|
||||
DxBridgeNullable = """" & DxToolsJson(value) & """"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxBridgeBoolean(value)
|
||||
If CBool(value) Then
|
||||
DxBridgeBoolean = "true"
|
||||
Else
|
||||
DxBridgeBoolean = "false"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxBridgeExportFailedPrefix()
|
||||
DxBridgeExportFailedPrefix = ChrW(&H65E0) & ChrW(&H6CD5) & _
|
||||
ChrW(&H5BFC) & ChrW(&H51FA) & ChrW(&H8BBE) & ChrW(&H8BA1) & _
|
||||
ChrW(&H5FEB) & ChrW(&H7167)
|
||||
End Function
|
||||
|
||||
Function DxBridgeProjectUnavailableMessage()
|
||||
DxBridgeProjectUnavailableMessage = ChrW(&H65E0) & ChrW(&H6CD5) & _
|
||||
ChrW(&H8BBF) & ChrW(&H95EE) & ChrW(&H5F53) & ChrW(&H524D) & _
|
||||
ChrW(&H5DE5) & ChrW(&H7A0B)
|
||||
End Function
|
||||
|
||||
Function DxBridgeIdentityUnavailableMessage()
|
||||
DxBridgeIdentityUnavailableMessage = ChrW(&H67D0) & ChrW(&H5668) & _
|
||||
ChrW(&H4EF6) & ChrW(&H8EAB) & ChrW(&H4EFD) & ChrW(&H4E0D) & _
|
||||
ChrW(&H53EF) & ChrW(&H8BFB)
|
||||
End Function
|
||||
|
||||
Function DxBridgeEmptyDesignMessage()
|
||||
DxBridgeEmptyDesignMessage = ChrW(&H5F53) & ChrW(&H524D) & _
|
||||
ChrW(&H8BBE) & ChrW(&H8BA1) & ChrW(&H6CA1) & ChrW(&H6709) & _
|
||||
ChrW(&H5668) & ChrW(&H4EF6)
|
||||
End Function
|
||||
@@ -0,0 +1,441 @@
|
||||
' Generalized apply transaction for the DxDesigner 7.9.5 bridge (protocol v2).
|
||||
' Keep this file ASCII-only.
|
||||
|
||||
Function DxProcessApply(runRoot, runId, snapshotId, objectMap, originalMap)
|
||||
Dim resultText
|
||||
Dim backupPath
|
||||
Dim errorText
|
||||
Dim failingSequence
|
||||
Dim changedCount
|
||||
Dim rollbackState
|
||||
Dim state
|
||||
|
||||
state = "rejected"
|
||||
failingSequence = 0
|
||||
changedCount = 0
|
||||
rollbackState = ""
|
||||
If DxPreflightApply(runRoot, runId, snapshotId, objectMap, _
|
||||
resultText, backupPath, errorText) Then
|
||||
state = DxApplySchedule(resultText, objectMap, _
|
||||
failingSequence, changedCount, rollbackState, errorText)
|
||||
End If
|
||||
Call DxWriteApplyStatus(runRoot, runId, state, changedCount, _
|
||||
backupPath, failingSequence, errorText, rollbackState)
|
||||
DxProcessApply = state
|
||||
End Function
|
||||
|
||||
Function DxPreflightApply(runRoot, runId, snapshotId, objectMap, _
|
||||
ByRef resultText, ByRef backupPath, ByRef errorText)
|
||||
Dim fso
|
||||
Dim requestPath
|
||||
Dim resultPath
|
||||
Dim requestText
|
||||
Dim requestRunId
|
||||
Dim requestSnapshotId
|
||||
Dim digest
|
||||
Dim actualDigest
|
||||
Dim lines
|
||||
Dim line
|
||||
Dim sequence
|
||||
Dim op
|
||||
Dim bridgeId
|
||||
Dim propertyName
|
||||
Dim expectedValue
|
||||
Dim newValue
|
||||
Dim finalValue
|
||||
Dim expectedSequence
|
||||
Dim rowCount
|
||||
Dim counts
|
||||
Dim projected
|
||||
Dim key
|
||||
Dim component
|
||||
|
||||
DxPreflightApply = False
|
||||
errorText = ""
|
||||
backupPath = ""
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
requestPath = fso.BuildPath(runRoot, "apply-request.json")
|
||||
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
|
||||
|
||||
requestText = DxToolsReadUtf8(requestPath)
|
||||
If InStr(requestText, """format_version"": 2,") = 0 Then
|
||||
errorText = "Unsupported apply request version"
|
||||
Exit Function
|
||||
End If
|
||||
If Not DxToolsJsonString(requestText, "run_id", requestRunId) Or _
|
||||
Not DxToolsJsonString(requestText, "snapshot_id", _
|
||||
requestSnapshotId) Or _
|
||||
Not DxToolsJsonString(requestText, "backup_path", backupPath) Or _
|
||||
Not DxToolsJsonString(requestText, "schedule_sha256", digest) Then
|
||||
errorText = "Apply request fields are invalid"
|
||||
Exit Function
|
||||
End If
|
||||
If requestRunId <> CStr(runId) Or _
|
||||
requestSnapshotId <> CStr(snapshotId) Then
|
||||
errorText = "Apply request identity is stale"
|
||||
Exit Function
|
||||
End If
|
||||
If Not fso.FileExists(backupPath) Then
|
||||
errorText = "Apply backup is missing"
|
||||
Exit Function
|
||||
End If
|
||||
actualDigest = DxToolsSha256File(resultPath)
|
||||
If LCase(digest) <> LCase(actualDigest) Then
|
||||
errorText = "Apply schedule digest mismatch"
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
resultText = DxToolsReadUtf8(resultPath)
|
||||
lines = Split(Replace(resultText, vbCr, ""), vbLf)
|
||||
expectedSequence = 1
|
||||
rowCount = 0
|
||||
Set counts = CreateObject("Scripting.Dictionary")
|
||||
Set projected = CreateObject("Scripting.Dictionary")
|
||||
For Each line In lines
|
||||
If Len(line) > 0 Then
|
||||
rowCount = rowCount + 1
|
||||
If Not DxToolsParseScheduleRow(line, sequence, op, bridgeId, _
|
||||
propertyName, expectedValue, newValue, finalValue) Then
|
||||
errorText = "Apply schedule row is invalid"
|
||||
Exit Function
|
||||
End If
|
||||
If sequence <> expectedSequence Then
|
||||
errorText = "Apply schedule sequence is not contiguous"
|
||||
Exit Function
|
||||
End If
|
||||
If Not objectMap.Exists(bridgeId) Then
|
||||
errorText = "Apply schedule has an unknown bridge ID"
|
||||
Exit Function
|
||||
End If
|
||||
If Not DxBridgeOpSupported(op) Then
|
||||
errorText = "Apply schedule has an unsupported operation"
|
||||
Exit Function
|
||||
End If
|
||||
key = DxBridgeOpKey(op, propertyName, bridgeId)
|
||||
If counts.Exists(key) Then
|
||||
counts(key) = counts(key) + 1
|
||||
Else
|
||||
counts.Add key, 1
|
||||
End If
|
||||
If counts(key) > 2 Then
|
||||
errorText = "Apply schedule repeats an operation target"
|
||||
Exit Function
|
||||
End If
|
||||
If Not projected.Exists(key) Then
|
||||
Set component = objectMap(bridgeId)
|
||||
projected.Add key, DxBridgeReadOpValue(component, op, _
|
||||
propertyName)
|
||||
End If
|
||||
If Not DxBridgeOpValueMatches(op, projected(key), _
|
||||
expectedValue) Then
|
||||
errorText = "Apply schedule expected value is stale"
|
||||
Exit Function
|
||||
End If
|
||||
projected(key) = CStr(newValue)
|
||||
expectedSequence = expectedSequence + 1
|
||||
End If
|
||||
Next
|
||||
If rowCount = 0 Then
|
||||
errorText = "Apply schedule is empty"
|
||||
Exit Function
|
||||
End If
|
||||
DxPreflightApply = True
|
||||
End Function
|
||||
|
||||
Function DxApplySchedule(resultText, objectMap, _
|
||||
ByRef failingSequence, ByRef changedCount, ByRef rollbackState, _
|
||||
ByRef errorText)
|
||||
Dim lines
|
||||
Dim line
|
||||
Dim sequence
|
||||
Dim op
|
||||
Dim bridgeId
|
||||
Dim propertyName
|
||||
Dim expectedValue
|
||||
Dim newValue
|
||||
Dim finalValue
|
||||
Dim component
|
||||
Dim touched
|
||||
Dim originals
|
||||
Dim finals
|
||||
Dim key
|
||||
Dim actual
|
||||
Dim writeError
|
||||
|
||||
Set touched = CreateObject("Scripting.Dictionary")
|
||||
Set originals = CreateObject("Scripting.Dictionary")
|
||||
Set finals = CreateObject("Scripting.Dictionary")
|
||||
lines = Split(Replace(CStr(resultText), vbCr, ""), vbLf)
|
||||
For Each line In lines
|
||||
If Len(line) > 0 Then
|
||||
Call DxToolsParseScheduleRow(line, sequence, op, bridgeId, _
|
||||
propertyName, expectedValue, newValue, finalValue)
|
||||
Set component = objectMap(bridgeId)
|
||||
actual = DxBridgeReadOpValue(component, op, propertyName)
|
||||
If Not DxBridgeOpValueMatches(op, actual, expectedValue) Then
|
||||
failingSequence = sequence
|
||||
errorText = "Component changed after preflight"
|
||||
If touched.Count = 0 Then
|
||||
DxApplySchedule = "rejected"
|
||||
Exit Function
|
||||
End If
|
||||
DxApplySchedule = DxRollbackState(objectMap, originals, _
|
||||
touched, rollbackState, errorText)
|
||||
Exit Function
|
||||
End If
|
||||
key = DxBridgeOpKey(op, propertyName, bridgeId)
|
||||
If Not touched.Exists(key) Then
|
||||
touched.Add key, Array(CStr(op), CStr(propertyName), _
|
||||
CStr(bridgeId))
|
||||
originals.Add key, actual
|
||||
End If
|
||||
writeError = ""
|
||||
If Not DxBridgeWriteOpValue(component, op, propertyName, _
|
||||
newValue, writeError) Then
|
||||
failingSequence = sequence
|
||||
If writeError = "" Then
|
||||
errorText = "Operation did not persist"
|
||||
Else
|
||||
errorText = writeError
|
||||
End If
|
||||
DxApplySchedule = DxRollbackState(objectMap, originals, _
|
||||
touched, rollbackState, errorText)
|
||||
Exit Function
|
||||
End If
|
||||
If Not DxBridgeOpValueMatches(op, _
|
||||
DxBridgeReadOpValue(component, op, propertyName), _
|
||||
newValue) Then
|
||||
failingSequence = sequence
|
||||
errorText = "Operation did not persist"
|
||||
DxApplySchedule = DxRollbackState(objectMap, originals, _
|
||||
touched, rollbackState, errorText)
|
||||
Exit Function
|
||||
End If
|
||||
finals.Add key, Array(CStr(op), CStr(propertyName), _
|
||||
CStr(bridgeId), CStr(finalValue))
|
||||
End If
|
||||
Next
|
||||
|
||||
If Not DxVerifyOperations(objectMap, finals, errorText) Then
|
||||
DxApplySchedule = DxRollbackState(objectMap, originals, touched, _
|
||||
rollbackState, errorText)
|
||||
Exit Function
|
||||
End If
|
||||
changedCount = touched.Count
|
||||
DxApplySchedule = "applied"
|
||||
End Function
|
||||
|
||||
Function DxRollbackState(objectMap, originals, touched, _
|
||||
ByRef rollbackState, ByRef errorText)
|
||||
Dim rollbackError
|
||||
rollbackError = ""
|
||||
If DxRollback(objectMap, originals, touched, rollbackError) Then
|
||||
rollbackState = "verified"
|
||||
DxRollbackState = "rolled-back"
|
||||
Else
|
||||
rollbackState = "failed"
|
||||
If rollbackError <> "" Then errorText = errorText & "; " & rollbackError
|
||||
DxRollbackState = "rollback-failed"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxRollback(objectMap, originals, touched, ByRef errorText)
|
||||
Dim key
|
||||
Dim entry
|
||||
Dim component
|
||||
Dim writeError
|
||||
DxRollback = True
|
||||
errorText = ""
|
||||
For Each key In touched.Keys
|
||||
entry = touched(key)
|
||||
Set component = objectMap(entry(2))
|
||||
writeError = ""
|
||||
If Not DxBridgeWriteOpValue(component, entry(0), entry(1), _
|
||||
originals(key), writeError) Then
|
||||
DxRollback = False
|
||||
errorText = "Rollback write failed for " & CStr(entry(2))
|
||||
ElseIf Not DxBridgeOpValueMatches(entry(0), _
|
||||
DxBridgeReadOpValue(component, entry(0), entry(1)), _
|
||||
originals(key)) Then
|
||||
DxRollback = False
|
||||
errorText = "Rollback verification failed for " & CStr(entry(2))
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function DxVerifyOperations(objectMap, finals, ByRef errorText)
|
||||
Dim key
|
||||
Dim entry
|
||||
Dim bridgeId
|
||||
Dim refdes
|
||||
Dim formalValues
|
||||
Dim hasRefdesOps
|
||||
|
||||
DxVerifyOperations = False
|
||||
hasRefdesOps = False
|
||||
For Each key In finals.Keys
|
||||
entry = finals(key)
|
||||
If Not DxBridgeOpValueMatches(entry(0), _
|
||||
DxBridgeReadOpValue(objectMap(entry(2)), entry(0), _
|
||||
entry(1)), entry(3)) Then
|
||||
errorText = "Final verification failed for " & CStr(entry(2))
|
||||
Exit Function
|
||||
End If
|
||||
If entry(0) = "refdes" Then hasRefdesOps = True
|
||||
Next
|
||||
If hasRefdesOps Then
|
||||
Set formalValues = CreateObject("Scripting.Dictionary")
|
||||
For Each bridgeId In objectMap.Keys
|
||||
refdes = CStr(objectMap(bridgeId).Refdes)
|
||||
If DxBridgeIsFormalRefdes(refdes) Then
|
||||
If formalValues.Exists(LCase(refdes)) Then
|
||||
errorText = "Duplicate reference designator: " & refdes
|
||||
Exit Function
|
||||
End If
|
||||
formalValues.Add LCase(refdes), bridgeId
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
DxVerifyOperations = True
|
||||
End Function
|
||||
|
||||
Function DxBridgeIsFormalRefdes(value)
|
||||
Dim expression
|
||||
Set expression = CreateObject("VBScript.RegExp")
|
||||
expression.Pattern = "^[A-Za-z]+[0-9]+$"
|
||||
expression.IgnoreCase = True
|
||||
DxBridgeIsFormalRefdes = expression.Test(CStr(value))
|
||||
End Function
|
||||
|
||||
Function DxBridgeOpSupported(op)
|
||||
DxBridgeOpSupported = False
|
||||
If CStr(op) = "refdes" Then DxBridgeOpSupported = True
|
||||
If CStr(op) = "property" Then DxBridgeOpSupported = True
|
||||
If CStr(op) = "visibility" Then DxBridgeOpSupported = True
|
||||
End Function
|
||||
|
||||
Function DxBridgeOpKey(op, propertyName, bridgeId)
|
||||
DxBridgeOpKey = CStr(op) & "|" & LCase(CStr(propertyName)) & "|" & _
|
||||
LCase(CStr(bridgeId))
|
||||
End Function
|
||||
|
||||
Function DxBridgeReadOpValue(component, op, propertyName)
|
||||
Select Case CStr(op)
|
||||
Case "refdes"
|
||||
DxBridgeReadOpValue = CStr(component.Refdes)
|
||||
Case "property"
|
||||
DxBridgeReadOpValue = ""
|
||||
On Error Resume Next
|
||||
DxBridgeReadOpValue = CStr( _
|
||||
component.Attributes.Item(CStr(propertyName)).Value)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
DxBridgeReadOpValue = ""
|
||||
End If
|
||||
On Error GoTo 0
|
||||
Case "visibility"
|
||||
DxBridgeReadOpValue = ""
|
||||
On Error Resume Next
|
||||
DxBridgeReadOpValue = DxBridgeNormalizeVisible( _
|
||||
component.Attributes.Item(CStr(propertyName)).Visible)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
DxBridgeReadOpValue = ""
|
||||
End If
|
||||
On Error GoTo 0
|
||||
Case Else
|
||||
DxBridgeReadOpValue = ""
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Function DxBridgeWriteOpValue(component, op, propertyName, value, _
|
||||
ByRef errorText)
|
||||
DxBridgeWriteOpValue = False
|
||||
errorText = ""
|
||||
On Error Resume Next
|
||||
Select Case CStr(op)
|
||||
Case "refdes"
|
||||
component.Refdes = CStr(value)
|
||||
Case "property"
|
||||
component.Attributes.Item(CStr(propertyName)).Value = CStr(value)
|
||||
Case "visibility"
|
||||
component.Attributes.Item(CStr(propertyName)).Visible = _
|
||||
CBool(CStr(value))
|
||||
Case Else
|
||||
Err.Raise vbObjectError + 801, "DxBridgeWriteOpValue", _
|
||||
"Unsupported operation: " & CStr(op)
|
||||
End Select
|
||||
If Err.Number <> 0 Then
|
||||
errorText = Err.Description
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Function
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
DxBridgeWriteOpValue = True
|
||||
End Function
|
||||
|
||||
Function DxBridgeOpValueMatches(op, actual, expected)
|
||||
If CStr(op) = "refdes" Then
|
||||
DxBridgeOpValueMatches = (LCase(CStr(actual)) = LCase(CStr(expected)))
|
||||
Else
|
||||
DxBridgeOpValueMatches = (CStr(actual) = CStr(expected))
|
||||
End If
|
||||
End Function
|
||||
|
||||
Sub DxWriteApplyStatus(runRoot, runId, state, changedCount, backupPath, _
|
||||
failingSequence, errorText, rollbackState)
|
||||
Dim text
|
||||
Dim failingValue
|
||||
Dim backupValue
|
||||
Dim errorValue
|
||||
Dim rollbackValue
|
||||
If failingSequence > 0 Then
|
||||
failingValue = CStr(failingSequence)
|
||||
Else
|
||||
failingValue = "null"
|
||||
End If
|
||||
If backupPath = "" Then
|
||||
backupValue = "null"
|
||||
Else
|
||||
backupValue = """" & DxToolsJson(backupPath) & """"
|
||||
End If
|
||||
If errorText = "" Then
|
||||
errorValue = "null"
|
||||
Else
|
||||
errorValue = """" & DxToolsJson(errorText) & """"
|
||||
End If
|
||||
If rollbackState = "" Then
|
||||
rollbackValue = "null"
|
||||
Else
|
||||
rollbackValue = """" & DxToolsJson(rollbackState) & """"
|
||||
End If
|
||||
text = "{" & vbCrLf & _
|
||||
" ""format_version"": 2," & vbCrLf & _
|
||||
" ""run_id"": """ & DxToolsJson(runId) & """," & vbCrLf & _
|
||||
" ""state"": """ & DxToolsJson(state) & """," & vbCrLf & _
|
||||
" ""changed_count"": " & CStr(changedCount) & "," & vbCrLf & _
|
||||
" ""backup_path"": " & backupValue & "," & vbCrLf & _
|
||||
" ""failing_sequence"": " & failingValue & "," & vbCrLf & _
|
||||
" ""error"": " & errorValue & "," & vbCrLf & _
|
||||
" ""rollback_state"": " & rollbackValue & vbCrLf & _
|
||||
"}" & vbCrLf
|
||||
Call DxToolsWriteUtf8Atomic(runRoot & "\apply-status.json", text)
|
||||
End Sub
|
||||
|
||||
Sub DxWriteProgress(runRoot, state)
|
||||
On Error Resume Next
|
||||
Call DxToolsWriteUtf8Atomic(runRoot & "\apply-progress.json", _
|
||||
"{" & vbCrLf & _
|
||||
" ""format_version"": 2," & vbCrLf & _
|
||||
" ""state"": """ & DxToolsJson(state) & """," & vbCrLf & _
|
||||
" ""updated"": """ & DxToolsJson(Now) & """" & vbCrLf & _
|
||||
"}" & vbCrLf)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
@@ -0,0 +1,338 @@
|
||||
' Expedition PCB bridge for the assembly refdes tidy-up. Keep this file ASCII-only.
|
||||
' Native migration of the legacy MoveAssemblyRef.vbs: the host exports fab
|
||||
' texts and component footprints, the portable exe computes the plan, and the
|
||||
' host applies it inside one undoable transaction.
|
||||
|
||||
Dim DxToolsHome
|
||||
|
||||
Sub DxToolsInstallExpeditionMenu()
|
||||
Dim menuBar
|
||||
Dim existing
|
||||
Dim button
|
||||
Dim i
|
||||
Dim caption
|
||||
|
||||
DxToolsHome = DxEpResolveRoot()
|
||||
If DxToolsHome = "" Then
|
||||
MsgBox "DxDesignerTools.exe not found next to this script.", _
|
||||
vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
caption = "Dx " & ChrW(&H6548) & ChrW(&H7387) & ChrW(&H5DE5) & ChrW(&H5177)
|
||||
Set menuBar = CommandBars("Document Menu Bar")
|
||||
For i = menuBar.Controls.Count To 1 Step -1
|
||||
Set existing = menuBar.Controls.Item(i)
|
||||
If existing.Caption = caption Then
|
||||
On Error Resume Next
|
||||
existing.Delete
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End If
|
||||
Next
|
||||
|
||||
Set DxExpeditionMenu = menuBar.Controls.Add(10) ' 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"
|
||||
End Sub
|
||||
|
||||
Sub DxExpeditionRunAssemblyRefdes()
|
||||
Dim app
|
||||
Dim docObj
|
||||
Dim requestText
|
||||
Dim planText
|
||||
Dim planPath
|
||||
Dim requestPath
|
||||
Dim fso
|
||||
Dim shell
|
||||
|
||||
Set app = Application
|
||||
Set docObj = DxEpGetLicensedDoc(app)
|
||||
If docObj Is Nothing Then Exit Sub
|
||||
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
requestPath = shell.ExpandEnvironmentStrings( _
|
||||
"%TEMP%\dx-assembly-request.txt")
|
||||
planPath = shell.ExpandEnvironmentStrings("%TEMP%\dx-assembly-plan.txt")
|
||||
|
||||
requestText = DxEpExportRequest(docObj)
|
||||
Call DxEpWriteAscii(requestPath, requestText)
|
||||
|
||||
Dim exec
|
||||
Dim commandLine
|
||||
commandLine = DxToolsQuote(DxToolsHome & "\DxDesignerTools.exe") & _
|
||||
" compute assembly-refdes --request " & DxToolsQuote(requestPath) & _
|
||||
" --output " & DxToolsQuote(planPath)
|
||||
On Error Resume Next
|
||||
Set exec = shell.Exec(commandLine)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
MsgBox "Cannot run DxDesignerTools.exe", vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
Do While exec.Status = 0
|
||||
Call DxEpSleep(50)
|
||||
Loop
|
||||
On Error GoTo 0
|
||||
If fso.FileExists(planPath) Then
|
||||
planText = DxEpReadAscii(planPath)
|
||||
Else
|
||||
planText = ""
|
||||
End If
|
||||
|
||||
Call DxEpApplyPlan(docObj, app, planText)
|
||||
End Sub
|
||||
|
||||
Function DxEpExportRequest(docObj)
|
||||
Dim fabtxts
|
||||
Dim fabtxt
|
||||
Dim lines
|
||||
Dim textIndex
|
||||
Dim componentLines
|
||||
Dim places
|
||||
Dim place
|
||||
Dim pa
|
||||
Dim dx
|
||||
Dim dy
|
||||
Dim sorted
|
||||
Dim x
|
||||
Dim y
|
||||
Dim temp
|
||||
Dim spans
|
||||
Dim componentKey
|
||||
Dim orientation
|
||||
Dim hasComponent
|
||||
|
||||
Set spans = CreateObject("Scripting.Dictionary")
|
||||
lines = ""
|
||||
componentLines = ""
|
||||
textIndex = 0
|
||||
Set fabtxts = docObj.FabricationLayerTexts( _
|
||||
epcbFabAll, epcbSelectAll, epcbSideTopOrBottom, True)
|
||||
|
||||
For Each fabtxt In fabtxts
|
||||
componentKey = ""
|
||||
orientation = ""
|
||||
hasComponent = False
|
||||
On Error Resume Next
|
||||
If Not fabtxt.Component Is Nothing Then
|
||||
hasComponent = True
|
||||
componentKey = CStr(fabtxt.Component.Name)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
componentKey = ""
|
||||
End If
|
||||
orientation = CStr(fabtxt.Component.Orientation)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
orientation = ""
|
||||
End If
|
||||
If componentKey <> "" And Not spans.Exists(componentKey) Then
|
||||
fabtxt.Component.Selected = True
|
||||
Err.Clear
|
||||
Set places = docObj.PlacementOutlines(epcbSelectSelected)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
Set places = Nothing
|
||||
End If
|
||||
dx = 0
|
||||
dy = 0
|
||||
If Not places Is Nothing Then
|
||||
For Each place In places
|
||||
pa = place.Geometry.Outline
|
||||
sorted = False
|
||||
Do While Not sorted
|
||||
sorted = True
|
||||
For x = 0 To UBound(pa, 2) - 1
|
||||
If pa(0, x) > pa(0, x + 1) Then
|
||||
temp = pa(0, x + 1)
|
||||
pa(0, x + 1) = pa(0, x)
|
||||
pa(0, x) = temp
|
||||
sorted = False
|
||||
End If
|
||||
Next
|
||||
Loop
|
||||
dx = (pa(0, UBound(pa, 2)) - pa(0, 0)) / 2
|
||||
sorted = False
|
||||
Do While Not sorted
|
||||
sorted = True
|
||||
For y = 0 To UBound(pa, 2) - 1
|
||||
If pa(1, y) > pa(1, y + 1) Then
|
||||
temp = pa(1, y + 1)
|
||||
pa(1, y + 1) = pa(1, y)
|
||||
pa(1, y) = temp
|
||||
sorted = False
|
||||
End If
|
||||
Next
|
||||
Loop
|
||||
dy = (pa(1, UBound(pa, 2)) - pa(1, 0)) / 2
|
||||
Next
|
||||
End If
|
||||
fabtxt.Component.Selected = False
|
||||
Err.Clear
|
||||
If componentLines <> "" Then componentLines = _
|
||||
componentLines & vbCrLf
|
||||
componentLines = componentLines & "C|" & componentKey & _
|
||||
"|" & CStr(fabtxt.Component.PositionX) & "|" & _
|
||||
CStr(fabtxt.Component.PositionY) & "|" & _
|
||||
CStr(dx) & "|" & CStr(dy)
|
||||
If Err.Number <> 0 Then Err.Clear
|
||||
spans.Add componentKey, True
|
||||
End If
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
|
||||
If lines <> "" Then lines = lines & vbCrLf
|
||||
lines = lines & "T|" & textIndex & _
|
||||
"|" & CStr(fabtxt.TextType) & _
|
||||
"|" & CStr(fabtxt.Side) & _
|
||||
"|" & IIf(fabtxt.Type = epcbFabAssembly, "1", "0") & _
|
||||
"|" & fabtxt.TextString & _
|
||||
"|" & orientation & _
|
||||
"|" & componentKey
|
||||
textIndex = textIndex + 1
|
||||
Next
|
||||
DxEpExportRequest = lines & vbCrLf & componentLines & vbCrLf
|
||||
End Function
|
||||
|
||||
Sub DxEpApplyPlan(docObj, app, planText)
|
||||
Dim fabtxts
|
||||
Dim fabtxt
|
||||
Dim index
|
||||
Dim lines
|
||||
Dim line
|
||||
Dim parts
|
||||
Dim planLines
|
||||
|
||||
Set planLines = CreateObject("Scripting.Dictionary")
|
||||
lines = Split(Replace(CStr(planText), vbCr, ""), vbLf)
|
||||
For Each line In lines
|
||||
If Len(line) > 0 Then
|
||||
parts = Split(line, "|")
|
||||
If UBound(parts) >= 1 Then
|
||||
If Not planLines.Exists(CStr(parts(1))) Then
|
||||
planLines.Add CStr(parts(1)), line
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
docObj.TransactionStart (epcbDRCModeDRC)
|
||||
app.LockServer
|
||||
index = 0
|
||||
Set fabtxts = docObj.FabricationLayerTexts( _
|
||||
epcbFabAll, epcbSelectAll, epcbSideTopOrBottom, True)
|
||||
For Each fabtxt In fabtxts
|
||||
If planLines.Exists(CStr(index)) Then
|
||||
Call DxEpApplyLine(planLines(CStr(index)), fabtxt)
|
||||
End If
|
||||
index = index + 1
|
||||
Next
|
||||
app.UnlockServer
|
||||
docObj.TransactionEnd (True)
|
||||
End Sub
|
||||
|
||||
Sub DxEpApplyLine(line, fabtxt)
|
||||
Dim parts
|
||||
parts = Split(line, "|")
|
||||
On Error Resume Next
|
||||
If parts(0) = "DELETE" Then
|
||||
fabtxt.Delete()
|
||||
ElseIf parts(0) = "MOVE" Then
|
||||
fabtxt.Format.VerticalJust = epcbJustifyVCenter
|
||||
fabtxt.Format.HorizontalJust = epcbJustifyHCenter
|
||||
fabtxt.Format.Font = parts(6)
|
||||
If parts(5) <> "" Then
|
||||
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)))
|
||||
End If
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Sub DxEpWriteAscii(path, text)
|
||||
Dim stream
|
||||
Set stream = CreateObject("Scripting.FileSystemObject"). _
|
||||
OpenTextFile(CStr(path), 2, True, 0)
|
||||
stream.Write CStr(text)
|
||||
stream.Close
|
||||
End Sub
|
||||
|
||||
Function DxEpReadAscii(path)
|
||||
Dim stream
|
||||
Set stream = CreateObject("Scripting.FileSystemObject"). _
|
||||
OpenTextFile(CStr(path), 1, False, 0)
|
||||
DxEpReadAscii = stream.ReadAll
|
||||
stream.Close
|
||||
End Function
|
||||
|
||||
Sub DxEpSleep(milliseconds)
|
||||
On Error Resume Next
|
||||
CreateObject("WScript.Shell").Run _
|
||||
"%ComSpec% /d /s /c ping -n 1 -w 100 127.0.0.1 > nul", 0, True
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
End Sub
|
||||
|
||||
Function DxEpResolveRoot()
|
||||
Dim fso
|
||||
Dim candidate
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
DxEpResolveRoot = ""
|
||||
On Error Resume Next
|
||||
candidate = CStr(WScript.ScriptFullName)
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
candidate = CStr(Scripting.ScriptFullName)
|
||||
End If
|
||||
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
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DxEpGetLicensedDoc(app)
|
||||
On Error Resume Next
|
||||
Dim key, licenseServer, licenseToken, docObj
|
||||
Set DxEpGetLicensedDoc = Nothing
|
||||
Set docObj = app.ActiveDocument
|
||||
If Err.Number <> 0 Then
|
||||
Call app.Gui.StatusBarText( _
|
||||
"No active document: " & Err.Description, epcbStatusFieldError)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Function
|
||||
End If
|
||||
key = docObj.Validate(0)
|
||||
Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
|
||||
licenseToken = licenseServer.GetToken(key)
|
||||
Set licenseServer = Nothing
|
||||
Err.Clear
|
||||
docObj.Validate (licenseToken)
|
||||
If Err.Number <> 0 Then
|
||||
Call app.Gui.StatusBarText( _
|
||||
"No active document license: " & Err.Description, _
|
||||
epcbStatusFieldError)
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Exit Function
|
||||
End If
|
||||
Set DxEpGetLicensedDoc = docObj
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
|
||||
'This part of the script sets up some menus for Demo Purposes
|
||||
' It adds a menu as the 8th item to the Sheet Menu Bar
|
||||
|
||||
|
||||
Dim SKY_env
|
||||
SKY_env= Scripting.GetEnvVariable("SKY_MT")
|
||||
|
||||
dim fred
|
||||
|
||||
|
||||
Set sMenu = CommandBars("Sheet Menu Bar").Controls.Add(cmdControlPopup)
|
||||
sMenu.Caption = "&SKY Tool"
|
||||
|
||||
'Add buttons to this menu
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "Help"
|
||||
fred = "wte " & SKY_env& "\readme.txt"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "Excel BOM"
|
||||
fred = "Form " & SKY_env& "\Bom.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
Option Explicit
|
||||
' Get the application object. It is understodd for internal scripts
|
||||
Dim pcbApp
|
||||
Set pcbApp = Application
|
||||
|
||||
Dim SKY_env
|
||||
SKY_env= Scripting.GetEnvVariable("SKY_MT")
|
||||
|
||||
' add icon to route menu bar
|
||||
'Dim cmdBars
|
||||
'Set cmdBars = Gui.CommandBars
|
||||
|
||||
'Dim RteToolBar, RteTBCntls, Btn1
|
||||
|
||||
'Set RteToolBar = gui.commandbars("Route")
|
||||
'Set RteTBCntls = RteToolBar.controls
|
||||
'Set Btn1 = RteTBCntls.Add(cmdControlButton)
|
||||
'Btn1.OnAction = "Run " + SKY_env + "\MoveAssemblyRef.vbs"
|
||||
'Btn1.TooltipText = "Auto Move Assembly RefDesigner"
|
||||
'Btn1.DescriptionText = "Run script: MoveAssemblyRef.vbs"
|
||||
'Btn1.BitmapFile = SKY_env + "\Icons\MoveAssemblyRef.bmp"
|
||||
|
||||
'add menu
|
||||
Dim sMenu
|
||||
Set sMenu = pcbApp.Gui.CommandBars("Document Menu Bar").Controls.Add(cmdControlPopup)
|
||||
sMenu.Caption = "&SKY Tool"
|
||||
|
||||
'Add buttons to this menu
|
||||
Dim sButton
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "×Ô¶¯µ÷Õû×°Åä²ãλºÅ"
|
||||
sButton.OnAction = "Run " + SKY_env + "\MoveAssemblyRef.vbs"
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 822 B |
@@ -0,0 +1,31 @@
|
||||
@ECHO OFF
|
||||
IF "%WDIR%" == "" GOTO NOPATH
|
||||
:YESPATH
|
||||
@ECHO MENTOR已安装
|
||||
pushd "%~dp0"
|
||||
|
||||
:win
|
||||
::如果SKY_MT为空,则未安装过,需要增加
|
||||
IF "%SKY_MT%" == "" GOTO win_add
|
||||
::不为空,则需要判断是否为当前路径
|
||||
wmic ENVIRONMENT where "name='SKY_MT'" get VariableValue|findstr /c:"%CD% ">nul&&(GOTO win_pathexist)
|
||||
::不是当前路径,则需要更新为当前路径
|
||||
wmic ENVIRONMENT where "name='SKY_MT' and username='<system>'" set VariableValue="%CD%"
|
||||
ECHO 变量已存在,但路径错误,已更改
|
||||
GOTO END
|
||||
:win_pathexist:
|
||||
ECHO 路径已存在
|
||||
GOTO END
|
||||
:win_add
|
||||
wmic ENVIRONMENT create name="SKY_MT",username="<system>",VariableValue="%CD%"
|
||||
wmic ENVIRONMENT where "name='WDIR' and username='<system>'" set VariableValue="%WDIR%;%%SKY_MT%%"
|
||||
GOTO END
|
||||
|
||||
:NOPATH
|
||||
@ECHO MENTOR未安装
|
||||
GOTO END
|
||||
:END
|
||||
wmic ENVIRONMENT where "name='WDIR'" get VariableValue
|
||||
wmic ENVIRONMENT where "name='SKY_MT'" get VariableValue
|
||||
|
||||
PAUSE
|
||||
@@ -0,0 +1,249 @@
|
||||
' ====================================================================
|
||||
' This program looks at all of the silkcreen and assembly reference designators and
|
||||
' changes any that are at 180 to 0 and at 270 to 90 and put them to the origin.
|
||||
'
|
||||
' This code is based on MoveAssemblyRef.vbs that is part of AATK 4.0
|
||||
' from Mentor Graphics
|
||||
'
|
||||
' Author: wuyongqing
|
||||
' Date : 2013.10.29
|
||||
' ====================================================================
|
||||
'
|
||||
'Option Explicit
|
||||
|
||||
'
|
||||
' The example below demonstrates the element manipulations
|
||||
' on a fabrication layer text.
|
||||
' It moves all the assembly text to the origin and changes the height and orientation
|
||||
' ====================================================================
|
||||
main
|
||||
|
||||
Sub main()
|
||||
' On Error Resume Next
|
||||
|
||||
Dim app 'As FablinkXEApplication ' MGCPCB.Application
|
||||
Set app = Application
|
||||
'Set app = GetObject(, "MGCPCB.FablinkXEApplication") '(, "MGCPCB.Application")
|
||||
|
||||
Dim docObj 'As MGCPCB.Document
|
||||
|
||||
Dim fabtxts 'As FabricationLayerTexts
|
||||
Dim fabtxt 'As FabricationLayerText
|
||||
Dim cnt, ori, dx, dy, pa, x, y, z, sorted, TheArray, Temp, n
|
||||
Dim place 'As PlacementOutline
|
||||
Dim places 'As PlacementOutlines
|
||||
|
||||
Dim MAXHEIGHT
|
||||
MAXHEIGHT = 0.8
|
||||
|
||||
' collect document object
|
||||
Set docObj = GetLicensedDoc(app)
|
||||
|
||||
If (docObj Is Nothing) Then Exit Sub
|
||||
|
||||
Dim size
|
||||
|
||||
Set fabtxts = docObj.FabricationLayerTexts(epcbFabAll, epcbSelectAll, epcbSideTopOrBottom, True) 'get a selection of all the fab layer texts
|
||||
cnt = fabtxts.Count
|
||||
|
||||
Call app.Gui.ProgressBarInitialize(True, "Progess", cnt, 0) 'initialize the progress bar from o to cnt
|
||||
cnt = 0
|
||||
|
||||
docObj.TransactionStart (epcbDRCModeDRC) ' make all the moves one single undable action
|
||||
app.LockServer 'speed up the process by locking the server
|
||||
|
||||
For Each fabtxt In fabtxts 'walk through all the fabrication layer texts
|
||||
|
||||
If Not fabtxt.Component Is Nothing Then 'if it is not text belonging to a component throw it out. Like board level texts.
|
||||
If fabtxt.TextType = 1 Then 'only 'epcbTextRefDes(1)' Type, Others will delete
|
||||
fabtxt.Component.Selected = True 'select the component
|
||||
'Call docObj.ActiveView.SetExtentsToSelection(False, True) 'zoom into the component
|
||||
|
||||
Set places = docObj.PlacementOutlines(epcbSelectSelected)
|
||||
|
||||
'docObj.ActiveView.SetExtentsToSelection
|
||||
|
||||
For Each place In places ' find the outside of the component to move the silkscreen text to
|
||||
'pa = place.Geometry.PointsArray
|
||||
pa = place.Geometry.Outline
|
||||
|
||||
sorted = False
|
||||
Do While Not sorted
|
||||
sorted = True
|
||||
For x = 0 To UBound(pa, 2) - 1
|
||||
If pa(0, x) > pa(0, x + 1) Then
|
||||
Temp = pa(0, x + 1)
|
||||
pa(0, x + 1) = pa(0, x)
|
||||
pa(0, x) = Temp
|
||||
sorted = False
|
||||
End If
|
||||
Next
|
||||
Loop
|
||||
dx = (pa(0, UBound(pa, 2)) - pa(0, 0)) / 2
|
||||
|
||||
sorted = False
|
||||
Do While Not sorted
|
||||
sorted = True
|
||||
For y = 0 To UBound(pa, 2) - 1
|
||||
If pa(1, y) > pa(1, y + 1) Then
|
||||
Temp = pa(1, y + 1)
|
||||
pa(1, y + 1) = pa(1, y)
|
||||
pa(1, y) = Temp
|
||||
sorted = False
|
||||
End If
|
||||
Next
|
||||
Loop
|
||||
dy = (pa(1, UBound(pa, 2)) - pa(1, 0)) / 2
|
||||
|
||||
Next
|
||||
|
||||
ori = fabtxt.Component.Orientation
|
||||
|
||||
fabtxt.Format.VerticalJust = epcbJustifyVCenter
|
||||
fabtxt.Format.HorizontalJust = epcbJustifyHCenter
|
||||
|
||||
n = Len(fabtxt.TextString)
|
||||
|
||||
If n < 5 Then
|
||||
'MsgBox fabtxt.TextString & vbCrLf & fabtxt.TextType & vbCrLf & fabtxt.Format.VerticalJust
|
||||
'fabtxt.Format.AspectRatio = 1
|
||||
fabtxt.Format.Font = "Arial"
|
||||
'fabtxt.Format.Height = 0.42
|
||||
ElseIf n < 6 Then
|
||||
fabtxt.Format.Font = "Arial Narrow"
|
||||
'fabtxt.Format.Height = 0.42
|
||||
Else
|
||||
fabtxt.Format.Font = "Arial Narrow"
|
||||
fabtxt.Format.Height = 0.35
|
||||
End If
|
||||
|
||||
'if n > 3 then'fabtxt.TextString = "CT26" Then
|
||||
' MsgBox "dx="&dx & "dy="&dy&vbCrLf & "x,y=" &fabtxt.Component.PositionX &","& fabtxt.Component.PositionY&vbCrLf &pa(0, UBound(pa, 2))&","&pa(0,0)&"y="&pa(1, UBound(pa, 2))&","&pa(1,0) &", UBound="& UBound(pa, 2)&",side="&fabtxt.Side
|
||||
'end if
|
||||
|
||||
If ori = 0 Or ori = 180 Then
|
||||
fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 0 'if the text is rotated at 0 or 180 make it 0
|
||||
|
||||
If fabtxt.Type = epcbFabAssembly Then
|
||||
if dy < 0.1 Or dy > MAXHEIGHT Then
|
||||
dy = MAXHEIGHT
|
||||
end if
|
||||
fabtxt.Format.Height(epcbUnitMM) = dy
|
||||
'fabtxt.Format.Penwidth(epcbUnitMM) = qing
|
||||
sss = fabtxt.Component.PositionX 'PositionX(epcbUnitMM)
|
||||
Call fabtxt.Move(fabtxt.Component.PositionX, fabtxt.Component.PositionY)' + dy)', epcbUnitMils)
|
||||
End If
|
||||
|
||||
ElseIf ori = 90 Or ori = 270 Then
|
||||
If fabtxt.Side = 1 Then 'On Top layer
|
||||
fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 90
|
||||
Else
|
||||
fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 270
|
||||
End If
|
||||
|
||||
If fabtxt.Type = epcbFabAssembly Then
|
||||
if dx < 0.1 Or dx > MAXHEIGHT Then
|
||||
dx = MAXHEIGHT
|
||||
end if
|
||||
fabtxt.Format.Height(epcbUnitMM) = dx
|
||||
'fabtxt.Format.Penwidth(epcbUnitMM) = qing
|
||||
'Call fabtxt.Move(fabtxt.Component.PositionX + dx, fabtxt.Component.PositionY)', epcbUnitMils)
|
||||
Call fabtxt.Move(fabtxt.Component.PositionX, fabtxt.Component.PositionY) ', epcbUnitMils)
|
||||
End If
|
||||
ElseIf ori = 45 Or ori = 225 Then
|
||||
fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 45
|
||||
|
||||
If fabtxt.Type = epcbFabAssembly Then
|
||||
dx = (pa(0, UBound(pa, 2)) - pa(0, 0)) * 0.54 / 2
|
||||
if dx < 0.1 Or dx > MAXHEIGHT Then
|
||||
dx = MAXHEIGHT
|
||||
end if
|
||||
fabtxt.Format.Height(epcbUnitMM) = dx
|
||||
'fabtxt.Format.Penwidth(epcbUnitMM) = qing
|
||||
'Call fabtxt.Move(fabtxt.Component.PositionX + dx, fabtxt.Component.PositionY)', epcbUnitMils)
|
||||
Call fabtxt.Move(fabtxt.Component.PositionX, fabtxt.Component.PositionY) ', epcbUnitMils)
|
||||
End If
|
||||
ElseIf ori = 135 Or ori = 315 Then
|
||||
fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 315
|
||||
|
||||
If fabtxt.Type = epcbFabAssembly Then
|
||||
dx = (pa(0, UBound(pa, 2)) - pa(0, 0)) * 0.54 / 2
|
||||
if dx < 0.1 Or dx > MAXHEIGHT Then
|
||||
dx = MAXHEIGHT
|
||||
end if
|
||||
fabtxt.Format.Height(epcbUnitMM) = dx
|
||||
'fabtxt.Format.Penwidth(epcbUnitMM) = qing
|
||||
'Call fabtxt.Move(fabtxt.Component.PositionX + dx, fabtxt.Component.PositionY)', epcbUnitMils)
|
||||
Call fabtxt.Move(fabtxt.Component.PositionX, fabtxt.Component.PositionY) ', epcbUnitMils)
|
||||
End If
|
||||
ElseIf ori > 90 And ori < 270 Then
|
||||
fabtxt.Format.Height(epcbUnitMM) = 0.4
|
||||
fabtxt.Format.Orientation(epcbAngleUnitDegrees) = ori + 180
|
||||
Call fabtxt.Move(fabtxt.Component.PositionX, fabtxt.Component.PositionY)
|
||||
Else
|
||||
fabtxt.Format.Height(epcbUnitMM) = 0.4
|
||||
fabtxt.Format.Orientation(epcbAngleUnitDegrees) = ori
|
||||
Call fabtxt.Move(fabtxt.Component.PositionX, fabtxt.Component.PositionY)
|
||||
End If
|
||||
|
||||
app.Gui.ProgressBar (cnt)
|
||||
cnt = cnt + 1
|
||||
|
||||
fabtxt.Component.Selected = False
|
||||
Else
|
||||
fabtxt.Delete()
|
||||
End If
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
app.UnlockServer 'unlock the server
|
||||
|
||||
docObj.TransactionEnd (True) 'end the make it all one undo
|
||||
app.Gui.ProgressBarInitialize (False)
|
||||
End Sub
|
||||
|
||||
'
|
||||
' This function retrieves an automation license for a document
|
||||
'
|
||||
' Returns:
|
||||
' - 'Nothing' if licensing failed .
|
||||
' - A reference to the active document of the application if
|
||||
' licensing succeeded.
|
||||
'
|
||||
Public Function GetLicensedDoc(app)
|
||||
On Error Resume Next
|
||||
Dim key, licenseServer, licenseToken, docObj
|
||||
|
||||
Set GetLicensedDoc = Nothing
|
||||
|
||||
' collect the active document
|
||||
Set docObj = app.ActiveDocument
|
||||
|
||||
If (Err) Then
|
||||
Call app.Gui.StatusBarText("No active document: " + Err.Description, epcbStatusFieldError)
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
' Ask Expedition’s document for the key
|
||||
key = docObj.Validate(0)
|
||||
|
||||
' Get token from license server
|
||||
Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
|
||||
licenseToken = licenseServer.GetToken(key)
|
||||
Set licenseServer = Nothing
|
||||
|
||||
' Ask the document to validate the license token
|
||||
Err.Clear
|
||||
|
||||
docObj.Validate (licenseToken)
|
||||
|
||||
If (Err) Then
|
||||
Call app.Gui.StatusBarText("No active document license: " + Err.Description, epcbStatusFieldError)
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
' everything is OK, return document
|
||||
Set GetLicensedDoc = docObj
|
||||
|
||||
End Function
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
EE7.9.5 BOM导出工具 20160830
|
||||
|
||||
功能描述:
|
||||
1、支持EE7.9.5 版本 BOM 按页导出到一个xls文件,导出格式可直接粘贴到BOM制作工具中。
|
||||
2、支持同一页中相同料号和描述的位号自动合并,同一料号不同描述的位号高亮显示。
|
||||
3、支持料号与描述一致性检查,不一致时料号红色高亮显示。
|
||||
4、支持描述中带“NC”关键字的物料自动删除,或者高亮显示。
|
||||
5、支持位号唯一性检查,位号不唯一时位号红色高亮显示。
|
||||
6、临时料号红色高亮显示。
|
||||
7、带有“USE”关键字的描述红色高亮显示。
|
||||
8、MARK、MOUNTHOLE等物料高亮显示。
|
||||
|
||||
安装方法:
|
||||
双击Intall.bat完成安装,Win7及以上版本请右键以管理权限安装。
|
||||
或者手动添加环境变量完成安装:
|
||||
1、新建环境变量SKY_MT,值为BOM导出工具的路径。
|
||||
2、修改WDIR环境变量,在后面增加%SKY_MT%。
|
||||
|
||||
|
||||
使用方法:
|
||||
打开需要导出BOM的EE7.9工程文件,使用“文件” ---- “打开” ---- “文件” 打开“Open File”
|
||||
对话框,修改文件类型为“Script Forms(*.efm)”,打开BOM导出工具目录下的BOM.efm文件。
|
||||
在打开的对话框中点击“ComponentList”按钮,稍等即可自动生成BOM。如果需要删除NC物料,
|
||||
请勾选“Delete NC component”选项。生成的BOM如需保存,请使用另存为。
|
||||
|
||||
|
||||
注意事项:
|
||||
1、BOM导出工具及项目工程文件的路径不能包含中文和空格。
|
||||
2、位号为“Ref Designator”项,料号为“Part Number”项,描述为“VALUE”项。
|
||||
3、有任何问题请联系 XiongYongZhao@skyworth.com
|
||||
|
||||
20160830更新内容:
|
||||
1、修复BOM导出时错乱的问题。
|
||||
2、增加料号与描述一致性检查功能,目前支持电阻、电容、电感三类。临时物料、空描述、带有
|
||||
USE关键字的物料不检查。不匹配时料号单元格底色为黄色高亮。
|
||||
3、增加位号唯一性检查功能,在导出后的BOM中,同一位号单元格底色为红色高亮。
|
||||
|
||||
已知问题:
|
||||
1、0~10R的电阻,系统中有两种物料编码规则,暂时只支持一种。
|
||||
2、电阻单位只支持R、K、M,电容只支持P、N、U,电感只支持U、M、H,无单位或者其它单位可能
|
||||
误报,请反馈。
|
||||
@@ -0,0 +1,7 @@
|
||||
;DxDesigner stuff
|
||||
[Viewdraw]
|
||||
Script#0=%SKY_MT%/DxMenuAdd.vbs
|
||||
脚本#0=%SKY_MT%/DxMenuAdd.vbs
|
||||
|
||||
[Expedition PCB]
|
||||
Script#0=%SKY_MT%/ExMenuAdd.vbs
|
||||
Binary file not shown.
@@ -0,0 +1,76 @@
|
||||
|
||||
'This part of the script sets up some menus for Demo Purposes
|
||||
' It adds a menu as the 9th item to the Sheet Menu Bar
|
||||
|
||||
|
||||
'Dim SKY_env
|
||||
'SKY_env= Scripting.GetEnvVariable("SKY_MT")
|
||||
|
||||
Dim fred
|
||||
|
||||
|
||||
Set sMenu = CommandBars("Sheet Menu Bar").Controls.Add(cmdControlPopup,,,9)
|
||||
sMenu.Caption = "一叶知秋(&Y)"
|
||||
|
||||
'Add buttons to this menu
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "孤立网络检查(&G)"
|
||||
fred = "Form " & "D:\NET_CHECK\NET-solitary.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "网络跨页互动(&K)"
|
||||
fred = "Form " & "D:\NET_CHECK\NET-interactive.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "全部网络列表(&N)"
|
||||
fred = "Form " & "D:\NET_CHECK\NET-List.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "位号批量命名(&W)"
|
||||
fred = "Form " & "D:\NET_CHECK\PART_Ref_CHA.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "Value批量修改(&V)"
|
||||
fred = "Form " & "D:\NET_CHECK\PART_Value_CHA.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "Value1批量修改(&V1)"
|
||||
fred = "Form " & "D:\NET_CHECK\PART_Value1_CHA.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "BOM导出(&B)"
|
||||
fred = "Form " & "D:\NET_CHECK\BOM_output\Bom.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "物料编号修改(&W)"
|
||||
fred = "Form " & "D:\NET_CHECK\PART_PartNumber_CHA.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "PartName批量隐藏(&P)"
|
||||
fred = "Form " & "D:\NET_CHECK\PartName_Hide.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "PartLabel批量隐藏(&L)"
|
||||
fred = "Form " & "D:\NET_CHECK\PartLabel_Hide.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "Value值遗漏查找(&VY)"
|
||||
fred = "Form " & "D:\NET_CHECK\Value_Check_Miss.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Set sButton = sMenu.Controls.Add
|
||||
sButton.Caption = "Value1值遗漏查找(&V1Y)"
|
||||
fred = "Form " & "D:\NET_CHECK\Value1_Check_Miss.efm"
|
||||
sButton.OnAction = fred
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user