# 아래한글 자체 스크립트 매크로와 파이썬 코드의 속도 차이를 좁힐 방법이 있을까요??

**URL:** <https://forum.developer.hancom.com/t/topic/2249>\
**Category:** 한글 오토메이션\
**Created:** [2월 23, 2025, 7:18오전 UTC](https://forum.developer.hancom.com/t/topic/2249 "2025-02-23T07:18:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user322](https://avatars.discourse-cdn.com/v4/letter/u/eb9ed0/32.png) [@user322](https://forum.developer.hancom.com/u/user322)\
**Post date:** [2월 23, 2025, 7:18오전 UTC](https://forum.developer.hancom.com/t/topic/2249/1 "2025-02-23T07:18:27Z")

</div>

안녕하세요.  
아래한글 자체 스크립트 매크로와 파이썬 코드의 속도 차이를 좁힐 방법이 있을까요??

간단하게 테스트를 해보면 아래는 한글 스크립트 매크로입니다.

```
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) 을 사용해봐도 마찬가지네요.

해결 방법이 있을까요?? 많은 조언 부탁 드립니다.

날씨가 아직도 쌀쌀하네요.  
감기 조심하시고 건강하세요~~

---

<div class="post-metadata">

**Author:** ![ygyoun](https://avatars.discourse-cdn.com/v4/letter/y/b4bc9f/32.png) [@ygyoun](https://forum.developer.hancom.com/u/ygyoun)\
**Post date:** [2월 24, 2025, 1:24오전 UTC](https://forum.developer.hancom.com/t/topic/2249/2 "2025-02-24T01:24:51Z")

</div>

안녕하세요  
저는 속도 차이가 크지 않은데 특정 문서에서 그럴까요? 특별히 발생하는 조건은 없을까요?

아래는 스크립트 매크로로 실행한 결과입니다.  
 ![Untitled video - Made with Clipchamp (1)](https://us1.discourse-cdn.com/flex016/uploads/hancom_dev_forum/original/2X/b/b848d908854a223e97c763e9addf0b9ff5dc84e6.gif)

아래는 파이썬으로 동작한 결과입니다.  
 ![Untitled video - Made with Clipchamp (3)](https://us1.discourse-cdn.com/flex016/uploads/hancom_dev_forum/original/2X/e/e540bdf8a96c5d3051c8e71a29256ed0c2b69f3e.gif)

확인 부탁드립니다.

감사합니다.

---

<div class="post-metadata">

**Author:** ![user322](https://avatars.discourse-cdn.com/v4/letter/u/eb9ed0/32.png) [@user322](https://forum.developer.hancom.com/u/user322)\
**Post date:** [2월 24, 2025, 5:16오전 UTC](https://forum.developer.hancom.com/t/topic/2249/3 "2025-02-24T05:16:35Z")

</div>

안녕하세요. 답변감사합니다.  
음… 예시 매크로를 한번만 실행할때는 한글 스크립트와 파이썬 코드 간의 시간 차이가 크지 않는데요.  
제가 만들고 있는 매크로는 한페이지당 많게는 10번 넘게 눌러야 해서  
반복하다 보면 그 시간차이가 꽤 크네요…  
그리고 아주 심플한 코드로 테스트를 한지라 시간차이가 더 작게 보일수 있겠네요.

아래 코드를 2-3번 연속 실행해 보시면 조금더 시간차이를 느끼실듯 합니다.  
한글이 열려있는 창에서 표 안에 커서를 두시고 2-3번 연속 실행해 보시면  
차이를 확연히 느끼실듯 합니다.

한글스크립트

```auto
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’  
이렇게 사용하는데, 다른분들은 버전에 맞게 숫자를 변경 하시면 됩니다.

```auto
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_())

```

- 한글스크립트  
 ![한글스크립트](https://us1.discourse-cdn.com/flex016/uploads/hancom_dev_forum/original/2X/4/4b2105ad50b8101166ee7af216c4826c1c5f3349.gif)

- 파이썬  
 ![파이썬](https://us1.discourse-cdn.com/flex016/uploads/hancom_dev_forum/original/2X/9/9903321b223d5aea5ca33135b665517cb2469fc1.gif)

---

<div class="post-metadata">

**Author:** ![ilco](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.developer.hancom.com/ilco/32/1213_2.png) [@ilco](https://forum.developer.hancom.com/u/ilco)\
**Post date:** [2월 24, 2025, 11:03오전 UTC](https://forum.developer.hancom.com/t/topic/2249/4 "2025-02-24T11:03:18Z")

</div>

아무래도 프로그램 바깥이랑 통신을 해야 하니 속도가 저하되나봐요ㅜ

화면을 계속 모니터링해야 하는 게 아니라면,

시간이 많이 걸리는 작업 직전에

Visible을 False로 바꾸시거나, 최소화하시는 방법도 추천드립니다…

(그쯤은 알고 계실 듯ㅜ)

---

<div class="post-metadata">

**Author:** ![user322](https://avatars.discourse-cdn.com/v4/letter/u/eb9ed0/32.png) [@user322](https://forum.developer.hancom.com/u/user322)\
**Post date:** [2월 25, 2025, 6:54오전 UTC](https://forum.developer.hancom.com/t/topic/2249/5 "2025-02-25T06:54:32Z")

</div>

편집중에 계속 써야 하는 부분이라서 안될듯 하네요. ㅠㅠ  
번거로워도 한글스크립트를 써야겠네요.  
답변감사합니다. ^^~

---

<div class="post-metadata">

**Author:** ![ilco](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.developer.hancom.com/ilco/32/1213_2.png) [@ilco](https://forum.developer.hancom.com/u/ilco)\
**Post date:** [2월 25, 2025, 7:45오전 UTC](https://forum.developer.hancom.com/t/topic/2249/6 "2025-02-25T07:45:56Z")

</div>

속도가 느린 파이썬 스크립트는 `hwp.RunScriptMacro` 메서드로 한글스크립트를 직접실행하게 할 수 있으니까… 하이브리드하게 쓰세요ㅋ
