10. Defun ÇÔ¼ö

 

AutoLISP¾È¿¡¼­´Â º°µµÀÇ ÇÔ¼ö¿Í ÇÁ·Î±×·¥À» ±¸ºÐÇÏÁö ¾ÊÀ¸¸ç ÇϳªÀÇ ÇÁ·Î±×·¥ ¾È¿¡¼­´Â ´ÙÁßÀÇ ÇÔ¼ö°¡ Á¤ÀÇÇÒ ¼ö ÀÖ°í

°¢°¢ÀÇ ÇÔ¼ö´Â ÇÁ·Î±×·¥À¸·Î¼­ÀÇ ±â´ÉÀ» °®´Â´Ù.

 

1. ÇÔ¼ö¼±¾ð½Ã À¯ÀÇ »çÇ×

    (1) ÇÔ¼öÀÇ À̸§Àº Ç×»ó ¾ËÆĺªÀ¸·Î ½ÃÀÛÇÏ¿©¾ß ÇÑ´Ù.

    (2) ÇÔ¼ö¸íÀº ¿µ¹®ÀÚ¿Í ¼ýÀÚÀÇ Á¶ÇÕÀ¸·Î ÀÌ·ç¾îÁö¸ç, Ư¼ö ±âÈ£(-, ;, ! µî)ÀÇ »ç¿ëÀÌ °¡´ÉÇÏ´Ù.

    (3) ÇÔ¼ö ¾ÈÀÇ ()ÀÇ °¹¼ö´Â ¹Ýµå½Ã °°¾Æ¾ß ÇÑ´Ù.

    (4) ¼¼¹ÌÄÝ·Ð(;)Àº ÁÖ¼®À̸ç, ±× ÇุÀ» Æ÷ÇÔÇÑ´Ù.

 

 

2. DEFUN (DEfine FUNction)

    (1) ±â´É

      »ç¿ëÇÒ ÇÔ¼ö¸¦ ¼±¾ðÇÏ´Â ÇÔ¼ö(ÇÔ¼ö À̸§À» Á¤ÀÇÇÔ)

      ¹ÝȯµÇ´Â °ªÀº °¡Àå ³ªÁß¿¡ ÁöÁ¤µÇ´Â °ªÀ¸·Î ´ÙÁßÀÇ °ªÀ» ¹ÝȯÇÏ°í ½ÍÀ¸¸é

      List¸¦ »ç¿ëÇÑ´Ù.

    (2) »ç¿ë¹ý

      (DEFUN  Function-name()

            Expression

            return value

      )

     

 

3. º¯¼öÀÇ Á¾·ù

    (1) ±¤¿ª º¯¼ö

      º¯¼öµéÀÇ °ªÀº ÇÁ·Î±×·¥ÀÌ ³¡³­ ÈÄ¿¡µµ ¾ø¾îÁöÁö ¾Ê°í Á¸ÀçÇÑ´Ù.

      ºñ¾î ÀÖ´Â °ýÈ£´Â ¸ðµç º¯¼ö¸¦ ±¤¿ª º¯¼ö·Î »ç¿ëÇÔÀ» ÀǹÌÇÑ´Ù.

      (Defun sample-01()

          Expression

      )

     

    (2) Áö¿ª º¯¼ö

      °ýÈ£ ¾ÈÀÇ Slash ÀÌÈÄÀÇ º¯¼öµéÀº ÇÁ·Î±×·¥ÀÌ ½ÇÇàµÉ ¶§ ÇÁ·Î±×·¥ ¾È¿¡¼­¸¸ °ªÀ» °¡Áø´Ù.

      (Defun sample-02( / variable variable ......)

          Expression

      )

     

    (3) µ¶¸³ º¯¼ö

      ÇÁ·Î±×·¥ ½ÇÇà½Ã ¿ÜºÎ·ÎºÎÅÍ º¯¼öÀÇ °ªÀ» ¹Þ¾Æµé¿© »ç¿ëÇÑ´Ù.

      (Defun sample-03(variable variable ......)

          Expression

      )

     

    (4) ¸í·É¾î Á¤ÀÇ ÇÔ¼ö

      Defun ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© AutoCAD¿¡ »õ·Î¿î ¸í·ÉÀ» Á¤ÀÇÇÑ´Ù.

      (Defun c:sample-04()

        Expression

      )

     

    ** Âü°í

      ¸í·É¾î Á¤ÀÇ ÇÔ¼ö ¿Ü¿¡ ÇÔ¼ö´Â ½ÇÇàÀ» À§ÇÏ¿© °ýÈ£¸¦ »ç¿ëÇؾ߸¸ ÇÑ´Ù.

 

 

4. ÇÔ¼ö ¼±¾ð ¿¹

    (1) ±¤¿ª º¯¼ö¸¦ »ç¿ëÇÏ´Â ÇÔ¼ö

       ¿¹Á¦ ÇÁ·Î±×·¥-01

       °á°ú

       

       (defun sample-01()

        (setq x 100)

        (setq y (+ x x))

        y                  ;; y°ª ¹Ýȯ

       )

       

       Command: (load "c:/sample")

       SAMPLE-01

       

       Command: (setq y1 (sample-01))

       200

       

       Command: !x

       100

       

       Command: !y

       200

       

       Command: !y1

       200

       

       ¸ðµç º¯¼ö¸¦ ±¤¿ª º¯¼ö·Î ¼±¾ð

       ÇÁ·Î±×·¥ Á¾·á ÈÄ x¿Í y°ªÀº °è¼Ó Á¸ÀçÇÑ´Ù.

       

    (2) Áö¿ª º¯¼ö¸¦ »ç¿ëÇÏ´Â ÇÔ¼ö

       ¿¹Á¦ ÇÁ·Î±×·¥-02

       °á°ú

       

       (defun sample-02( / x y)

        (setq x 100)

        (setq y (+ x x))

        (list x y)       ;; x , y°ªÀ» List·Î ¹Ýȯ

       )

       

       Command: (load "c:/sample")

       SAMPLE-02

       

       Command: (setq xylist (sample-02))

       200

       

       Command: !x

       nil

       

       Command: !y

       nil

       

       Command : !xylist

       (100 200)

       

       x¿Í y¸¦ Áö¿ª º¯¼ö·Î ¼±¾ð

       ÇÁ·Î±×·¥ Á¾·áÈÄ x¿Í yÀÇ °ªÀº ¾ø¾îÁø´Ù.

       

    (3) µ¶¸³ º¯¼ö¸¦ »ç¿ëÇÏ´Â ÇÔ¼ö

        ¿¹Á¦ ÇÁ·Î±×·¥-03

        °á°ú

       

       (defun sample-03(x)      ;; x°ªÀ» Àü´Þ ¹ÞÀ½

        (setq y (+ x x))

        y                   ;; y°ª ¹Ýȯ

       )

       

       

       Command: (load "c:/hello")

       SAMPLE

       

       Command: (setq y1 (sample-03 100))

       200

       

       Command: !x

       100

       

       Command: !y

       200

       

       Command: !y1

       200

       

       x¸¦ µ¶¸³ º¯¼ö·Î ¼±¾ð

       ÇÁ·Î±×·¥ ½ÇÇà½Ã xÀÇ °ªÀ» ÁöÁ¤ÇØ¾ß ÇÑ´Ù.

     

    (4) ¸í·É¾î Á¤ÀÇ ÇÔ¼ö

        ¿¹Á¦ ÇÁ·Î±×·¥-04

       °á°ú

       

       (defun c:sample-04()

        (setq x 100)

        (setq y (+ x x))

       )

       

       Command: (load "c:/sample")

       SAMPLE-04

       

       Command: sample-04

       200

       

       Command: !x

       100

       

       Command: !y

       200

       

       sample-04¸¦ ¸í·É¾î Á¤ÀÇ ÇÔ¼ö·Î ÁöÁ¤

       ÇÁ·Î±×·¥ ½ÇÇà½Ã °ýÈ£¸¦ »ç¿ëÇÏÁö ¾Ê¾Æµµ µÈ´Ù.

     

     

    (5) ¸í·É¾î Á¤ÀÇ ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ ¿¹Á¦ ÇÁ·Î±×·¥

       »ç°¢ÇüÀ» ±×¸®´Â ÇÁ·Î±×·¥

       

       

        (Defun c:sample-05( / xy01 xy02 xy03 xy04)

        (setq xy01 (list 100 100))

        (setq xy03 (list 200 200))

        (setq xy02 (list (car xy01) (cadr xy03)))

        (setq xy04 (list (car xy03) (cadr xy01)))

        (command "line" xy01 xy02 xy03 xy04 "c")

       )

       

       Command: (load "c:/sample")

       C:SAMPLE-05

       

       Command: sample-05

       line From point:

       To point:

       To point:

       To point:

       To point: c

       Command: nil

       

       Command: !xy01

       nil

       

       Command: !xy02

       nil

       

       Command: !xy03
       nil

       

       Command: !xy04
       nil

       

     

     

 

COMMAND ÇÔ¼ö

ÃÖÃÊ ÀÛ¼ºÀÏ 2000.02.25

Ãâ·Â ÇÔ¼ö

ÃÖÁ¾ ¼öÁ¤ÀÏ 2006.04.05