明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1349|回复: 7

[LISP]帮帮忙改一下吧!!!!

[复制链接]
发表于 2005-11-14 11:21 | 显示全部楼层 |阅读模式

这是一个别人的程序,恳请高手们在这个程序的基础上更改一下吧,就是在输入坐标的顺序上变化一下,由X、Y、H输入顺序变化为Y、X、H

谢谢大家了!!!!!

发表于 2005-11-14 11:32 | 显示全部楼层
程序在哪里
 楼主| 发表于 2005-11-14 13:46 | 显示全部楼层

不好意思。刚才忘发了。

这是程序:

(defun c:lx (/ ptlst idx OS_old)

  (setq ptlst (getdata))

  (setq OS_old (getvar "OSMODE"))

  (setvar "OSMODE" 0)

  (command "pline")

  (while (/= 0 (setq idx (getint "\n请输入点号<0 to exit>: ")))

  (command (cdr (assoc idx ptlst)))

    );while

  (command "")

  (setvar "OSMODE" OS_old)

  (princ)

)

(defun Getdata (/ f line rtnlst)

  (setq f (open "d:\\ "*.txt" "r"))

  (while (setq line (read-line f))

    (setq rtnlst (cons (mapcar 'read (string_to_numbers line)) rtnlst))

  )

  (close f)

  (reverse rtnlst)

)

;; By Bill Kramer

; ------------------------------------------------------ Listing 4.4

;

(defun String_To_Numbers (

     inStr  ;;Input string

     /

     Res    ;;Result list

     Buf    ;;String buffer

     Inx      ;;Character location

     CH     ;;Character

     )

  (setq Inx 1 ;start at the beginning of the string

 Buf "" ;init buffer to empty

 )

  ;

  ; Loop until the end of the string.

  ; (I indicates where we are in the string)

  ;

  (while (<= Inx (strlen inStr))

    ;

    ; Get the character at position Inx, increment position indicator

    (setq CH (substr inStr Inx 1)

   Inx (1+ Inx)

   )

    ;

    (cond

      ; Test to see if character is a digit.

      ((wcmatch CH "[0-9.]")

        (if (= CH ".") ;is it decimal?

   (if (not (wcmatch Buf "*`.*")) ;not already in there

     (setq Buf (strcat Buf CH))

     (Flush_Buf))

   ;

          (setq Buf (strcat Buf CH)))

      )

      ((= Buf "") ;is the buffer empty?

        ;Is CH minus

 (if (= CH "-")

   (setq Buf CH) ;Yes, save in Buf

 )

      )

      ('T ;else buffer is not empty

        (Flush_Buf)

        (if (= CH "-")

   (setq Buf CH))

      )

    ); End of COND

  ); End of WHILE

  ;

  (if (and (/= Buf "")

    (not (wcmatch Buf "[+-.]"))

    )

    (Flush_Buf))

  (reverse Res)

)

;

; ------------------------------------------------------ Listing 4.5

;

(defun Flush_Buf ()

  (if (not (wcmatch Buf "[+-.]")) ;is it not just +-.?

    (progn

      ;Clean it up first

      (if (= (substr Buf 1 1) ".")

 (setq Buf (strcat "0" Buf))) ;;add zero to front if .#

      (if (= (substr Buf (strlen Buf)) ".")

 (setq Buf (substr Buf 1 (1- (strlen Buf))))) ;;remove decimal if #.

      ;Add to RES list

      (setq RES (cons Buf RES))))

  (setq Buf "") ;;reset Buf

)

 

 

 楼主| 发表于 2005-11-14 19:19 | 显示全部楼层

恳请大家帮我一下吧!!!!

谢谢了!!!!!

发表于 2005-11-14 20:16 | 显示全部楼层

;将(getdata)函数改为如下即可

(defun Getdata (/ f line rtnlst)
  ;(setq f (open "d:\\  "*.txt" "r"));注意:该行掉了一后引号
  (setq f (open "d:\\" "*.txt" "r"))
  (while (setq line (read-line f))
    (setq rtnlst (cons (mapcar 'read (string_to_numbers line)) rtnlst))
  )
  (close f)
  (reverse rtnlst)
 

  ;增加部分
  (foreach f rtnlst
     (setq rtnlst (subst (cons (car f) (cons (caddr f) (cons (cadr f) (cdddr f))))
                                  f
                                rtnlst
                         )         
     )
  )
)

 楼主| 发表于 2005-11-15 09:30 | 显示全部楼层

还是不行,更改后的程序如下:

(defun c:lx (/ ptlst idx OS_old)

  (setq ptlst (getdata))

  (setq OS_old (getvar "OSMODE"))

  (setvar "OSMODE" 0)

  (command "pline")

  (while (/= 0 (setq idx (getint "\n请输入点号<0 to exit>: ")))

  (command (cdr (assoc idx ptlst)))

    );while

  (command "")

  (setvar "OSMODE" OS_old)

  (princ)

)

(defun Getdata (/ f line rtnlst)
  ;(setq f (open "d:\\  "iicc.txt" "r"));注意:该行掉了一后引号
  (setq f (open "d:\\" "iicc.txt" "r"))
  (while (setq line (read-line f))
    (setq rtnlst (cons (mapcar 'read (string_to_numbers line)) rtnlst))
  )
  (close f)
  (reverse rtnlst)
 

  ;增加部分
  (foreach f rtnlst
     (setq rtnlst (subst (cons (car f) (cons (caddr f) (cons (cadr f) (cdddr f))))
                                  f
                                rtnlst
                         )         
     )
  )
)

;; By Bill Kramer

; ------------------------------------------------------ Listing 4.4

;

(defun String_To_Numbers (

     inStr  ;;Input string

     /

     Res    ;;Result list

     Buf    ;;String buffer

     Inx      ;;Character location

     CH     ;;Character

     )

  (setq Inx 1 ;start at the beginning of the string

 Buf "" ;init buffer to empty

 )

  ;

  ; Loop until the end of the string.

  ; (I indicates where we are in the string)

  ;

  (while (<= Inx (strlen inStr))

    ;

    ; Get the character at position Inx, increment position indicator

    (setq CH (substr inStr Inx 1)

   Inx (1+ Inx)

   )

    ;

    (cond

      ; Test to see if character is a digit.

      ((wcmatch CH "[0-9.]")

        (if (= CH ".") ;is it decimal?

   (if (not (wcmatch Buf "*`.*")) ;not already in there

     (setq Buf (strcat Buf CH))

     (Flush_Buf))

   ;

          (setq Buf (strcat Buf CH)))

      )

      ((= Buf "") ;is the buffer empty?

        ;Is CH minus

 (if (= CH "-")

   (setq Buf CH) ;Yes, save in Buf

 )

      )

      ('T ;else buffer is not empty

        (Flush_Buf)

        (if (= CH "-")

   (setq Buf CH))

      )

    ); End of COND

  ); End of WHILE

  ;

  (if (and (/= Buf "")

    (not (wcmatch Buf "[+-.]"))

    )

    (Flush_Buf))

  (reverse Res)

)

;

; ------------------------------------------------------ Listing 4.5

;

(defun Flush_Buf ()

  (if (not (wcmatch Buf "[+-.]")) ;is it not just +-.?

    (progn

      ;Clean it up first

      (if (= (substr Buf 1 1) ".")

 (setq Buf (strcat "0" Buf))) ;;add zero to front if .#

      (if (= (substr Buf (strlen Buf)) ".")

 (setq Buf (substr Buf 1 (1- (strlen Buf))))) ;;remove decimal if #.

      ;Add to RES list

      (setq RES (cons Buf RES))))

  (setq Buf "") ;;reset Buf

)

 

 运行时出现一下情况:

命令:lx

;错误:参数太多

 

 

请大侠们明示!!!!!

 

 

 

 

 

 

 

 楼主| 发表于 2005-11-15 09:49 | 显示全部楼层

问题已经解决了,

谢谢您了!!!!

发表于 2005-11-19 21:30 | 显示全部楼层

怎么解决的,说下吧

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-18 07:04 , Processed in 0.176815 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表