Sign in to follow this  
Followers 0
det54

help with porting some code

3 posts in this topic

Hi all,

I am working on automating SolidWorks Flow Simulation, and had successfully written a script using WinTask a while back that I would like to convert to run in AutoIt. Most of the changes I have made to the script so far involve renaming variables or functions. There are some instances where I think AutoIt should be able to access some of the lists or tables in SolidWorks, but I can't figure out how to make this happen. I have tried using the included Window Info tool and also Spy++, but some of the menus only open when a TreeView item is right-clicked, and they go away as soon as I change focus to the spy tools, so I have not been able to find the proper ID for the controls. For the time being, I am using MouseClick to handle everything, but I would much rather access list items by name. Below is a sample of my WinTask code - it contains window names/handles that I think AutoIt should be able to utilize. I think I want to use ControlClick to access some of the controls, but I could not get it to work for some of these items. Can anyone help me with converting the UseWindow, ChooseItem, and Click(Button, "Name") commands? Any help is much appreciated!

- Dan

PS - I will be searching for some Excel workbook access functions (read cells, write cells, etc) - if anyone has some helpful links please share :)

'------------------------------------------------------------------------------------------------------

'Gets 9 individual Surface Parameters concentrations

'This assumes that the Results tree has been expanded, otherwise it will not find Surface Parameters Ends

Sub GetSurfParams()

y = 1

While y < 10 'Repeat 9 times

UseWindow("SLDWORKS.EXE|AfxOleControl90u|"+file$+" *|2",1)

ChooseItem(TreeView, "1", "Surface Parameters "+Str$(y), single, right )

'Pause 10 ticks

'UseWindow("SLDWORKS.EXE|SysTreeView32|"+file$+" *|8",1)

UseWindow("SLDWORKS.EXE|SysTreeView32|",1)

ChooseMenu(Context,"&Edit Definition...")

UseWindow("SLDWORKS.EXE|#32770|"+file$+" *|3",1)

Click(Button,"Show ")

UseWindow("SLDWORKS.EXE|NIKFlexGrid8L|"+file$+" *|3",1) 'Make sure mouse is not obscuring Copy Table bitmap

ClickMouse(Left,Down,264,69)

MoveMouse(265,69)

MoveMouse(265,68)

ClickMouse(Left,Up,265,68)

Pause until

Bitmap("C:\Program Files (x86)\WinTask\Scripts\CopyTable.bmp")

InWindow("SLDWORKS.EXE|ToolbarWindow32|"+file$+" *|7",1)

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")

End

EndPause

UseWindow("SLDWORKS.EXE|AfxFrameOrView90u|"+file$+" *|35",1)

ChooseItem(ToolBar, "|1", "|45", single, left ) 'Copy table of values to clipboard

Pause 10 ticks

a$=GetClipboard$()

'MsgBox(a$) 'for debugging

UseWindow("SLDWORKS.EXE|Button|"+file$+" *|18",1)

SendKeys("<Enter>")

excel_file$="Testing1.xlsm" 'Working file for clipboard functions

macro$="Macro1"

workbook$="Sheet1"

ExecExcelMacro(excel_file$,macro$,30)

'Pause 10 clicks

ReadExcel(excel_file$,"D2",b$())

'MsgBox(b$(0)) 'for debugging

Surf_Param$(y)=b$(0)

y = y + 1

Wend

EndSub 'End of GetSurfParams

Share this post


Link to post
Share on other sites



Hi, detroit54, welcome to the forum. Based on your code (please put all code between tags in the future for readability

[/CODE]) this looks like something AutoIt can surely accomplish. I would suggest the following:

[code]

Sub GetSurfParams() <--For Subs look at Func in the help file.

y = 1
While y < 10 'Repeat 9 times <-- Look at For in the help file (ex: For $y = 1 to 10)

UseWindow("SLDWORKS.EXE|AfxOleControl90u|"+file$+" *|2",1) <--Look at WinActivate

ChooseItem(TreeView, "1", "Surface Parameters "+Str$(y), single, right ) <--Look into the Control commands.

'Pause 10 ticks <--Look at Sleep in the help file

ClickMouse(Left,Down,264,69)
MoveMouse(265,69)            <--Look at Mouse Management in the help file, or use ControlClick for better performance
MoveMouse(265,68)
ClickMouse(Left,Up,265,68)

Pause until
Bitmap("C:\Program Files (x86)\WinTask\Scripts\CopyTable.bmp") <--You can use a While loop or look up WinWaitActive
InWindow("SLDWORKS.EXE|ToolbarWindow32|"+file$+" *|7",1)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !") <--Look at parameters for Msgbox
End
EndPause

a$=GetClipboard$() <--look at ClipPut() and ClipGet(), or the _Clipboard functions in the help file.

excel_file$="Testing1.xlsm" 'Working file for clipboard functions
macro$="Macro1"              <---check out the _Excel functions in the help file
workbook$="Sheet1"
ExecExcelMacro(excel_file$,macro$,30)

Try writing some code after you have looked at the help file, and don't be shy about posting what you come up with (even if it does't work as you would like it to). We'll be glad to assist :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Sorry, I wasn't trying to be lazy - I should have been more specific. I had already figured out WinActivate, MsgBox, and ClipGet functions from the help file. My questions follow the particular code I was having trouble with below:

ChooseItem(TreeView, "1", "Surface Parameters "+Str$(y), single, right ) <--Look into the Control commands.

I looked at the Control commands (specifically ControlClick), used the Spy tool to try to identify the tree item identifiers, and even tried the macro recorder to produce the correct code for me, but I could not figure out what exactly to put in for "title", "text", or controlID to make this work. I was hoping that by including the above snippet from WinTask that someone might be able to tell me how to use the "TreeView", "1", and "Surface Parameters 1" in the ControlClick command. The macro editor just skips this part of the process and gives a message that TreeView32 objects are not supported.

Note that I have nine individual "Surface Parameters X" items in the feature tree that I want to access and change. I appended the loop iteration number to this string in the old code. What has to happen is that I need to right-click each Surface Parameters item, then select Edit (or send "e"). I then click "Copy Entire Table" to put the values into the clipboard, then I click the "OK" button (or just send "Enter") to close the dialog and move on to the next Surface Parameters item.

Below is some other code from WinTask and what I tried in AutoIt with some success. I'd appreciate any help or tips for improvement.

[i]WinTask Code:[/i]

UseWindow("SLDWORKS.EXE|SysTreeView32|",1)
ChooseMenu(Context,"&Edit Definition...")

[i]AutoIt Code:[/i]

ControlClick("SolidWorks Premium 2012 x64 Edition - [PS High 9env SW2012 - 120907.SLDPRT *]","swCaption","SysTreeView326","Right") ;Surface Parameters 1
Send("e")

[i]WinTask Code:[/i]

UseWindow("SLDWORKS.EXE|#32770|"+file$+" *|3",1)
Click(Button,"Show ")

[i]AutoIt Code:[/i]

ControlClick("SolidWorks Premium 2012 x64 Edition - [PS High 9env SW2012 - 120907.SLDPRT *]","swCaption","Button21") [i];Show[/i]

UseWindow("SLDWORKS.EXE|AfxFrameOrView90u|"+file$+" *|35",1)
ChooseItem(ToolBar, "|1", "|45", single, left ) 'Copy table of values to clipboard

I couldn't figure this one out at all, the macro recorder gives the message that "AutoIt supports no ToolbarWindow32" (AutoIt Macro Generator V 0.21 beta - it is old).

AutoIt Code:

ControlClick("SolidWorks Premium 2012 x64 Edition - [PS High 9env SW2012 - 120907.SLDPRT *]","swCaption","Button28") ;OK button

This works for the OK button, but I could also just send the "Enter" key. Do I need to include the entire window title here, or will "SolidWorks" suffice?

Thanks!

- Dan

Share this post


Link to post
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
Sign in to follow this  
Followers 0