- 将函数的旧代码替换为以下内容:gp:drawOutline
;;;---------------------------------------------------------------
;;;     Function: gp:drawOutline                                  
;;;---------------------------------------------------------------
;;;  Description: This function will draw the outline of the garden
;;;               path.                                            
;;;--------------------------------------------------------------- 
;;;  Note: No error checking or validation is performed on the     
;;;  BoundaryData parameter.  The sequence of items within this
;;;  parameter does not matter, but it is assumed that all sublists
;;;  are present and contain valid data.                           
;;; --------------------------------------------------------------
(defun gp:drawOutline (BoundaryData / VLADataPts PathAngle
                                      Width HalfWidth StartPt PathLength
                                      angm90 angp90 p1 p2
                                      p3 p4 polypoints pline
                      )
  ;; extract the values from the list BoundaryData
  (setq PathAngle (cdr (assoc 50 BoundaryData))
        Width (cdr (assoc 40 BoundaryData))
        HalfWidth (/ Width 2.00)
        StartPt (cdr (assoc 10 BoundaryData))
        PathLength (cdr (assoc 41 BoundaryData))
        angp90 (+ PathAngle (Degrees->Radians 90))
        angm90 (- PathAngle (Degrees->Radians 90))
        p1 (polar StartPt angm90 HalfWidth)
        p2 (polar p1 PathAngle PathLength)
        p3 (polar p2 angp90 Width)
        p4 (polar p3 (+ PathAngle (Degrees->Radians 180)) PathLength)
        polypoints (apply 'append
                     (mapcar '3dPoint->2dPoint (list p1 p2 p3 p4))
                   )
  )
  ;; ***** data conversion *****
  ;; Notice, polypoints is in AutoLISP format, consisting of a list
  ;; of the 4 corner points for the garden path.
  ;; The variable needs to be converted to a form of input parameter
  ;; acceptable to ActiveX calls.
  (setq VLADataPts (gp:list->variantArray polypoints))
  ;; Add polyline to the model space using ActiveX automation.
  (setq	pline (vla-addLightweightPolyline
                 *ModelSpace*; Global Definition for Model Space
                 VLADataPts
              ) ;_ end of vla-addLightweightPolyline
  ) ;_ end of setq
  (vla-put-closed pline T)
  ;; Return the ActiveX object name for the outline polyline
  ;; The return value should look something like this:
  ;; #<VLA-OBJECT IAcadLWPolyline 02351a34> 
  pline
) ;_ end of defun
 请注意,现在返回变量 ,而不是函数的存根版本中使用的带引号的符号。gp:drawOutlinepline'SomeEname
  
- 通过选择刚刚输入的代码并选择 Visual LISP 工具栏上的“格式选择”按钮来设置刚刚输入的代码的格式。
 
- 启用 ActiveX 并为指向模型空间的指针添加全局变量赋值,如前所述。滚动到文本编辑器窗口的顶部,并在第一个窗口之前添加以下代码:defun
;;;--------------------------------------------------------------
;;; First step is to load ActiveX functionality. If ActiveX support 
;;; already exists in document (can occur when Bonus tools have been 
;;; loaded into AutoCAD), nothing happens. Otherwise, ActiveX 
;;; support is loaded.                                
;;;---------------------------------------------------------------
(vl-load-com)
;;; In Lesson 4, the following comment and code is moved to utils.lsp
;;;---------------------------------------------------------------
;;; For ActiveX functions, we need to define a global variable that 
;;; "points" to the Model Space portion of the active drawing. This 
;;; variable, named *ModelSpace* will be created at load time.      
;;;---------------------------------------------------------------
(setq *ModelSpace*
      (vla-get-ModelSpace
        (vla-get-ActiveDocument (vlax-get-acad-object))
      ) ;_ end of vla-get-ModelSpace
) ;_ end of setq
 请注意上面的代码如何存在于任何 .因此,Visual LISP 会在您加载文件时自动执行代码。defun
  
- 在函数中查找以下行:C:GPath
(setq PolylineName (gp:drawOutline))
 将其更改为以下内容:
 (setq PolylineName (gp:drawOutline gp_PathData))
 该函数现在需要一个参数(包含折线边界数据的列表),并且此更改满足了该要求。gp:drawOutline
  
- 将 Constructing a Variant from a List of Points 中显示的函数添加到 gpmain.lsp 的末尾。gp:list->variantArray
尝试加载并运行修订后的程序。在看到最终结果之前,Visual LISP 会从 AutoCAD 中移除控制权,因此在控件返回到 Visual LISP 后,请切换回 AutoCAD 窗口。如果程序运行正常,您应该会看到花园小径的边框。如果发现错误,请调试代码,然后重试。