Created
March 22, 2012 08:19
-
-
Save moluapple/2157102 to your computer and use it in GitHub Desktop.
[Indesign] Word DLL 简繁转换 python 脚本打包测试
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
抽出WORD中繁简转换的DLL,直接调用. | |
需要的文件: MSTR2TSC.DLL MSTR2TSC.LEX MSO.DLL | |
原文见:http://hyry.dip.jp:8000/code.py?id=105 | |
''' | |
import ctypes | |
import win32com.client | |
def translate(s, gb_big): | |
d = ctypes.windll.LoadLibrary('MSTR2TSC.DLL') | |
d.TCSCInitialize() | |
ptr, num = ctypes.c_wchar_p(0), ctypes.c_int(0) | |
d.TCSCConvertText(s, len(s), ctypes.byref(ptr), ctypes.byref(num), gb_big, False, True) | |
# 1 or 0 简 -> 繁, False or True 转换常用词、使用港台异体字 | |
out = ptr.value | |
d.TCSCFreeConvertedText(ptr) | |
d.TCSCUninitialize() | |
return out | |
def transId(): | |
app = win32com.client.Dispatch('Indesign.Application.CS5') | |
text = app.ActiveDocument.Selection | |
gb_big = app.DoScript('confirm("是(Enter):繁>简\\n否(Esc):简>繁", 0, "简繁转换")', 1246973031) | |
try: | |
text.Contents = translate(text.Contents, gb_big) | |
except AttributeError: | |
text[0].Contents = translate(text[0].Contents, gb_big) | |
if __name__ == '__main__': | |
transId() |
链接已失效,另外这个方法现在似乎用不了了,dll导入时会提示找不到模块
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
采用 cx_Freeze 打包。打包好的程序在此下载。
运行方法:解压至 ID CS5 脚本文件夹,选中文本或文本框后,脚本面板双击.exe文件运行。
打包所用 setup.py 如下:
命令行输入
python setup.py build
运行。