I’m attempting to retrieve the name of the linked cut-list table in the drawing using the GetKeepLinkedToBOMName method. Unfortunately, this method does not provide the linked cut-list name as expected. It functions perfectly for Bills Of Materials (BOM), but not for cut-list table…
The GetKeepLinkedToBOM method works OK for both BOM and cut-list table.
Checking with the community to see if anyone has discovered any workarounds. Thank you.
1 Like
This is a bit of a bad hack IMO but it works:
Preconditions: Have view pre-selected on drawing before running this macro
Option Explicit
#If Win64 Then
Private Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function FindWindowEx Lib "User32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare PtrSafe Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Const WM_GETTEXT As Long = &HD
Private Const WM_GETTEXTLENGTH As Long = &HE
#End If
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swSelMgr As SelectionMgr
Dim swView As View
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject6(1, -1)
swApp.RunCommand swCommands_Properties, Empty
Dim caption As String
caption = FindLinkedBOMCaption() 'Gets caption from opened dialog window '
Debug.Print caption
swApp.RunCommand swCommands_e.swCommands_PmCancel, Empty
End Sub
Function FindLinkedBOMCaption() As String
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "Drawing View Properties")
Dim myControl As Long
Dim myControl2 As Long
myControl = FindWindowEx(hwnd, 0&, vbNullString, vbNullString)
myControl2 = FindWindowEx(myControl, 0&, vbNullString, "Balloons")
myControl = FindWindowEx(myControl, myControl2, "ComboBox", vbNullString)
Dim sLen As Long
sLen = SendMessage(myControl, WM_GETTEXTLENGTH, 0, ByVal 0&)
Dim sBuffer As String
sBuffer = Space(sLen)
Dim sStr As String
SendMessage myControl, WM_GETTEXT, sLen + 1, ByVal sBuffer
'Debug.Print hwnd & " Contents: [" & sBuffer & "]" '
FindLinkedBOMCaption = sBuffer
End Function
2 Likes
Thank you Alex, it is a bit crazy workaround but it works.
2 Likes