Skip to content

Commit

Permalink
v2.2.3 功能新增 (#6)
Browse files Browse the repository at this point in the history
**新增:**

* ESC键清空power-input输入框内容

* 获取 CATIA V5 R2020 算法适配

* ESC 清除POWER-INPUT功能提供启用选项

* 结构树自动排序功能

* 排序算法优化,更快更准确, 输入错误别名的判断机制BUG修复

**优化:**

* 启动windows计算器功能优化,CATIA别名算法优化

* space按键的算法优化,与其他功能的算法函数复用

* Change Title Match Mode to option 2

* 优化配置文件缺失时的提示信息

* IME库文件整合到windows.ahk

* README 更新
  • Loading branch information
zedeeee authored Jan 28, 2024
1 parent d8d51d2 commit c892772
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 205 deletions.
26 changes: 25 additions & 1 deletion Lib/AHK_LOG.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,29 @@ AHK_LOGI(Message)
{
if !DEBUG_I
return
k_ToolTip(Message, 1000)
k_ToolTip(Message, 3000)
}

; 开发功能启用提示
; 1. 检查标记值
; 2. 根据情况弹出提示框, 返回按键状态
; 3. 修改值
; 4. 重载
init_dev_func_prompt(ini_path, key, describe) {
dev_func_section := "DevFunc"

if IniRead(ini_path, dev_func_section, key) == -1
{
user_chooise := MsgBox("是否需要启用开发功能 : `n" . describe, "UCLC 开发功能启用", 0x233)
switch user_chooise
{
case "Yes": IniWrite(1, ini_path, dev_func_section, key)
case "No": IniWrite(0, ini_path, dev_func_section, key)
default: MsgBox("未启用 " . describe . "`n下次启动脚本会再次询问", "UCLC 开发功能启用", 0x30)
}
}

k_ToolTip(ESC_CLEAN_FUNC_FLAG, 1000)

return IniRead(ini_path, dev_func_section, key)
}
49 changes: 36 additions & 13 deletions Lib/CATAlias.ahk
Original file line number Diff line number Diff line change
@@ -1,38 +1,61 @@
#Requires AutoHotKey v2.0
#include stdio.ahk
#Include AHK_LOG.ahk
#Include CAT_Automatic.ahk

/**
* 获取用户别名配置文件中指定的key值
*
* @param alias_list_ini_path(string) 配置文件的路径
* @param section(string) ini 文件的section, 一般是工作台名称
* @param key(string) 键值, 一般是输入的别名
*
* @example:
* - GR = CATPstReorderHdr ; 图形树重新排序
* @return arr[1]
* - arr[1] == "CATPstReorderHdr"
*
* @example:
* - AGR = CATPstReorderHdr &cat_auto_graph_tree_reorder ; 图形树自动排序
* @return arr[2]
* - arr[1] == "CATPstReorderHdr"
* - arr[2] == "cat_auto_graph_tree_reorder"
*/
read_user_alias(alias_list_ini_path, section, key) {
command_id_and_cb_array := Array()

; 读取CATAlias.ini配置文件中的别名, 并返回别名字符串
; 返回的字符串会自动排除 “;” 以后的内容
readAlias(k_Section, k_Key) {
try {
; 返回 CATAlias.ini 内 Key 的对应值
AHK_LOGI("调用 " k_Section)
return StrSplit(IniRead(alias_ini_path, k_Section, k_Key), ";")[1]
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
}
catch as e {
if e
{
try {
AHK_LOGI("调用 通用")
return StrSplit(IniRead(alias_ini_path, "通用", k_Key), ";")[1]
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
}
catch as e {
k_ToolTip("没有找到与" k_Key "对应的命令", 1000)
return ""
k_ToolTip(Format("没有找到与 {1} 对应的命令",key), 1000)
return command_id_and_cb_array
; Exit
}
}
}
}

; 查找 ini 文件,匹配 [Hotkey] 的对应快捷键
SendAliasCommand(ThisHotkey) {
register_command(ThisHotkey) {
try {
ControlSetText("", FocuseHwnd)
SendInput("c:" readAlias("HotKey", ThisHotkey) "{Enter}")
SendInput(" ")
ControlSetText("", ControlGetFocus("A"))
SendInput("c:" read_user_alias(alias_ini_path, "HotKey", ThisHotkey)[1] "{Enter}")
}
catch as e {
k_ToolTip("热键注册失败,请检查" alias_ini_path "目录是否正确", 3000)
}
}
}
139 changes: 139 additions & 0 deletions Lib/CAT_Automatic.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#Requires AutoHotkey v2.0

#Include CATAlias.ahk
#Include AHK_LOG.ahk


/**
* 根据输入的用户别名, 执行配置文件中的 COMMAND_ID 以及 函数调用
* @param alias_strings 用户别名字符串, 不区分大小写
* @param power_input_hwnd 超级输入框的 hwnd 值
*
*/
cat_alias_exexcution(alias_string, power_input_hwnd)
{
current_workbench := CAT_CURRENT_WORKBENCH()

command_id_and_cb_array := read_user_alias(alias_ini_path, current_workbench, StrUpper(alias_string))

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

; hwnd_current := ControlGetHwnd("A")
ControlSetText("c:" . command_id_and_cb_array[1], power_input_hwnd)
; ControlSetText("c:" . "ViewAlignment", power_input_hwnd)
SendInput "{Enter}"

if command_id_and_cb_array.Length == 2
{
%command_id_and_cb_array[2]%()
}

}

; 获取装配设计下的 "图形树重新排序" 窗口, 自动执行排序操作
cat_auto_graph_tree_reorder()
{
GroupAdd "ReorderTree", "Graph tree reordering"
GroupAdd "ReorderTree", "图形树重新排序"
raw_lists_string := ""

dialogbox_hwnd := WinWait("ahk_group ReorderTree", , 5)
if dialogbox_hwnd == 0
{
Exit
}

Listbox_items := ControlGetItems("ListBox1", dialogbox_hwnd)

for item in Listbox_items {
raw_lists_string .= item ","
}

sorted_lists_string := Sort(raw_lists_string, "D,")
refrence_lists_array := StrSplit(SubStr(sorted_lists_string, 1, StrLen(sorted_lists_string) - 1), ',')

listbox_classnn := "ListBox1"
free_move_button := ControlGetHwnd("自由移动", dialogbox_hwnd)

listbox_items := ControlGetItems(listbox_classnn, dialogbox_hwnd)

; 检查当前的排序状态
loop listbox_items.Length
{
if (listbox_items[A_Index] == refrence_lists_array[A_Index]) {
if (A_Index == listbox_items.Length)
{
k_ToolTip("已排序完成, 不用继续排序", 3000)
Sleep 1000
PostMessage(0x10, 0, , , dialogbox_hwnd)
Exit
}
continue
}
else {
break
}
}

try {
; 执行排序
refrence_item_index := 0

for item in refrence_lists_array
{
refrence_item_index += 1
ControlChooseString(refrence_lists_array[A_Index], listbox_classnn, dialogbox_hwnd)
if (ControlGetIndex(listbox_classnn, dialogbox_hwnd) == A_Index)
{
continue
}
SendMessage(0xF5, 0, 0, free_move_button, dialogbox_hwnd)
ControlChooseIndex(A_Index, listbox_classnn, dialogbox_hwnd)

while ControlChooseString(item, listbox_classnn, dialogbox_hwnd) != refrence_item_index
{
Sleep 1
}
}
}
catch Error as e
{
AHK_LOGI(Format("函数: {1} 执行失败`n错误信息: {2} on Line {3} `n 文件: {4}", e.What, e.Message, e.Line, e.File))
Exit
}

k_ToolTip("结构树排序完成", 2000)
}

; 检测当前 CATIA 工作台,并返回字符串
CAT_CURRENT_WORKBENCH()
{
WinExist("A")

workbench_name := "NULL"
visible_text := WinGetTextFast_A(false)

; 获取工作台列表
if WORKBENCH_LIST_A.Length = 0
{
INI_GET_ALL_VALUE_A(config_ini_path, "workbench")
}

for value1 in visible_text {
for value2 in WORKBENCH_LIST_A {
; FileAppend "WORKBENCH_LIST_A: " value1 " " "visible_text: " value2 "`n", ".\log.txt"
if (value1 != value2)
{
continue
}
AHK_LOGI("value1: " value1 "`n" "value2: " value2 "`n" "A_index: " A_Index)
workbench_name := value1
return workbench_name
}
}

}
28 changes: 0 additions & 28 deletions Lib/IME.ahk

This file was deleted.

20 changes: 12 additions & 8 deletions Lib/string.ahk
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#Requires AutoHotkey v2.0

; 获取 ini 文件内指定 section 内所有 value, 将 value 以数组形式返回
; - string: file_path
; - string: section_name
/**
* **获取 ini 文件内指定 section 内所有 value, 将 value 以数组形式返回**
* @param file_path(string) 目标 ini 文件的路径
* @param section_name(string) 指定 section 的名称
* @return Array
*/
INI_GET_ALL_VALUE_A(file_path, section_name)
{
values := Array()
Expand All @@ -23,15 +26,16 @@ INI_GET_ALL_VALUE_A(file_path, section_name)
}


; 通过config.ini文件读取分项配置文件路径
INI_GET_USERCONFIG_PATH(k_key)
; 获取 config.ini 文件 [UserConf] 下的对应配置文件路径
;
GET_USER_CONFIG_INI_PATH(key)
{
try {
sub_config_path := A_ScriptDir "/user-config/" IniRead(config_ini_path, "UserConf", k_key)
return sub_config_path
path := A_ScriptDir "\user-config\" IniRead(".\config.ini", "UserConf", key)
return path
}
catch as e {
MsgBox("获取" k_key "配置文件失败,请检查 config.ini 和" k_key "配置文件路径是否正确")
MsgBox("获取 [" key "] 配置文件失败,请检查 config.ini 和 [" key "] 配置文件路径是否正确")
}

}
27 changes: 25 additions & 2 deletions Lib/window.ahk → Lib/windows.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,30 @@ WinGetTextFast_A(detect_hidden) {

name := StrGet(buf)
; names.Push(name)
names.InsertAt(1,name)
names.InsertAt(1, name)
}
return names
}
}


; 通过调用WinAPI切换输入法
; https://github.com/mudssky/myAHKScripts
;
;
IMEmap := map(
"zh", 0x8040804,
"en", 0x4090409
)

getCurrentIMEID() {
winID := WinGetID("A")
ThreadID := DllCall("GetWindowThreadProcessId", "UInt", WinID, "UInt", 0)
InputLocaleID := DllCall("GetKeyboardLayout", "Uint", ThreadID, "Uint")
return InputLocaleID
}

switchIMEbyID(IMEID) {
PostMessage(0x0050, 0, IMEID, , "A")
}


Loading

0 comments on commit c892772

Please sign in to comment.