• 金昌JCH文件批量转BMP/JPG图片脚本


    目录

    制作初衷

    脚本原理

    效果展示

    python库安装

    目录结构

    脚本源码

    注意事项

    成品下载

    其他资料


    转载请注明出处:CSDN-小锋学长生活大爆炸

    制作初衷

    • 网上找了好久都没有找到免费好用的工具,唯一一个工具还要收费,下载看了下,好像也是通过金昌EX9000实现的转换,所以自己做了个。
    • 虽然能通过金昌EX9000软件来手动转换,但当文件达到几十上百个时,手动就也太慢了。
    • 金昌EX9000是免费的,但确实也是年代很久了。
    • 听说也有其他类似“秋风分色软件”等等,但找不到下载方式,而且好像也是收费的。
    • 找了下没有解释JCH格式的教程,所以最后妥协,通过脚本控制金昌EX9000来实现一个一个的自动化转换。

    脚本原理

    其实就是通过模拟手动点点点,控制金昌EX9000软件实现转换,所以效率较低,但至少也比手工块。

    效果展示

    python库安装

    pip install autoit pyautogui

    目录结构

    注意要把它俩放在一起喔~

     

    脚本源码

    开源Github:GitHub - 1061700625/JCHConvertor: 金昌JCH文件批量转BMP/JPG图片脚本

    1. import os.path
    2. import sys
    3. import time
    4. from glob import glob
    5. import autoit
    6. import pyautogui
    7. def open_app():
    8. while True:
    9. if not autoit.win_exists("金昌Ex9000 ---- 印花智能设计分色系统"):
    10. print('>> 未运行,先启动软件')
    11. autoit.run('Ex9000.exe')
    12. time.sleep(2)
    13. if autoit.win_exists("Dialog", text="下次起动显示"):
    14. autoit.control_click("Dialog", "[Class:Button; instance:2]")
    15. autoit.send('{ENTER}')
    16. time.sleep(2)
    17. if autoit.win_exists("Dialog", text="使用了其他版本"):
    18. autoit.send('{ENTER}')
    19. autoit.win_wait_active("Dialog", 3, text="智能修复后")
    20. autoit.send('{ENTER}')
    21. autoit.win_wait_active("Dialog", 3, text="系统修复完毕")
    22. autoit.send('{ENTER}')
    23. time.sleep(2)
    24. continue
    25. if autoit.win_exists("疑问", text="越权访问"):
    26. autoit.send('!N')
    27. time.sleep(1)
    28. autoit.process_close('Ex9000.exe')
    29. time.sleep(2)
    30. continue
    31. # pyautogui.alert(title='软件启动错误', text='请重新运行本软件')
    32. # sys.exit(0)
    33. autoit.win_set_state("金昌Ex9000 ---- 印花智能设计分色系统", autoit.properties.SW_SHOW)
    34. autoit.win_set_state("金昌Ex9000 ---- 印花智能设计分色系统", autoit.properties.SW_MAXIMIZE)
    35. # autoit.win_move("金昌Ex9000 ---- 印花智能设计分色系统", 0, 0, 800, 600)
    36. autoit.control_focus("金昌Ex9000 ---- 印花智能设计分色系统", "[Class:MDIClient; instance:1]")
    37. autoit.win_activate("金昌Ex9000 ---- 印花智能设计分色系统")
    38. autoit.win_wait_active("金昌Ex9000 ---- 印花智能设计分色系统", 3)
    39. print('>> 软件启动成功!')
    40. break
    41. def open_jch(file_path):
    42. print('>> 打开文件:' + file_path)
    43. autoit.send("^w")
    44. time.sleep(0.5)
    45. autoit.send("^o")
    46. autoit.win_wait_active("打开文件", 5)
    47. autoit.control_send("打开文件", "[Class:Edit; instance:1]", file_path)
    48. autoit.send("{ENTER}")
    49. autoit.send("{ENTER}")
    50. autoit.win_wait_active("金昌Ex9000 ---- 印花智能设计分色系统", 5, text="标准工具条")
    51. print('>> 文件打开成功!')
    52. def merge_jch():
    53. print('>> 合并图层')
    54. if autoit.win_exists("", text="混合模式"):
    55. text_mode = "混合模式"
    56. elif autoit.win_exists("", text="覆盖模式"):
    57. text_mode = "覆盖模式"
    58. else:
    59. text_mode = "图层"
    60. print('>> 调出图层')
    61. autoit.send("{F3}")
    62. print('>> 激活图层 => ' + text_mode)
    63. autoit.win_activate("", text=text_mode)
    64. time.sleep(1)
    65. autoit.control_click("", control="[Class:Button; instance:2]", text=text_mode)
    66. autoit.send("{down 6}")
    67. autoit.send("{ENTER}")
    68. print('>> 图层合并成功!')
    69. def save_jch(file_path):
    70. print('>> 保存文件:' + file_path)
    71. autoit.send("^+s")
    72. autoit.win_wait_active("另存为", 5)
    73. autoit.control_send("另存为", "[Class:Edit; instance:1]", file_path)
    74. autoit.send("{ENTER}")
    75. autoit.send("{ENTER}")
    76. print('>> 文件保存成功!')
    77. def close_app():
    78. autoit.win_close("金昌Ex9000 ---- 印花智能设计分色系统")
    79. print('>> 软件关闭成功!')
    80. if __name__ == '__main__':
    81. input_dir_path = pyautogui.prompt(text="请输入JCH文件所在路径").strip()
    82. if input_dir_path is None:
    83. pyautogui.alert('欢迎下次使用!')
    84. sys.exit(0)
    85. print('>> input_dir_path: ' + input_dir_path)
    86. if not os.path.isdir(input_dir_path):
    87. pyautogui.alert('不是文件夹或路径不存在: ' + input_dir_path)
    88. sys.exit(0)
    89. output_dir_path = pyautogui.prompt(text="请确认(或修改)输出图片所在路径", default=os.path.join(input_dir_path, 'images')).strip()
    90. print('>> output_dir_path: ' + output_dir_path)
    91. if not os.path.exists(output_dir_path):
    92. os.makedirs(output_dir_path)
    93. image_format = pyautogui.prompt(text="请确认(或修改)输出图片的格式\n支持bmp、jpg", default='bmp').strip()
    94. if image_format is None:
    95. pyautogui.alert('欢迎下次使用!')
    96. sys.exit(0)
    97. print('>> image_format: ' + image_format)
    98. jchs = glob(os.path.join(input_dir_path, '*.jch'))
    99. print(f">> 共搜索到{len(jchs)}个JCH文件")
    100. # print(jchs)
    101. confirm = pyautogui.confirm(title="即将开始转换", text=f"共搜索到{len(jchs)}个JCH文件\n运行过程中请不要动鼠标和键盘!!!", buttons=['OK', 'Cancel'])
    102. if confirm == 'Cancel':
    103. pyautogui.alert('欢迎下次使用!')
    104. sys.exit(0)
    105. try:
    106. open_app()
    107. for jch_file in jchs:
    108. # jch_file = jchs[0] # only for test
    109. open_jch(jch_file)
    110. time.sleep(2)
    111. merge_jch()
    112. time.sleep(2)
    113. jch_name = jch_file.split(os.sep)[-1]
    114. output_file_path = os.path.join(output_dir_path, jch_name.split('.')[0] + '.' + image_format)
    115. save_jch(output_file_path)
    116. # wait for complete
    117. time.sleep(2)
    118. close_app()
    119. pyautogui.confirm(title='转换完成', text='欢迎下次使用!')
    120. except Exception as e:
    121. pyautogui.alert(title='脚本异常终止', text=str(e))
    122. input('>> 输入任意键退出...')

    注意事项

    1、文件夹下的金昌EX9000软件一定要设置Win7兼容模式,不然启动总报错!!

    2、点击“即将开始转换”对话框后,一定不要操作键盘和鼠标,否则脚本会识别错误控件,导致异常退出!!!若脚本长时间没反应,或者弹出“转换完成”的对话框后,再操作鼠标喔!!!(因为脚本是模拟手工操作,所以人为点击会影响脚本正常运行)

    3、注意JCH和保存图片的路径都万万不能包含中文!!!

    成品下载

    打包出来的exe体积非常大,而且存在autoit.dll问题,可能跟我的Python环境有关,有条件的建议自己打包,或者直接运行py脚本。

    金昌JCH文件批量转BMP/JPG图片脚本-快应用文档类资源-CSDN下载

    其他资料

  • 相关阅读:
    JDK1.5 新特性【泛型】
    Intel汇编-JMP无条件调转
    arp 隔离
    RabbitMQ
    虚拟电厂可视化大屏,深挖痛点精准减碳
    【力扣周赛】第 357 场周赛(⭐反悔贪心)
    Manifest merger failed
    Three.js 打造缤纷夏日3D梦中情岛 🌊
    移动协同办公系统,让工作更轻松,生活更美好!
    openssl3.2 - exp - calc PE file checksum and SHA3-512
  • 原文地址:https://blog.csdn.net/sxf1061700625/article/details/126431492