Jump to content

Help:Get Combobox list and popup new combobox


 Share

Go to solution Solved by Nine,

Recommended Posts

Hello Everyone,

Hope everyone being safe and well.

I'm newbie here, I'm facing an issue to get combobox list.

There is a Combobox in AutoCAD, it has list of Dynamic List. so i want to get the list and then display for user selection.

I found the Code on Help page, but it's displays only the Drives. Could you please help me to get rid of this.

 

Combobox Info:

>>>> Control <<<<
Class:    SNET$combobox
Instance:    1
ClassnameNN:    SNET$combobox1
Name:    
Advanced (Class):    [CLASS:SNET$combobox; INSTANCE:1]
ID:    8193
Text:    

>>>> Control <<<<
Class:  SNET$combobox
Instance:   1
ClassnameNN:    SNET$combobox1
Name:   
Advanced (Class):   [CLASS:SNET$combobox; INSTANCE:1]
ID: 8193

 Found this code on Help Page:

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $g_idMemo

Example()

Func Example()
    Local $aList, $idCombo
    Opt("GUIDataSeparatorChar", ",") ; set seperator char to char we want to use

    ; Create GUI
    GUICreate("ComboBox Get List", 400, 296)
    $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    ; Add files
    _GUICtrlComboBox_AddDir($idCombo, "", $DDL_DRIVES, False)

    ; Get List
    $aList = StringSplit(_GUICtrlComboBox_GetList($idCombo), ",")
    For $x = 1 To $aList[0]
        MemoWrite($aList[$x])
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Attached the Combobox, This Dynamic , so each time these list has been changed.

 

Thanks in Advance.

 

Combobox.jpg

Link to comment
Share on other sites

The problem with your request is that it is very unclear.  You ask how to get info from another app but you show no effort in doing so.  Where is the code that you tried to get the content of the external combo box ?  How you make sure that the other app is running ?  What is the name of the app ?  What is the aut3info tool saying about the window (not just the control) ?  And many other questions, but I'll stop here. 

Make sure you clearly states your request if you want help...

Link to comment
Share on other sites

Hi Nine,

Thanks for your reply,

The App is running on Background, and the App Name is AutoCAD 2018,

Please find the Info of the Combobox.

Here is the code I tried,

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $g_idMemo

Example()
Opt("WinTitleMatchMode", 2)
WinActivate("Autodesk AutoCAD Map 3D 2018")
sleep(400)
WinWait("Autodesk AutoCAD Map 3D 2018")
sleep(400)
Opt("WinTitleMatchMode", 2)
WinWait("Add port mapping for ")
sleep(500)
WinActivate("Add port mapping for ")
sleep(500)
$hCombo =ControlGetHandle("Add port mapping for", "", "[CLASS:SNET$combobox; INSTANCE:4]")

Func Example()
    Local $aList, $idCombo
    Opt("GUIDataSeparatorChar", ",") ; set seperator char to char we want to use

    ; Create GUI
    GUICreate("ComboBox Get List", 400, 296)
    $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
       $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    ; Add files
  ; _GUICtrlComboBox_AddDir($idCombo, "", $DDL_DRIVES, False)
_GUICtrlComboBox_AddDir($idCombo, "", $hCombo, False)
    ; Get List
    $aList = StringSplit(_GUICtrlComboBox_GetList($idCombo), ",")
    For $x = 1 To $aList[0]
        MemoWrite($aList[$x])
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Please let me know if anything.

Thanks.

Info.jpg

Link to comment
Share on other sites

Well, Example function is executed BEFORE you initialize $hCombo !

Also, I cannot recommend more that you add some error handling in your code, checking for return values of the functions you call and also @error.  That way you can know if the statement you just executed is successful or not.

Link to comment
Share on other sites

Link to comment
Share on other sites

OK, try this from Scite and report full console here :

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $g_idMemo, $hCombo
Local $vResult
Opt("WinTitleMatchMode", 2)
$vResult = WinActivate("Autodesk AutoCAD Map 3D 2018")
ConsoleWrite($vResult & "/" & @error & @CRLF)
$vResult = WinWait("Autodesk AutoCAD Map 3D 2018")
ConsoleWrite($vResult & "/" & @error & @CRLF)
$vResult = WinWait("Add port mapping for")
ConsoleWrite($vResult & "/" & @error & @CRLF)
$vResult = WinActivate("Add port mapping for")
ConsoleWrite($vResult & "/" & @error & @CRLF)
$hCombo = ControlGetHandle("Add port mapping for", "", "[CLASS:SNET$combobox; INSTANCE:4]")
ConsoleWrite($hCombo & "/" & @error & @CRLF)
Local $iCount = _GUICtrlComboBox_GetCount($hCombo)
If $iCount <= 0 Then Exit ConsoleWrite("unable to read combo" & @CRLF)
Global $sList = _GUICtrlComboBox_GetList($hCombo)
ConsoleWrite($sList & @CRLF)

Example()

Func Example()
    Local $aList, $idCombo
    ;Opt("GUIDataSeparatorChar", ",") ; set seperator char to char we want to use

    ; Create GUI
    GUICreate("ComboBox Get List", 400, 296)
    $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    GUICtrlSetData($idCombo, $sList)
    $aList = StringSplit(_GUICtrlComboBox_GetList($idCombo), "|")
    For $x = 1 To $aList[0]
        MemoWrite($aList[$x])
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
  ConsoleWrite($sMessage & @CRLF)
  GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Please study the code carefully.  I added some error handling like I told you to do.  Report full console here, so we can understand what is going on...

Link to comment
Share on other sites

Hello Nine,

Thank you so much, 

It's getting the list of items from the Combobox and shows in new drop down. but i can't able to select the Item in that new dropdown.

 

Here is the console output,

0x0004081A/0
0x0004081A/0
0x00040AE4/0
0x00040AE4/0
0x00040AFA/0
72FiberBypass|72FiberFeeder|DEFECTIVESPLTRPORTS2092A|FDHDistribution1432|FDHDistribution433864|SPLTR1|SPLTR2|SPLTR3|SPLTR4|SPLTR5|SPLTR6|SPLTR7|SPLTR8|SPLTR9|SPLTR10
72FiberBypass
72FiberFeeder
DEFECTIVESPLTRPORTS2092A
FDHDistribution1432
FDHDistribution433864
SPLTR1
SPLTR2
SPLTR3
SPLTR4
SPLTR5
SPLTR6
SPLTR7
SPLTR8
SPLTR9
SPLTR10

 

New drop down, created by Autoit.

image.png.a1e2a1292cc0d22c70c1ab7fe0f9028a.png

 

Thank you once again.

Edited by SNET2022
Link to comment
Share on other sites

SNET

You can select item using either:

_GUICtrlListBox_SelectString($g_idMemo,"FDHDistribution433864")

or 

_GUICtrlListBox_SetCurSel ($g_idMemo, 0);select item at 0 position

to get item use:

_GUICtrlListBox_GetText($g_idMemo,_GUICtrlListBox_GetCurSel($g_idMemo))

 

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

Link to comment
Share on other sites

Or is it this ?

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>


Global $g_idMemo, $hCombo
Local $vResult
Opt("WinTitleMatchMode", 2)
$vResult = WinActivate("Autodesk AutoCAD Map 3D 2018")
ConsoleWrite($vResult & "/" & @error & @CRLF)
$vResult = WinWait("Autodesk AutoCAD Map 3D 2018")
ConsoleWrite($vResult & "/" & @error & @CRLF)
$vResult = WinWait("Add port mapping for")
ConsoleWrite($vResult & "/" & @error & @CRLF)
$vResult = WinActivate("Add port mapping for")
ConsoleWrite($vResult & "/" & @error & @CRLF)
$hCombo = ControlGetHandle("Add port mapping for", "", "[CLASS:SNET$combobox; INSTANCE:4]")
ConsoleWrite($hCombo & "/" & @error & @CRLF)
Local $iCount = _GUICtrlComboBox_GetCount($hCombo)
If $iCount <= 0 Then Exit ConsoleWrite("unable to read combo" & @CRLF)
Global $sList = _GUICtrlComboBox_GetList($hCombo)
ConsoleWrite($sList & @CRLF)
Global $sCurrent = _GUICtrlComboBox_GetEditText($hCombo)
ConsoleWrite($sCurrent & "/" & @error & @CRLF)

Example()

Func Example()
  Local $aList, $idCombo
  ;Opt("GUIDataSeparatorChar", ",") ; set seperator char to char we want to use

  ; Create GUI
  GUICreate("ComboBox Get List", 400, 296)
  $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
  $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
  GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
  GUISetState(@SW_SHOW)

  GUICtrlSetData($idCombo, $sList, $sCurrent)
  $aList = StringSplit(_GUICtrlComboBox_GetList($idCombo), "|")
  For $x = 1 To $aList[0]
    MemoWrite($aList[$x])
  Next
  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        Exit
      Case $idCombo
        ControlCommand("Add port mapping for", "", "[CLASS:SNET$combobox; INSTANCE:4]", "SelectString", GUICtrlRead($idCombo))
    EndSwitch
  WEnd
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
  ConsoleWrite($sMessage & @CRLF)
  GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

 

Link to comment
Share on other sites

Hi, 

I just have added a button to select, and tried it. But i can select from dropdown, but that Text not reflecting in that Combobox (in AutoCAD application.

 

I did some changes on this code.

Func Example()
  Local $aList, $idCombo
  ;Opt("GUIDataSeparatorChar", ",") ; set seperator char to char we want to use

  ; Create GUI
  GUICreate("ComboBox Get List", 400, 296)
  $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
  $g_idMemo = GUICtrlCreateEdit("", 2, 32, 300, 266, 0)
  GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
  GUISetState(@SW_SHOW)
  $Button_1 = GUICtrlCreateButton("SELECT", 310,50, 80, 30)

  GUICtrlSetData($idCombo, $sList, $sCurrent)
  $aList = StringSplit(_GUICtrlComboBox_GetList($idCombo), "|")
  For $x = 1 To $aList[0]
    MemoWrite($aList[$x])
  Next
  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        Exit
    ; Case $idCombo
         Case $Button_1
       ; ControlCommand("Add port mapping for", "", "[CLASS:SNET$combobox; INSTANCE:4]", "SelectString", GUICtrlRead($idCombo))
        $CBBox3=GUICtrlRead($idCombo)
    EndSwitch
  WEnd
EndFunc   ;==>Example
$hCombo = ControlGetHandle("Add port mapping for", "", "[CLASS:SNET$combobox; INSTANCE:4]")
_GUICtrlComboBox_SelectString($hCombo,$CBBox3)

; Write a line to the memo control
Func MemoWrite($sMessage)
  ConsoleWrite($sMessage & @CRLF)
  GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

 

Link to comment
Share on other sites

Do not put code in between functions.  That is a terrible way to program.  Replace your case with this one :

Case $Button_1
    $vResult = _GUICtrlComboBox_SelectString($hCombo, GUICtrlRead($idCombo))
    ConsoleWrite($vResult & "/" & @error & @CRLF)

 

Link to comment
Share on other sites

Hello Nine,

Sorry for changing your code.

Everything works fine now, but when i select SPLTR1 on Autoit combobox, SPLTR10 is updated on AutoCAD Combobox,

same time, If i select SPLTR10 on Autoit combobox, SPLTR10 is updated on AutoCAD Combobox, all other SPLTR2,3,4,5...works fine.

image.png.9fdb8b73016ae1b3df33fbf6a2974b67.png 

 

Thanks.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...