aaryan 发表于 2022-7-6 07:52:22

错误的参数值:不是f

大家好,
 
运行此代码后,我收到一个错误(错误的参数值:不适合字节),无法找到解决方案。请帮忙。
 
(defun c:Bathy (/ tpath fd info Soundings Bs Bsc BSL data ipt ba tpt x y xs ys)
(defun *error* (msg)
(if msg (princ (strcat "\nError! " msg)))
(princ)
)
;//pBe
(defun _roundTruncated(a)
   (setq b (fix a)
         c (* (abs (- a b)) 10))
    (if (= c 0)
      (setq d 0)
         (setq d (fix (+ c (/ c (abs c) 2.0))))))
;//
(setq tpath (getfiled "Select XYZ File" "*.*" "" 4))
   (setvar "cmdecho" 0)
   (setvar "osmode" 0)
   (graphscr)
   (setq fd   (open tpath "r")
info (read-line fd)
   )
   (if        (/= info nil)
   (progn
(if (setq Soundings (getfiled "Select Sounding Block" "*.*" "dwg" 4))
(progn
(setq Bs (Getreal "\nScale factor for Bathymetry Block <1>:"))
(if (= Bs Nil)
(setq Bsc 1)
(setq Bsc Bs)
))(exit))
   )
   (progn (alert "Bathy file is empty") (exit))
   )
   (setq Bsl (rtos Bsc 2 3))
   (while (/= info nil)
   (setq data (read (strcat "(" (vl-string-translate "," " " info) ")"))
         ipt (list (car data)(cadr data))
         bat (atof (rtos (caddr data) 2 4))
    tpt data)
   
   (setq xfin 0
    yfin 0
    zfin 0)
   
   (Setq xfin (car data)
    yfin (cadr data)
    zfin (caddr data))

   (setq xfin (1+ xfin)
    yfin (1+ yfin)
    zfin (1+ zfin))
   
   (setq xlst (cons xfin xlst)
    ylst (cons yfin ylst)
    zlst (cons zfin zlst))
   
   (setq xmax (apply 'max xlst)
    xmax (eval (cons 'max xlst))
    ymax (apply 'max ylst)
    ymax (eval (cons 'max ylst))
    zmax (apply 'max zlst)
    zmax (eval (cons 'max zlst)))

   (setq xmin (apply 'min xlst)
    xmin (eval (cons 'min xlst))
    ymin (apply 'min ylst)
    ymin (eval (cons 'min ylst))
    zmin (apply 'min zlst)
    zmin (eval (cons 'min zlst)))

   (command "_.zoom" "W" (list xmin ymin) (list xmax ymax))
   
   (if (< bat 0)
(progn
   (setq ba (* -1 bat)
    x (fix ba)
         y (_roundTruncated bat))
   (if (= y 10)
(progn
(setq x (+ x 1)
      y 0))
(progn
(setq x x
      y y)))          
   (setq xs (strcat "%%U" (itoa x))
    ys (itoa y))
   (command "insert" Soundings ipt Bsl Bsl 0 xs ys)
   (setq info (read-line fd)))
       (progn
   (setq x(fix bat)
         y (_roundTruncated bat))
   (if (= y 10)
(progn
(setq x (+ x 1)
      y 0))
(progn
(setq x x
      y y)))   
   (setq xs        (itoa x)
    ys        (itoa y))      
   (command "insert" Soundings ipt Bsl Bsl 0 xs ys)
   (setq info (read-line fd))
   )))
   (close fd)
   (command "regen")
   (setvar "osmode" 31743)
   (*error* nil)
   (princ)
)

pBe 发表于 2022-7-6 07:58:00

简而言之,它应该做什么?

aaryan 发表于 2022-7-6 08:02:09

谢谢pBe我一直在等待,很高兴看到你的回复。
实际上,我正在尝试从xyz文件中找出最小和最大x、y和z值。
在得到min x min y和max x以及max y之后,我将使用(命令_.zoom“W”(list minx miny)(list maxx maxy))。
简单地说,我想放大感兴趣的区域,然后我的命令插入应该开始。

pBe 发表于 2022-7-6 08:07:00

 
我明白了,从代码现在的编写方式来看。您希望在每次插入之前“缩放”。这是你想要的吗?
首先,第一次运行时,xlist、ylst、zlst将为缩放窗口传递相同的点值。。。结果*无效*
 
建议:从外部文件收集所有数据,然后从收集的列表中运行“插入和缩放”(如果需要)。但是,您可以调整代码,使其包含一个条件,即只有当xlst/ylst/zlst上有两个或更多数据时,它才会启动缩放。你知道即使这样。直到最后一次插入,您才真正“看到”代码的缩放部分。
 
所以,收集数据。检索最大/最小值,调用缩放,然后开始插入。
 
知道了?

aaryan 发表于 2022-7-6 08:11:17

谢谢
不是每次插入时我都要缩放,而是在导入块之前缩放到整个区域的范围。
例如,我的文件包含
200,300,13.5
300,500,14.6
500,100,17.1
800,1000,19.9
然后我想缩放窗口(list(xmin)200(ymin)100)(list(xmax)800(ymax)1000)整个区域并开始导入。
希望我能做到。
当做

pBe 发表于 2022-7-6 08:16:51

 
(defun _HiLow(lev lev2 lst)
   (list
         (apply lev (mapcar 'car lst))
         (apply lev2 (mapcar 'cadr lst))
         ))
 

(progn         
   (setq fd   (open tpath "r"))
(while(setqinfo (read-line fd))
             (setq Pdata
                        (cons (read (strcat "(" (vl-string-translate
                                                ","" " info)
                                          ")"))
                              Pdata))
             )
               (close fd)
(command "_.zoom" "w" (_HiLow 'min 'min Pdata)(_HiLow 'max 'max Pdata))
....... <the rest of your code> .........

 
其中,Pdata是从外部文件导出的点列表
((200 300 13.5) (300 500 14.6) (500 100 17.1) (800 1000 19.9))
 
你可以在列表外进行操作
 
(foreach item Pdata (do this..))
 
先试试看,如果遇到困难,请尽管问
 
编辑:不过,你可以在插入块时缩小收集点列表,这将减少处理时间,但我想只是一点点

aaryan 发表于 2022-7-6 08:19:17

谢谢。。明天我的办公时间结束了,我会试试看,让你知道它是怎么工作的。。。
再次感谢,祝你今天愉快。。

aaryan 发表于 2022-7-6 08:25:07

我很困惑。。请调查一下。
这是我正在使用的实际代码,未能在适当的位置插入您的代码。请帮我个忙。
 
(defun c:Bathy (/ tpath fd info Soundings Bs Bsc BSL data ipt ba tpt x y xs ys)
(defun *error* (msg)
(if msg (princ (strcat "\nError! " msg)))
(princ)
)
;//pBe
(defun _roundTruncated(a)
   (setq b (fix a)
         c (* (abs (- a b)) 10))
    (if (= c 0)
      (setq d 0)
         (setq d (fix (+ c (/ c (abs c) 2.0))))))
;//

;//pBe
(defun _HiLow(lev lev2 lst)
   (list
         (apply lev (mapcar 'car lst))
         (apply lev2 (mapcar 'cadr lst))
         ))
;//

(setq tpath (getfiled "Select XYZ File" "*.*" "" 4))
   (setvar "cmdecho" 0)
   (setvar "osmode" 0)
   (graphscr)
   (setq fd   (open tpath "r")
info (read-line fd)
   )
   (if        (/= info nil)
   (progn
(if (setq Soundings (getfiled "Select Sounding Block" "*.*" "dwg" 4))
(progn
(setq Bs (Getreal "\nScale factor for Bathymetry Block <1>:"))
(if (= Bs Nil)
(setq Bsc 1)
(setq Bsc Bs)
))(exit))
   )
   (progn (alert "Bathy file is empty") (exit))
   )
   (setq Bsl (rtos Bsc 2 3))
   (while (/= info nil)
   (setq data (read (strcat "(" (vl-string-translate "," " " info) ")"))
         ipt (list (car data)(cadr data))
         bat (atof (rtos (caddr data) 2 4))
    tpt data)
   (if (< bat 0)
(progn
   (setq ba (* -1 bat)
    x (fix ba)
         y (_roundTruncated bat))
   (if (= y 10)
(progn
(setq x (+ x 1)
      y 0))
(progn
(setq x x
      y y)))          
   (setq xs (strcat "%%U" (itoa x))
    ys (itoa y))
   (command "insert" Soundings ipt Bsl Bsl 0 xs ys)
   (setq info (read-line fd)))
       (progn
   (setq x(fix bat)
         y (_roundTruncated bat))
   (if (= y 10)
(progn
(setq x (+ x 1)
      y 0))
(progn
(setq x x
      y y)))   
   (setq xs        (itoa x)
    ys        (itoa y))      
   (command "insert" Soundings ipt Bsl Bsl 0 xs ys)
   (setq info (read-line fd))
   )))
   (close fd)
   (command "zoom" "e")
   (command "regen")
   (setvar "osmode" 31743)
   (*error* nil)
   (princ)
)
 
我应该在哪一行插入您给定的缩放窗口代码,我正在尝试,但失败了。

pBe 发表于 2022-7-6 08:26:47

 
请原谅代码的粗糙性,我保留了你的大部分代码,否则它将是一个完整的重新编写,你真的不希望这样。原始代码越多,您就越容易理解。
 
(defun c:Bathy (/ tpath fd info Soundings Bs Bsc BSL Pdata data ipt ba tpt x y xs ys)
(vl-load-com)
(defun *error*(msg)
   (if msg
         (princ (strcat "\nError! " msg)))
   (princ)
   )
;//pBe
(defun _roundTruncated(a)
   (setq b (fix a)
         c (* (abs (- a b)) 10))
    (if (= c 0)
      (setq d 0)
         (setq d (fix (+ c (/ c (abs c) 2.0))))))
(defun _HiLow(lev lev2 lst)
   (list
         (apply lev (mapcar 'car lst))
         (apply lev2 (mapcar 'cadr lst))
         ))   
   ;//
(defun _errormsg ( lst / x )
(if (setq x (vl-some '(lambda ( x ) (if (null (eval (car x))) (cadr x))) lst))
(alert x)
)
)

(setvar "cmdecho" 0)
   (graphscr)
(if (and
(setq Pdata nil tpath (getfiled "Select XYZ File" "*.*" "txt" 4))
       (setq fsz (> (vl-file-size tpath) 0))
(setq Soundings (getfiled "Select Sounding Block" "*.*" "dwg" 4))
       (progn
             (setq Bs (Getreal "\nScale factor for Bathymetry Block <1>:"))
      (if (= Bs Nil) (setq Bsc 1) (setq Bsc Bs)))
)
(progn
      (setq fd   (open tpath "r"))
      (setq Bsl (rtos Bsc 2 3))
      (while(setqinfo (read-line fd))
            (setq Pdata
                         (cons (read (strcat "(" (vl-string-translate
                                                   ","" " info)
                                             ")"))
                               Pdata))
            )
   (close fd)
               (command "_.zoom" "w" (_HiLow 'min 'min Pdata)(_HiLow 'max 'max Pdata))
       (foreach data Pdata
(setq ipt (list (car data) (cadr data))
      bat (atof (rtos (caddr data) 2 4))
      tpt data)
(if (< bat 0)
      (progn
            (setq ba (* -1 bat)
                  x(fix ba)
                  y(_roundTruncated bat))
            (if (= y 10)
                  (progn
                        (setq x (+ x 1)
                              y 0))
                  (progn
                        (setq x x
                              y y)))
            (setq xs (strcat "%%U" (itoa x))
                  ys (itoa y))
                           )
      (progn
            (setq x (fix bat)
                  y (_roundTruncated bat))
            (if (= y 10)
                  (progn
                        (setq x (+ x 1)
                              y 0))
                  (progn
                        (setq x x
                              y y)))
            (setq xs (itoa x)
                  ys (itoa y))
                            ))
(command "insert" Soundings "_scale" Bsl "_non" ipt 0 xs ys)
            (runtime "....            Creating Soundings")
            )
;(command "zoom" "e")
(command "regen")
             )
   (_errormsg
'(
    (tpath "Failed to select Data File")
    (fsz "Bathy file is empty")
    (Soundings "Failed to select Block")
)
)
   )
(*error* nil)
   (princ)
)
 
什么是(运行时…)作用
 
要考虑的系统变量:
Attreq公司
丁津
 
我建议您研究错误处理
Lee Mac的错误处理
 
HTH公司

aaryan 发表于 2022-7-6 08:33:24

谢谢你,
感谢您维护我的代码并将其更正到最后。
作为一个新手,如果你重写代码,我将无法理解你的代码。我对这个线程的最后一个要求是,请给我推荐一些好的VISUAL LISP教程
我从Jeffery P Sanders网站上学到的是一个很好的教程,适用于autolisp初学者,但适用于Visual Lisp?。。
顺便说一句,我的同事以前使用的runtme函数在导入块时会像连续的点一样出现,所以我删除了它,这样如果任何新手想要使用这个例程,他就不会感到困惑。
谢谢和问候
Aaryan公司
页: [1] 2
查看完整版本: 错误的参数值:不是f