明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1079|回复: 2

[已解答] 转换临时对话框中的字符处理

[复制链接]
发表于 2015-11-6 11:50:52 | 显示全部楼层 |阅读模式
本帖最后由 hbgsw 于 2015-11-6 11:53 编辑

问题点:每次生成临时DCL的时候,格式基本都是固定的,所以想弄个lisp,直接将做好的DCL转换为临时DCL,论坛找了一圈也没有找到合适的程序,
所以打算自己写个,但是到了laybel和key 后面的引号" "处卡住了,不知道如何判断填写 \ ,请各位高手支援下,谢谢!

DCL格式:
            label = "注册" ;
            key = "c03" ;

临时DCL格式:
(write-line "            label =\"注册\" ;" f)
(write-line "            key =\"c03\" ;" f)

子程序如下:
  1. (defun readfile (file / fn str txt )
  2.      ;路径文件名,结果返回为list ;(strcat txtdir "formset.txt")
  3.   (if (setq file (findfile file))
  4.     (progn
  5.       (setq fn (open file "r"))
  6.       (setq str nil)
  7.       (if (not (setq txt (read-line fn))) ;判断文件是否为空
  8. (progn (princ "\n 文件为空,readfile 文件失败") (exit))
  9.       )
  10.       (cond ((= (substr txt 1 1) ";") ;读取配置文件为表,
  11.       (while (setq txt (read-line fn))
  12.         (if (and (/= txt "")
  13.    (/= (substr txt 1 1) ";")
  14.    (setq txt (read txt))
  15.      )
  16.    (setq str (cons txt str))
  17.         )
  18.       )
  19.      )
  20.      ((= (substr txt 1 2) "/*") ;读取DCL文件,并转换为临时对话框格式,对话框采用飞诗格式,或第一行/* 格式固定。
  21.       (while (and (setq txt (read-line fn))
  22.     (/= txt "")
  23.       )
  24.         (setq txt (strcat "(write-line" "\"" txt "\"" " f)"))
  25.         (setq str (cons txt str))
  26.       )
  27.      )
  28.      (t
  29.       (alert "\n readfile 文件格式不正确")
  30.      )
  31.       )
  32.       (close fn)
  33.       (princ)
  34.       (setq str (reverse str))
  35.     )
  36.     (progn (princ "\n 文件不存在或文件错误,readfile读取文件失败")
  37.     (exit)
  38.     )
  39.   )
  40. )
  41. (if (not lj)
  42.   (setq lj "C:/Users/31000/Desktop/")
  43. )
  44. (setq txt (readfile (getfiled "选择DCL文件" lj "DCL" 2)))
  45. (setq fname (vl-filename-mktemp "temp.txt")
  46.       f     (open fname "w")
  47. )
  48. (foreach x txt
  49.   (write-line x f)
  50. )
  51. (close f)
  52. (startapp "notepad.exe" fname)
  53. (command "delay" 600)
  54. (princ)
  55. (vl-file-delete fname)

发表于 2015-11-6 13:23:41 | 显示全部楼层
(VL-PRIN1-TO-STRING str)
 楼主| 发表于 2015-11-6 14:01:37 | 显示全部楼层
Gu_xl 发表于 2015-11-6 13:23
(VL-PRIN1-TO-STRING str)

⊙﹏⊙b!
谢谢伟大的G版,一个函数就搞定了,让我等汗颜呐!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-21 06:19 , Processed in 0.163436 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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