AutoCAD中的AutoLISP函数不良参数

问题描述 投票:0回答:1
(defun gml2dwg (odabir)

    ;; RANDOM CODE ;;
    ;; This is the part where I should open a filepath "odabir" 
    (setq datoteka (open odabir "r"))

    ;; CODE IS CONTINUED )

(defun c:gml2dwg (/ odabir)   
    (setq odabir (getstring "Odabir:"))  
    (gml2dwg odabir)   
    (princ) )

(defun c:gmlimport (/ allfiles fpath)   
     (setq allfiles (vl-directory-files "C:\\Users\\Admin\\Documents\\gml2" "*.gml"))  
(foreach file allfiles
    ((setq fpath (strcat "C:\\Users\\Admin\\Documents\\gml2\\" file))
    (gml2dwg fpath))   )
      (princ) )

因此,如上所示,我有第一个长lisp函数gml2dwg,它将gml文件作为输入,并从autocad中的文件中绘制多边形。该函数只能将一个文件作为输入,因此我在向cad输入6000+ gml文件时遇到问题。我写了另外两个函数,其中c:gml2dwg是一个能够获取参数的函数,因为gml2dwg不能用作命令。第三个--c:gmlimport用于从目录获取所有文件并通过c:gml2dwg循环它,但我得到的只是这个错误:

*********Pogreška:坏参数类型:stringp nil! **********如果没有事先调用(push-error-using-command),则无法从错误中调用(命令)。建议将(命令)调用转换为(command-s)。

第一个函数在VLISP控制台(gml2dwg“somefilepath”)中调用它的形式工作正常。谁能告诉我其他两个功能有什么问题?它可能是参数/参数或设置变量,但我在lisp中是一个业余爱好者,所以我需要你的帮助才能搞清楚。谢谢。

lisp autocad autolisp
1个回答
1
投票

如果我没有误解,gml2dwg是一个LISP定义的命令:

(defun c:gml2dwg ...)

如果是这样,您不能使用命令函数调用gml2dwg并传递参数。您需要将c:gml2dwg函数拆分为2个函数:

1)标准的LISP函数,它有两个参数:一些选项(“k”?)和文件路径。此函数包含根据参数绘制多边形的代码。

(defun gml2dwg (option fpath) ...)

2)一个LISP定义的命令,它获取用户输入并调用gml2dwg函数传递输入结果。

(defun c:gml2dwg (/ option fpath ...)
  (setq option ...)
  (setq fpath ...)
  (gml2dwg option fpath)
  (princ)
)

这样,您可以从c:gmlimport调用gml2dwg函数:

(defun c:gmlimport (/ allfiles fpath)
  (setq allfiles (vl-directory-files
           "C:\\Users\\Admin\\Documents\\gml2"
           "*.gml"
         )
  )
  (foreach file allfiles
    (setq fpath (strcat "C:\\Users\\Admin\\Documents\\gml2\\" file))
    (gml2dwg "k" fpath)
  )
  (princ)
)

注意:我删除了一个多余的左括号。

© www.soinside.com 2019 - 2024. All rights reserved.