AutoLISP コードで連想リストを使用する方法は説明したので、gp:getPointInput 関数の完成バージョンの記述にこの方法を使用することができるでしょう。gpmain.lsp として保存した gp:getPointInput の前バージョンを、次に示すコードに置き換えてください。
;;;--------------------------------------------------------------;
;;; Function: gp:getPointInput ;
;;;--------------------------------------------------------------;
;;; Description: This function asks the user to select three ;
;;; points in a drawing, which will determine the ;
;;; path location, direction, and size. ;
;;;--------------------------------------------------------------;
;;; If the user responds to the get functions with valid data, ;
;;; use startPt and endPt to determine the position, length, ;
;;; and angle at which the path is drawn. ;
;;;--------------------------------------------------------------;
;;; The return value of this function is a list consisting of: ;
;;; (10 . Starting Point) ;; List of 3 reals (a point) denoting ;
;;; ;; starting point of garden path. ;
;;; (11 . Ending Point) ;; List of 3 reals (a point) denoting ;
;;; ;; ending point of garden path. ;
;;; (40 . Width) ;; Real number denoting boundary ;
;;; ;; width. ;
;;; (41 . Length) ;; Real number denoting boundary ;
;;; ;; length. ;
;;; (50 . Path Angle) ;; Real number denoting the angle ;
;;; ;; of the path, in radians. ;
;;;--------------------------------------------------------------;
(defun gp:getPointInput (/ StartPt EndPt HalfWidth)
(if (setq StartPt (getpoint "\nStart point of path: "))
(if (setq EndPt (getpoint StartPt "\nEndpoint of path: "))
(if (setq HalfWidth (getdist EndPt "\nhalf-width of path: "))
;; if you've made it this far, build the association list
;; as documented above. This will be the return value
;; from the function.
(list
(cons 10 StartPt)
(cons 11 EndPt)
(cons 40 (* HalfWidth 2.0))
(cons 50 (angle StartPt EndPt))
(cons 41 (distance StartPt EndPt))
) ) ) ) )
次に、gpmain.lsp のメイン関数 C:GPath を更新します。この関数を次のコードのように変更します。
(defun C:GPath (/ gp_PathData)
;; Ask the user for input: first for path location and
;; direction, then for path parameters. Continue only if you
;; have valid input. Store the data in gp_PathData.
(if (setq gp_PathData (gp:getPointInput))
(if (gp:getDialogInput)
(progn
;; At this point, you have valid input from the user.
;; Draw the outline, storing the resulting polyline
;; pointer in the variable called PolylineName.
(setq PolylineName (gp:drawOutline))
(princ "\nThe gp:drawOutline function returned <")
(princ PolylineName)
(princ ">")
(Alert "Congratulations - your program is complete!")
) ;_ end of progn
(princ "\nFunction cancelled.")
) ;_ end of if
(princ "\nIncomplete information to draw a boundary.")
) ;_ end of if
(princ) ; exit quietly
);_ end of defun
コードをコピーして貼り付ける場合、C:GPath: の先頭のヘッダとして、次のコメントを追加してください。
;;;**************************************************************; ;;; Function: C:GPath The Main Garden Path Function ; ;;;--------------------------------------------------------------; ;;; Description: This is the main garden path function. It is a ; ;;; C: function, meaning that it is turned into an ; ;;; AutoCAD command called GPATH. This function ; ;;; determines the overall flow of the garden path ; ;;; program. ; ;;;**************************************************************; ;;; The gp_PathData variable is an association list of the form: ; ;;; (10 . Starting Point) - List of 3 reals (a point) denoting ; ;;; starting point of the garden path. ; ;;; (11 . Ending Point) - List of 3 reals (a point) denoting ; ;;; endpoint of the garden path. ; ;;; (40 . Width) - Real number denoting boundary ; ;;; width. ; ;;; (41 . Length) - Real number denoting boundary ; ;;; length. ; ;;; (50 . Path Angle) - Real number denoting the angle of ; ;;; the path, in radians. ; ;;; (42 . Tile Size) - Real number denoting the size ; ;;; (radius) of the garden path tiles. ; ;;; (43 . Tile Offset) - Spacing of tiles, border to border. ; ;;; ( 3 . Object Creation Style) ; ;;; - Object creation style indicates how ; ;;; the tiles are to be drawn. The ; ;;; expected value is a string and one ; ;;; one of three values (string case ; ;;; is unimportant): ; ;;; "ActiveX" ; ;;; "Entmake" ; ;;; "Command" ; ;;; ( 4 . Polyline Border Style) ; ;;; - Polyline border style determines ; ;;; the polyline type to be used for ; ;;; path boundary. The expected value ; ;;; one of the following (string case is; ;;; unimportant): ; ;;; "Pline" ; ;;; "Light" ; ;;;**************************************************************;
プログラムが正常に実行されないときは、誤りを修正し、もう一度実行してください。可能な限り、修正と実行を繰り返してください。どうしても正常に実行できない場合は、Tutorial¥VisualLISP¥Lesson2 フォルダから正しいコードをコピーしてもかまいません。