Jump to content

Facing issue in GUI command - (Moved)


Recommended Posts

Hi,

I'm here trying to select a process in drop down. The selected option should redirects to an excel sheet. There it'll take input of picture names. With these pictures names, it should copy the respective pictures from separate folder and finally it should paste on the desired window. 

I'm able to do upto the drop down. The button command is not working. When I click button, It should close drop down popup and starts pasting pictures on the composer. Kindly give me your suggestion.

 

This is my code.

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Excel.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

WinActivate("X Composer") ; activating software composer(name sake)


HotKeySet("{ESC}",bye) ; hot key to force stop script

Func bye()
   Exit
EndFunc

$pictoPath = "C:\Desktop\Pictures Library"   

$hndl = WinGetHandle("X Composer")
$className = _WinAPI_GetClassName($hndl)
$endian = StringRight($className,16)

WinActivate("X Composer")

;Get the Top Position of the WorksSheet
$cPos = ControlGetPos("X Composer","","Afx:0000000140000000:2b:0000000000010005:" & $endian & "1")
$w = $cPos[2]
$h = $w*0.615
ConsoleWrite("Width:" & $w & @CRLF)
ConsoleWrite("Height:" & $h & @CRLF)
$xPos = $cPos[0]
$yPos = $cPos[1] + ($cPos[3]-$h)/2


Local $hGUI = GuiCreate("Pictogram Sequencing", 500, 200)
$cmb1 = GUICtrlCreateCombo("Select a Process", 10, 10, 200, 60)
    GUICtrlSetData($cmb1, "DRILLING|INSTALLATION|DEBURRING|GROUNDING|REVETING|WELDING", "Select a day")
$cmb2 = GUICtrlCreateCombo("Select a Sub Process", 250, 10, 200, 60)

GUISetState(@SW_SHOW)
$Button1 = GUICtrlCreateButton("Select", 60, 100, 65, 17)
    ;Local $idButton = GUICtrlCreateButton( "Select", 10, 200, 195, 20 )
    ;Local $idLabel = GUICtrlCreateLabel( "", 215, 200, 195, 20, $SS_ETCHEDFRAME )
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cmb1
                Switch GUICtrlRead($cmb1)
                    Case "DRILLING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|DRILL 1|DRILL 2|DRILL 3", "Select a Sub Process")
                    Case "INSTALLATION"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|PART INSTALLATION|CARPET INSTALLATION|CABINET INSTALLATION|DIVAN INSTALLATION", "Select a Sub Process")
                    Case "DEBURRING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|DRILL DEBUR|PART DEBUR|WELD DEBUR", "Select a Sub Process")
                    Case "GROUNDING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|GROUNDING INSPECTION|PART GROUNDING", "Select a Sub Process")
                    Case "REVETING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|PARTS REVETING|SURFACE REVETING|STRUCTURE REVETING", "Select a Sub Process")
                    Case "WELDING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|MIG WELDING|TIG WELDING|ARC WELDING", "Select a Sub Process")
                     Case $Button1
                        ExpandGUI()

                EndSwitch
        EndSwitch
     WEnd

     Func ExpandGUI()
;Get the Process List from Excel
$oBook = _Excel_BookAttach("C:\Desktop\Input.xlsx")
$Count = $oBook.Sheets($cmb1).UsedRange.Rows.Count
$process = _Excel_RangeRead($oBook,Default,"A2:A" & $count)


WinActivate("X Composer")
_ClipPutFile($pictoPath & "\" & $process[0] & ".jpg")
$hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[0] & ".jpg")
$imgH = _GDIPlus_ImageGetHeight($hImage)
;MsgBox($MB_SYSTEMMODAL, " ", $imgH)
;ConsoleWrite($i&$imgH & "-" & $diff & @CRLF)
$currYPos = $currYPos + $h*0.157
$currXPos = ($xPos+80/(968/$w))
MouseMove($xPos+80/(968/$w),$currYPos)
Send("^v")


_GDIPlus_Startup()
$currYPos = $yPos-20/(1103/$h)
MouseMove($xPos+80/(968/$w),$currYPos)

WinActivate("X Composer") 
_ClipPutFile($pictoPath & "\" & $process[0] & ".jpg")
$hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[0] & ".jpg")
$imgH = _GDIPlus_ImageGetHeight($hImage)
$currYPos = $currYPos + $h*0.157
MouseMove($xPos+80/(968/$w),$currYPos)
Send("^v")

For $i = 1 to 5 ;Ubound($Data)-1
   WinActivate("X Composer")
   _ClipPutFile($pictoPath & "\" & $process[$i] & ".jpg")
   $hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[$i-2] & ".jpg")
   $imgH = _GDIPlus_ImageGetHeight($hImage)
   $diff = ($imgH-476)*0.4/(1103/$h) + 10/(1103/$h)
   ConsoleWrite($imgH & "-" & $diff & @CRLF)
   $currYPos = $currYPos + $h*0.157 + $diff
   MouseMove($xPos+80/(968/$w),$currYPos)
   Send("^v")
Next

;If check for 4 to decide on the X POS

For $i = 4 to Ubound($Data)-1

Next

_GDIPlus_Shutdown()


     EndFunc

 

 

 

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi,

I'm here trying to select a process in drop down. The selected option should redirects to an excel sheet. There it'll take input of picture names. With these pictures names, it should copy the respective pictures from separate folder and finally it should paste on the desired window. 

I'm able to do up to the drop down. The button command is not working. When I click button, It should close drop down popup and starts pasting pictures on the composer. Kindly give me your suggestion.

 

This is my code.

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Excel.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

WinActivate("X Composer") ; activating software composer(name sake)


HotKeySet("{ESC}",bye) ; hot key to force stop script

Func bye()
   Exit
EndFunc

$pictoPath = "C:\Desktop\Pictures Library"   

$hndl = WinGetHandle("X Composer")
$className = _WinAPI_GetClassName($hndl)
$endian = StringRight($className,16)

WinActivate("X Composer")

;Get the Top Position of the WorksSheet
$cPos = ControlGetPos("X Composer","","Afx:0000000140000000:2b:0000000000010005:" & $endian & "1")
$w = $cPos[2]
$h = $w*0.615
ConsoleWrite("Width:" & $w & @CRLF)
ConsoleWrite("Height:" & $h & @CRLF)
$xPos = $cPos[0]
$yPos = $cPos[1] + ($cPos[3]-$h)/2


Local $hGUI = GuiCreate("Pictogram Sequencing", 500, 200)
$cmb1 = GUICtrlCreateCombo("Select a Process", 10, 10, 200, 60)
    GUICtrlSetData($cmb1, "DRILLING|INSTALLATION|DEBURRING|GROUNDING|REVETING|WELDING", "Select a day")
$cmb2 = GUICtrlCreateCombo("Select a Sub Process", 250, 10, 200, 60)

GUISetState(@SW_SHOW)
$Button1 = GUICtrlCreateButton("Select", 60, 100, 65, 17)
    ;Local $idButton = GUICtrlCreateButton( "Select", 10, 200, 195, 20 )
    ;Local $idLabel = GUICtrlCreateLabel( "", 215, 200, 195, 20, $SS_ETCHEDFRAME )
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cmb1
                Switch GUICtrlRead($cmb1)
                    Case "DRILLING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|DRILL 1|DRILL 2|DRILL 3", "Select a Sub Process")
                    Case "INSTALLATION"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|PART INSTALLATION|CARPET INSTALLATION|CABINET INSTALLATION|DIVAN INSTALLATION", "Select a Sub Process")
                    Case "DEBURRING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|DRILL DEBUR|PART DEBUR|WELD DEBUR", "Select a Sub Process")
                    Case "GROUNDING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|GROUNDING INSPECTION|PART GROUNDING", "Select a Sub Process")
                    Case "REVETING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|PARTS REVETING|SURFACE REVETING|STRUCTURE REVETING", "Select a Sub Process")
                    Case "WELDING"
                        GUICtrlSetData($cmb2, "")
                        GUICtrlSetData($cmb2, "Select a Sub Process|MIG WELDING|TIG WELDING|ARC WELDING", "Select a Sub Process")
                     Case $Button1
                        ExpandGUI()

                EndSwitch
        EndSwitch
     WEnd

     Func ExpandGUI()
;Get the Process List from Excel
$oBook = _Excel_BookAttach("C:\Desktop\Input.xlsx")
$Count = $oBook.Sheets($cmb1).UsedRange.Rows.Count
$process = _Excel_RangeRead($oBook,Default,"A2:A" & $count)


WinActivate("X Composer")
_ClipPutFile($pictoPath & "\" & $process[0] & ".jpg")
$hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[0] & ".jpg")
$imgH = _GDIPlus_ImageGetHeight($hImage)
;MsgBox($MB_SYSTEMMODAL, " ", $imgH)
;ConsoleWrite($i&$imgH & "-" & $diff & @CRLF)
$currYPos = $currYPos + $h*0.157
$currXPos = ($xPos+80/(968/$w))
MouseMove($xPos+80/(968/$w),$currYPos)
Send("^v")


_GDIPlus_Startup()
$currYPos = $yPos-20/(1103/$h)
MouseMove($xPos+80/(968/$w),$currYPos)

WinActivate("X Composer") 
_ClipPutFile($pictoPath & "\" & $process[0] & ".jpg")
$hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[0] & ".jpg")
$imgH = _GDIPlus_ImageGetHeight($hImage)
$currYPos = $currYPos + $h*0.157
MouseMove($xPos+80/(968/$w),$currYPos)
Send("^v")

For $i = 1 to 5 ;Ubound($Data)-1
   WinActivate("X Composer")
   _ClipPutFile($pictoPath & "\" & $process[$i] & ".jpg")
   $hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[$i-2] & ".jpg")
   $imgH = _GDIPlus_ImageGetHeight($hImage)
   $diff = ($imgH-476)*0.4/(1103/$h) + 10/(1103/$h)
   ConsoleWrite($imgH & "-" & $diff & @CRLF)
   $currYPos = $currYPos + $h*0.157 + $diff
   MouseMove($xPos+80/(968/$w),$currYPos)
   Send("^v")
Next

;If check for 4 to decide on the X POS

For $i = 4 to Ubound($Data)-1

Next

_GDIPlus_Shutdown()


     EndFunc

 

Link to comment
Share on other sites

How to go to the desired worksheet in excel. I tried with [_Excel_BookList]. But while selecting button1 (Select) from the dropdown window, it should go to the desired worksheet(Eg., DRILLING, WELDING, GROUNDING etc.,) in excel as shown in figure below. I'm not getting. Give me suggestion friends...! 

 

 

Capture1.PNG

Capture2.PNG

Link to comment
Share on other sites

  • Moderators

Please stick to one thread per topic, and please wait 24 hours before bumping your threads. Spam posting is not going to get your question answered any more quickly.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I think I see what you want to do. I don't know if this code will work perfectly because I don't have your pictures or excel file, but I fixed your switch cases and now it calls the function. 

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Excel.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

WinActivate("X Composer") ; activating software composer(name sake)


HotKeySet("{ESC}",bye) ; hot key to force stop script

Func bye()
   Exit
EndFunc

$pictoPath = "C:\Desktop\Pictures Library"

$hndl = WinGetHandle("X Composer")
$className = _WinAPI_GetClassName($hndl)
$endian = StringRight($className,16)

WinActivate("X Composer")

;Get the Top Position of the WorksSheet
$cPos = ControlGetPos("X Composer","","Afx:0000000140000000:2b:0000000000010005:" & $endian & "1")
$w = $cPos[2]
$h = $w*0.615
ConsoleWrite("Width:" & $w & @CRLF)
ConsoleWrite("Height:" & $h & @CRLF)
$xPos = $cPos[0]
$yPos = $cPos[1] + ($cPos[3]-$h)/2


Local $hGUI = GuiCreate("Pictogram Sequencing", 500, 200)
$cmb1 = GUICtrlCreateCombo("Select a Process", 10, 10, 200, 60)
    GUICtrlSetData($cmb1, "DRILLING|INSTALLATION|DEBURRING|GROUNDING|REVETING|WELDING", "Select a day")
$cmb2 = GUICtrlCreateCombo("Select a Sub Process", 250, 10, 200, 60)

GUISetState(@SW_SHOW)
$Button1 = GUICtrlCreateButton("Select", 60, 100, 65, 17)
    ;Local $idButton = GUICtrlCreateButton( "Select", 10, 200, 195, 20 )
    ;Local $idLabel = GUICtrlCreateLabel( "", 215, 200, 195, 20, $SS_ETCHEDFRAME )
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cmb1
                $cRead = GUICtrlRead($cmb1)
                If $cRead = "DRILLING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|DRILL 1|DRILL 2|DRILL 3", "Select a Sub Process")
                Elseif $cRead = "INSTALLATION" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|PART INSTALLATION|CARPET INSTALLATION|CABINET INSTALLATION|DIVAN INSTALLATION", "Select a Sub Process")
                ElseIf $cRead = "DEBURRING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|DRILL DEBUR|PART DEBUR|WELD DEBUR", "Select a Sub Process")
                ElseIf $cRead =  "GROUNDING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|GROUNDING INSPECTION|PART GROUNDING", "Select a Sub Process")
                ElseIf $cRead =  "REVETING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|PARTS REVETING|SURFACE REVETING|STRUCTURE REVETING", "Select a Sub Process")
                ElseIf $cRead = "WELDING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|MIG WELDING|TIG WELDING|ARC WELDING", "Select a Sub Process")
                EndIf
            Case $Button1
                ExpandGUI()
        EndSwitch
     WEnd

Func ExpandGUI()
    ;Get the Process List from Excel
    $oBook = _Excel_BookAttach("C:\Desktop\Input.xlsx")
    $Count = $oBook.Sheets($cmb1).UsedRange.Rows.Count
    $process = _Excel_RangeRead($oBook,Default,"A2:A" & $count)


    WinActivate("X Composer")
    _ClipPutFile($pictoPath & "\" & $process[0] & ".jpg")
    $hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[0] & ".jpg")
    $imgH = _GDIPlus_ImageGetHeight($hImage)
    ;MsgBox($MB_SYSTEMMODAL, " ", $imgH)
    ;ConsoleWrite($i&$imgH & "-" & $diff & @CRLF)
    $currYPos = $currYPos + $h*0.157
    $currXPos = ($xPos+80/(968/$w))
    MouseMove($xPos+80/(968/$w),$currYPos)
    Send("^v")

    _GDIPlus_Startup()
    $currYPos = $yPos-20/(1103/$h)
    MouseMove($xPos+80/(968/$w),$currYPos)

    WinActivate("X Composer")
    _ClipPutFile($pictoPath & "\" & $process[0] & ".jpg")
    $hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[0] & ".jpg")
    $imgH = _GDIPlus_ImageGetHeight($hImage)
    $currYPos = $currYPos + $h*0.157
    MouseMove($xPos+80/(968/$w),$currYPos)
    Send("^v")

    For $i = 1 to 5 ;Ubound($Data)-1
       WinActivate("X Composer")
       _ClipPutFile($pictoPath & "\" & $process[$i] & ".jpg")
       $hImage = _GDIPlus_ImageLoadFromFile($pictoPath & "\" & $process[$i-2] & ".jpg")
       $imgH = _GDIPlus_ImageGetHeight($hImage)
       $diff = ($imgH-476)*0.4/(1103/$h) + 10/(1103/$h)
       ConsoleWrite($imgH & "-" & $diff & @CRLF)
       $currYPos = $currYPos + $h*0.157 + $diff
       MouseMove($xPos+80/(968/$w),$currYPos)
       Send("^v")
    Next

    ;If check for 4 to decide on the X POS

    For $i = 4 to Ubound($Data)-1

    Next

    _GDIPlus_Shutdown()
EndFunc

 

Link to comment
Share on other sites

I tried to assign the column name (Eg: A, B, C, etc.,). I just approached IF condition for [$dRead] and assign the respective column name in [$p]. But it takes only the final value. 

GUISetState(@SW_SHOW)
$Button1 = GUICtrlCreateButton("Select", 60, 100, 65, 17)
    ;Local $idButton = GUICtrlCreateButton( "Select", 10, 200, 195, 20 )
    ;Local $idLabel = GUICtrlCreateLabel( "", 215, 200, 195, 20, $SS_ETCHEDFRAME )
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cmb1
                $cRead = GUICtrlRead($cmb1)
                $dRead = GUICtrlRead($cmb2);updated
                $p = "A"
                If $cRead = "DRILLING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|DRILL 1|DRILL 2|DRILL 3", "Select a Sub Process")

                    If $dRead = "DRILL 1" Then
                        $p = "A"
                       ElseIf $dRead = "DRILL 2" Then
                        $p = "B"
                       ElseIf $dRead = "DRILL 3" ;Then
                        $p = "C"
                        EndIf

                Elseif $cRead = "INSTALLATION" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|PART INSTALLATION|CARPET INSTALLATION|CABINET INSTALLATION|DIVAN INSTALLATION", "Select a Sub Process")

                    If $dRead = "PART INSTALLATION" Then
                        $p = "A"
                       ElseIf $dRead = "CARPET INSTALLATION" Then
                        $p = "B"
                       ElseIf $dRead = "CABINET INSTALLATION" Then
                        $p = "C"
                       ElseIf $dRead = "DIVAN INSTALLATION" ;Then
                        $p = "D"
                        EndIf

                ElseIf $cRead = "DEBURRING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|DRILL DEBUR|PART DEBUR|WELD DEBUR", "Select a Sub Process")

                    If $dRead = "DRILL DEBUR" Then
                        $p = "A"
                       ElseIf $dRead = "PART DEBUR" Then
                        $p = "B"
                       ElseIf $dRead = "WELD DEBUR" ;Then
                        $p = "C"
                        EndIf

                ElseIf $cRead =  "GROUNDING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|GROUNDING INSPECTION|PART GROUNDING", "Select a Sub Process")

                    If $dRead = "GROUNDING INSPECTION" Then
                        $p = "A"
                       ElseIf $dRead = "PART GROUNDING" ;Then
                        $p = "B"
                        EndIf

                ElseIf $cRead =  "REVETING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|PARTS REVETING|SURFACE REVETING|STRUCTURE REVETING", "Select a Sub Process")

                    If $dRead = "PARTS REVETING" Then
                        $p = "A"
                       ElseIf $dRead = "SURFACE REVETING" Then
                        $p = "B"
                       ElseIf $dRead = "STRUCTURE REVETING" ;Then
                        $p = "C"
                        EndIf


                ElseIf $cRead = "WELDING" Then
                    GUICtrlSetData($cmb2, "")
                    GUICtrlSetData($cmb2, "Select a Sub Process|MIG WELDING|TIG WELDING|ARC WELDING", "Select a Sub Process")

                    If $dRead = "MIG WELDING" Then
                        $p = "A"
                       ElseIf $dRead = "TIG WELDING" Then
                        $p = "B"
                       ElseIf $dRead = "ARC WELDING" ;Then
                        $p = "C"
                        EndIf


                EndIf
            Case $Button1
                ExpandGUI()
        EndSwitch
     WEnd
Func ExpandGUI()

   $oBook = _Excel_BookAttach(@DesktopDir &"\Data\Input.xlsx")
   $oBook.Sheets($cRead).Select
   $Count = $oBook.Sheets($cRead).UsedRange.Rows.Count
   $process = _Excel_RangeRead($oBook,Default,$p & "2:" & $p & $count)
   $pictoPath =  @DesktopDir & "\Data\Pictos Library\" & $cRead

 

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...