안녕하세요.
아래한글 자체 스크립트 매크로와 파이썬 코드의 속도 차이를 좁힐 방법이 있을까요??
간단하게 테스트를 해보면 아래는 한글 스크립트 매크로입니다.
function OnScriptMacro_테스트_1()
{
HAction.Run("TableCellBlock");
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
HAction.Run("TableUpperCell")
}
표에서 셀 블럭잡고 위로 10줄 이동하는 매크로인데.
실행하면 언제 실행했냐는듯 짠… 하는데…
이걸 파이썬으로 코딩을 해보면
(열려있는 한글파일에서 실행 되는 기본소스는 생략…)
hwp.HAction.Run("TableCellBlock")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("TableUpperCell")
이렇게 되는데 눈에 보일정도로 후루룩 실행이 됩니다.
물론 아래처럼 반복문을 사용해서 해도 마찬가지네요…
hwp.HAction.Run("TableCellBlock")
for i in range(10):
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run이 느린가 해서 hwp.MovePos(102,0,0) 을 사용해봐도 마찬가지네요.
해결 방법이 있을까요?? 많은 조언 부탁 드립니다.
날씨가 아직도 쌀쌀하네요.
감기 조심하시고 건강하세요~~
1개의 좋아요
안녕하세요
저는 속도 차이가 크지 않은데 특정 문서에서 그럴까요? 특별히 발생하는 조건은 없을까요?
아래는 스크립트 매크로로 실행한 결과입니다.
아래는 파이썬으로 동작한 결과입니다.
확인 부탁드립니다.
감사합니다.
1개의 좋아요
안녕하세요. 답변감사합니다.
음… 예시 매크로를 한번만 실행할때는 한글 스크립트와 파이썬 코드 간의 시간 차이가 크지 않는데요.
제가 만들고 있는 매크로는 한페이지당 많게는 10번 넘게 눌러야 해서
반복하다 보면 그 시간차이가 꽤 크네요…
그리고 아주 심플한 코드로 테스트를 한지라 시간차이가 더 작게 보일수 있겠네요.
아래 코드를 2-3번 연속 실행해 보시면 조금더 시간차이를 느끼실듯 합니다.
한글이 열려있는 창에서 표 안에 커서를 두시고 2-3번 연속 실행해 보시면
차이를 확연히 느끼실듯 합니다.
한글스크립트
function OnScriptMacro_테스트_1()
{
HAction.Run("Cancel");
HAction.Run("TableCellBlock");
HAction.Run("TableColPageDown");
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("TableResizeDown");
HAction.Run("TableUpperCell")
HAction.Run("Cancel");
}
파이썬 코드
*물론 아시겠지만 저는 한글버전 네오를 사용해서
if name == ‘!HwpObject.96.1’
이렇게 사용하는데, 다른분들은 버전에 맞게 숫자를 변경 하시면 됩니다.
import sys
import pythoncom
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
from win32com.client import Dispatch
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('테스트_01')
self.setGeometry(100, 100, 300, 200)
self.button_01 = QPushButton('클릭', self)
self.button_01.move(100, 80)
self.button_01.clicked.connect(self.cell_up)
def cell_up(self):
context = pythoncom.CreateBindCtx(0)
running_coms = pythoncom.GetRunningObjectTable()
monikers = running_coms.EnumRunning()
for moniker in monikers:
name = moniker.GetDisplayName(context,moniker);
if name == '!HwpObject.96.1': #저는 네오를 사용중이라 96.1을 사용하였습니다.
# 2010 : "!HwpObject.80.1"
# 2014 : "!HwpObject.90.1"
# NEO : "!HwpObject.96.1"
# 2018 : "!HwpObject.100.1"
# 2020 : "!HwpObject.110.1"
# 2022 : "!HwpObject.120.1"
# 2024 : "!HwpObject.130.1"
obje = running_coms.GetObject(moniker)
hwp = Dispatch(obje.QueryInterface(pythoncom.IID_IDispatch))
hwp.HAction.Run("Cancel");
hwp.HAction.Run("TableCellBlock")
hwp.HAction.Run("TableColPageDown");
for i in range(10):
hwp.HAction.Run("TableResizeDown");
hwp.HAction.Run("TableUpperCell")
hwp.HAction.Run("Cancel");
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
한글스크립트
파이썬
1개의 좋아요
ilco
2월 24, 2025, 11:03오전
4
아무래도 프로그램 바깥이랑 통신을 해야 하니 속도가 저하되나봐요ㅜ
화면을 계속 모니터링해야 하는 게 아니라면,
시간이 많이 걸리는 작업 직전에
Visible을 False로 바꾸시거나, 최소화하시는 방법도 추천드립니다…
(그쯤은 알고 계실 듯ㅜ)
편집중에 계속 써야 하는 부분이라서 안될듯 하네요. ㅠㅠ
번거로워도 한글스크립트를 써야겠네요.
답변감사합니다. ^^~
2개의 좋아요
ilco
2월 25, 2025, 7:45오전
6
속도가 느린 파이썬 스크립트는 hwp.RunScriptMacro
메서드로 한글스크립트를 직접실행하게 할 수 있으니까… 하이브리드하게 쓰세요ㅋ
1개의 좋아요