CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoLISP 开发指南

更新存根函数

2023-1-5 07:38| 发布者: admin| 查看: 279| 评论: 0|来自: AutoCAD

您现在已经修改了函数。每当您修改存根函数时,都应始终检查以下几点:gp:getDialogInput

  • 声明是否发生了变化?也就是说,该函数是否仍然采用相同数量的参数?defun
  • 该函数是否返回不同的东西?

在这种情况下,这两个问题的答案都是肯定的。该函数现在接受路径宽度的参数(用于设置默认磁贴大小和间距)。而不是返回函数的存根版本返回的值,现在返回一个包含四个新值的关联列表。gp:getDialogInputTgp:getDialogInput

这两种更改都会影响调用函数的代码和处理函数返回值的代码。将gpmain.lsp中以前版本的函数替换为以下代码:C:GPath

(defun C:GPath (/ gp_PathData gp_dialogResults)
  ;; 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 (setq gp_dialogResults (gp:getDialogInput (cdr(assoc 40
                               gp_PathData))))
      (progn
        ;; Now take the results of gp:getPointInput and append this
        ;; to the added information supplied by gp:getDialogInput.
        (setq gp_PathData (append gp_PathData gp_DialogResults))

        ;; At this point, you have all the input from the user.
        ;; Draw the outline, storing the resulting polyline
        ;; "pointer" in the variable called PolylineName.
        (setq PolylineName (gp:drawOutline gp_PathData))
      ) ;_ 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

  • 调用函数时,路径宽度将传递给它。这是通过提取与关联列表的键 40 索引关联的值来完成的。gp:getDialogInputgp_PathData
  • 返回的关联列表 by 分配给调用的变量。如果此变量具有值,则需要将其内容追加到已存储的关联列表值中。gp:getPointInputgp_dialogResultsgp_PathData

由于替换了存根版本中的占位符,代码中还有其他更改。最简单的方法是从在线教程中复制此代码并将其粘贴到您的文件中。


路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 12:43

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部