Skip to content

Commit

Permalink
Feature/v2.4.2 dev/alias function (#19)
Browse files Browse the repository at this point in the history
* single instance force

* add support list for autoime

* 别名函数调用算法升级

* ignore file update

* 装配:快速操作零部件以指定方向运动

* update README
  • Loading branch information
zedeeee authored Jul 12, 2024
1 parent 72a4cc2 commit 9c03633
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test/
/test
/.vscode
40 changes: 29 additions & 11 deletions Lib/CATAlias.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
#Include CAT_Automatic.ahk

/**
* 获取用户别名配置文件中指定的key值
* 获取用户别名配置文件中指定的key值,结果以数组形式返回
*
* @param alias_list_ini_path(string) 配置文件的路径
* @param section(string) ini 文件的section, 一般是工作台名称
* @param key(string) 键值, 一般是输入的别名
* @return Array 返回命令,[回调函数],[参数]
*
* @example:
* - GR = CATPstReorderHdr ; 图形树重新排序
* @return arr[1]
* @return arr[]
* - arr[1] == "CATPstReorderHdr"
*
* @example:
* - AGR = CATPstReorderHdr &cat_auto_graph_tree_reorder ; 图形树自动排序
* @return arr[2]
* @return arr[]
* - arr[1] == "CATPstReorderHdr"
* - arr[2] == "cat_auto_graph_tree_reorder"
*/
Expand All @@ -26,26 +27,43 @@ read_user_alias(alias_list_ini_path, section, key) {

try {
AHK_LOGI("调用 " section)
command_id_and_cb_str := StrSplit(StrReplace(IniRead(alias_list_ini_path, section, key), A_Space, ''), ";")[1]
command_id_and_cb_array := StrSplit(command_id_and_cb_str, "&")
return command_id_and_cb_array
config_str := IniRead(alias_list_ini_path, section, key)
command_id_and_cb_array := process_config(config_str)
}
catch as e {
if e
{
try {
AHK_LOGI("调用 通用")
command_id_and_cb_str := StrSplit(StrReplace(IniRead(alias_list_ini_path, "通用", key), A_Space, ''), ";")[1]
command_id_and_cb_array := StrSplit(command_id_and_cb_str, "&")
return command_id_and_cb_array
config_str := IniRead(alias_list_ini_path, "通用", key)
command_id_and_cb_array := process_config(config_str)
}
catch as e {
k_ToolTip(Format("没有找到与 {1} 对应的命令", key), 1000)
return command_id_and_cb_array
; Exit
return 0
}
}
}

return command_id_and_cb_array
}

process_config(config) {
result := []

; 去除注释部分
config := StrReplace(Trim(StrSplit(config, ";")[1]), "&", ",")
params := StrSplit(config, ",")

result.Push(Trim(params[1], " `t"))

; 去除后面所有项的空格
Loop params.length - 1
{
result.Push(Trim(params[A_Index + 1]))
}

return result
}

; 查找 CAT_Hotkey.ini 文件,注册对应快捷键/* */
Expand Down
43 changes: 30 additions & 13 deletions Lib/CAT_Automatic.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
*/
cat_command_execution(input_string, command_ini, power_input_hwnd)
{
; 获取当前工作台
current_workbench := match_current_workbench(workbench_list)

; 获取对应的Command-id 和 回调函数
command_id_and_cb_array := read_user_alias(command_ini, current_workbench, StrUpper(input_string))

if command_id_and_cb_array.Length == 0
if !command_id_and_cb_array
{
k_ToolTip(Format("没有找到与 '{1}' 对应的命令", input_string), 1000)
return
}

; command-id 输出到power-input
ControlSetText("c:" . command_id_and_cb_array[1], power_input_hwnd)

; timeout handling
Expand All @@ -33,9 +36,15 @@ cat_command_execution(input_string, command_ini, power_input_hwnd)
k_ToolTip("错误:" . e.What e.Message, 2000)
}

if command_id_and_cb_array.Length == 2
{
%command_id_and_cb_array[2]%()
; 执行回调函数,如有
if command_id_and_cb_array.Length >= 2 {
params := []
loop command_id_and_cb_array.Length - 2
{
params.Push(command_id_and_cb_array[A_Index + 2])
}

%command_id_and_cb_array[2]%(params*)
}

}
Expand Down Expand Up @@ -118,14 +127,26 @@ cat_auto_graph_tree_reorder()
k_ToolTip("结构树排序完成", 2000)
}

quick_manipulation(diraction) {
GroupAdd "Manipulation", "操作参数"

manipulation_hwnd := WinWait("ahk_group Manipulation", , 5)
if manipulation_hwnd == 0
Exit

diract_button := ControlGetHwnd(diraction, manipulation_hwnd)

SendMessage(0xF5, 0, 0, diract_button, manipulation_hwnd)
}


/**
* 通过比对工作台控件和工作台列表,返回当前生效工作台
*
* @param workbench_map 工作台列表
* @returns {string} 工作台名称
*/
match_current_workbench(workbench_map)
{
match_current_workbench(workbench_map) {
workbench_control_hwnd := ControlGetHwnd("WebBrowser", "A")
; workbench_buttons :=

Expand Down Expand Up @@ -153,8 +174,7 @@ catia_window_classnn_map := Map(
* @param obj 自定义封装
* @returns {bool}
*/
is_catia_exe_and_title(obj)
{
is_catia_exe_and_title(obj) {
if (StrLower(obj.exe) == "cnext.exe" and StrUpper(SubStr(obj.title, 1, 8)) == "CATIA V5")
{
return true
Expand All @@ -169,9 +189,7 @@ is_catia_exe_and_title(obj)
* @param obj 自定义封装
* @returns {bool}
*/
is_included_catia_class(obj)
{

is_included_catia_class(obj) {
test_class := obj.class

for , value in catia_window_classnn_map
Expand Down Expand Up @@ -239,8 +257,7 @@ get_power_input_edit_hwnd() {
* @param ini_path ini文件路径
* @param dict 指定字典对象
*/
read_all_section_from_ini(ini_path, dict)
{
read_all_section_from_ini(ini_path, dict) {
section_array := StrSplit(IniRead(ini_path), "`n")

for section in section_array
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@

## 附加功能
1. 产品结构树自动排序
2. 自动切换输入法为英文
1. `Shift + Tab`在多个 CATIA 窗口循环切换
2. 快速操作零部件以指定方向 移动/平移(响应速度优于罗盘操作)
3. 自动切换输入法为英文
4. `Shift + Tab`在多个 CATIA 窗口循环切换
5. `ESC` 清除 Power-input 输入框的内容(测试功能)
1. 双击 `右Ctrl` 键呼出 Everything(Everything需要设置快捷键`win+]`
6. `Win+鼠标滚轮`:切换虚拟桌面(Windows 11)
7. `RAlt+鼠标滚轮`:调节音量,`RAlt+鼠标中键`:静音切换
6. 双击 `右Ctrl` 键呼出 Everything(Everything需要设置快捷键`win+]`
7. `Win+鼠标滚轮`:切换虚拟桌面(Windows 11)
8. `RAlt+鼠标滚轮`:调节音量,`RAlt+鼠标中键`:静音切换

## 使用方法

Expand Down
1 change: 1 addition & 0 deletions UCLC.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Requires AutoHotKey v2.0
#SingleInstance Force
SetTitleMatchMode 2

#Include ./Lib/CATAlias.ahk
Expand Down
Binary file modified config.ini
Binary file not shown.

0 comments on commit 9c03633

Please sign in to comment.