Thursday, 30 May 2013

An AHK script to select particular tables for reverse engineering in PowerDesigner

The following script helps to select tables (optionally any objects) in the 'Database Reverse Engineering' window of PowerDesigner 15.3 that are stored in txt file.
#include Acc.ahk
#SingleInstance force
SelectTables(){
local v_hwnd
local v_ahkId
local v_accObject
local v_file
local v_tableName
local v_powerDisTableName
static SELFLAG_NONE := 0
static SELFLAG_TAKEFOCUS := 0x1
static SELFLAG_TAKESELECTION := 0x2
static SELFLAG_EXTENDSELECTION := 0x4
static SELFLAG_ADDSELECTION := 0x8
static SELFLAG_REMOVESELECTION := 0x10
v_ahkId := WinExist( "A" )
;ControlGet, v_hwnd, HWND, , SysListView322, ahk_id %v_ahkId%
MouseGetPos, , , , v_hwnd, 2
v_accObject := Acc_ObjectFromWindow( v_hwnd )
if ( "IAccessible" != ComObjType( v_accObject, "Name" ) ){
return
}
local v_fileName
v_fileName := "views_to_reverse.txt"
v_file := FileOpen( ".\" . v_fileName, "r-d" ) ;open for reading, share all access except for delete
if ( !IsObject( v_file ) ){
MsgBox Can't open %v_fileName% for reading.
return
}
local v_tableDict
v_tableDict := Object()
For Each, v_child in Acc_Children( v_accObject )
{
if ( IsObject( v_child ) ){
continue
}
v_powerDisTableName := Trim( v_accObject.accName( v_child ), " `t`r`n" )
v_tableDict[ v_powerDisTableName ] := v_child
}
While, 0 == v_file.AtEOF
{
v_tableName := Trim( v_file.ReadLine(), " `t`r`n" )
if ( v_tableDict.HasKey( v_tableName ) ){
v_accObject.accSelect( SELFLAG_TAKEFOCUS + SELFLAG_ADDSELECTION, v_tableDict[ v_tableName ] )
}
}
v_file.Close()
return
}
#IfWinActive ahk_class #32770
F5::SelectTables()
view raw gistfile1.ahk hosted with ❤ by GitHub
First one should unmark all objects in the list view, then run the script, hit F5, and after the selection process ends (that can be noticed by stopped blinking of the 'Database Reverse Engineering' window) hit SPACE to mark only selected objects.
Here's the resulting list:

Script uses Acc Library to get the names of items in the ListView and to select them. It should be run under one of the latest releases of AutoHotkey_L.
In my particular case file containing list of objects is called 'tables_to_reverse.txt' (see the script).

No comments:

Post a Comment