gardenpath 関数は、庭園の歩道を描くために、ユーザが AutoCAD のコマンド プロンプトまたはユーザ インタフェースから実行する主要なカスタム関数です。
gardenpath 関数を実行すると、ユーザ入力を取得し、次にその入力に基づいて庭園の歩道を描画する一連のセカンダリ関数が実行されます。gardenpath 関数がこれらのセカンダリ関数にアクセスするようにするためには、これらのセカンダリ関数を gard npath 関数の実行前にロードしておく必要があります。AutoLISP の load 関数を使用して LSP ファイルをロードし、このファイルに格納されている関数を、ユーザおよび AutoCAD にロードされているその他の AutoLISP 関数が使用できるようにします。
次に、gardenpath 関数を格納するために使用する LSP ファイルを作成し、gardenpath 関数によって使用されるセカンダリ関数を含む LSP ファイルをロードする方法を説明します。
[すべてのプログラム]
[アクセサリ]
[メモ帳]をクリックします。
[名前を付けて保存]を選択します。 LSP ファイルは閉じないでください。
[アプリケーション]を選択します。
[環境設定]を選択します。
[保存]を選択します。 LSP ファイルは閉じないでください。
次に、gpmain.lspファイルが AutoCAD にロードされたときに load 関数を使用して utils.lsp、gpdraw.lsp、gp-io.lsp ファイルをロードする方法を説明します。
(load "utils.lsp" "\nutils.lsp was not loaded successfully.") (load "gpdraw.lsp" "\ngpdraw.lsp was not loaded successfully.") (load "gp-io.lsp" "\ngp-io.lsp was not loaded successfully.")
次の手順では、gardenpath という名前の関数を定義できます。この関数は、次のセカンダリ関数を指定した順序で実行します。
gardenpath 関数は、いずれの引数も受け入れず、値も返しません。
(defun c:gardenpath ( / osmode-old cmdecho-old gp_PathData
gp_TileData gp_BorderStyle tileList
)
; Begin undo recording
(command "._undo" "_be")
; Turn off object snapping
(setq osmode-old (getvar "OSMODE"))
(setvar "OSMODE" 0)
; Turn off command echoing
(setq cmdecho-old (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
; Prompt the user the input that will define the path
; Store the path data
(if (setq gp_PathData (gp:getPathInput))
(if (setq gp_TileData (gp:getTileInput))
(if (setq gp_BorderStyle (gp:getBorderStyleInput))
(progn
; Append the results of gp:getPointInput, gp:getTileInput,
; and gp:getBorderStyle into a single list
(setq gp_PathData (append gp_PathData
gp_TileData
gp_BorderStyle
)
)
; Get the boundary list returned by the gp:calcPathBoundary function.
; The list of boundary points is expressed as the DXF values 12
; through 15.
(setq gp_pathData (append gp_pathData
(cadr (gp:calcPathBoundary gp_PathData))
)
)
; Add the tiles within the path boundary
(prompt (strcat "\nThe path required "
(itoa
(length
(setq tileList (gp:calcTiles gp_PathData))
)
)
" tiles."
)
)
; Add the tiles to the path data
(setq gp_PathData (append (list (cons 100 tileList))
gp_PathData
)
)
)
(prompt "\nFunction cancelled.")
)
(prompt "\nIncomplete information to draw tiles.")
)
(prompt "\nIncomplete information to draw boundary.")
)
; Restore the previous values of OSMODE and CMDECHO
(setvar "OSMODE" osmode-old)
(setvar "CMDECHO" cmdecho-old)
; End undo recording
(command "._undo" "_e")
(princ)
)
次の手順では、gardenpath 関数を実行する、短縮された名前を持つ新しい関数を実装できます。短縮された名前は、コマンド プロンプトに対して直接入力することができます。
(defun c:gp ( / )(c:gardenpath))
(prompt "\nType GARDENPATH or GP to draw a garden path.") (princ)