明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: liminnet

向版主请教,怎么样建立一个TXT文件,让lsp去读它的值才能用,谢谢

  [复制链接]
发表于 2008-6-17 13:31 | 显示全部楼层

;;给你一个子程序,以表的形式返回文件的全部内容

;;例如d盘存在 abc.txt  则调用 (ffile "abc.txt") 

(defun ffile(f / f_dat txt_row)
 (setq ccdate '()
       f_dat (open (strcat "d:/" f) "r"))
    (while (setq txt_row (read-line f_dat))
    (setq ccdate (cons txt_row ccdate))
  ) (close f_dat) (reverse ccdate)
)

 楼主| 发表于 2008-6-17 13:34 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2008-6-17 13:39 | 显示全部楼层
本帖最后由 作者 于 2008-6-17 13:41:53 编辑

只需要将二楼的写成函数就可以了
  1. (defun read_txtfile (txtfile / line lst)  ;;定义函数,语法(read_text <TXT文件名>)
  2.   (if (and (setq txtfile (findfile txtfile)) ;;判断文件存在
  3.            (not (vl-file-directory-p txtfile))  ;;确保文件名不是文件夹
  4.            (setq txtfile (open txtfile "r"))    ;;打开
  5.       )
  6.     (progn
  7.       (while (setq line (read_line txtfile)) ;;循环读取文件每一行
  8.       ;;(if ...     ;;此处可以添加验证该行的内容是否正确
  9.         (setq lst (cons line txtfile))  ;;将该行内容储存到表
  10.       ;;)
  11.       )
  12.       (close txtfile)    ;;关闭
  13.       (reverse lst)    ;;返回TXT文件内容
  14.     )
  15.   )
  16. )
  17. ;;-------------------------------------------------------------------------------------------
  18. ;; test
  19. (read_txtfile "C:\\TEST.TXT")
发表于 2008-6-17 13:46 | 显示全部楼层
个人认为这样加密没有什么意义。
  1. (defun c:xxxx (/ fl line)
  2. (setq fl (open "filename" "r")) ;打开文件
  3. (setq line (read-line fl)) ;读取文件的一行
  4. (close fl) ;关闭文件
  5. (if (/= line "password")
  6.   (exit)
  7. ) ;_ End if
  8. ………………程序正文
  9. ) ;_ End defun
  1. (defun c:xxxx (/ fl line)
  2. (setq fl (open "filename" "r")) ;打开文件
  3. (setq line (read-line fl)) ;读取文件的一行
  4. (close fl) ;关闭文件
  5. (if (/= line "password")
  6.   (exit)
  7. ) ;_ End if
  8. ………………程序正文
  9. ) ;_ End defun

 楼主| 发表于 2008-6-17 14:02 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2008-6-17 14:06 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2008-6-17 14:35 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2008-6-17 15:10 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2008-6-17 16:25 | 显示全部楼层
(defun c:ppp( / a aa f line)
(if (findfile "key.txt") 
  (progn
    (setq f (open (findfile "key.txt") "r"))   
    (setq line (read-line f))   
    (close f)
    (if (=  "888888" line)
      (progn
        (setq aa (ssget))
        (setq a (getvar "clayer"))
        (command "chprop" aa "" "la" a "")
      )
      (alert "未授权,请联系作者!")
    )
  )

(print)     
)
 楼主| 发表于 2008-6-17 16:37 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-17 13:06 , Processed in 0.198216 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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