明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: zhongzilei

[求助]一个很好的生成图层的lisp,有问题,如何修改

  [复制链接]
发表于 2007-11-20 21:05:00 | 显示全部楼层

1、将程序放入ACAD.LSP或ACAD.MNL中,函数名写成S::STARTUP就可以自动运行了。

2、将要执行的程序加入启动组,程序名同上。

 楼主| 发表于 2007-11-20 23:36:00 | 显示全部楼层
本帖最后由 作者 于 2007-11-20 23:38:32 编辑

谢谢版主的解答。不过这个程序,是我跟我以前的同事要的,现在失去联系了。我试了多次不能成功,请版主把这个程序改好发上来好吗?
发表于 2007-11-21 08:25:00 | 显示全部楼层
程序写得太繁琐。改了改,未调试。将程序写入ACAD.LSP或其它文件名加入启动组即可。
  1. (defun s::startup () (cxy:layerset-add "zongtu"))
  2. (defun cxy:layerset-add (listname / file fname line)
  3.   (cxy:StartSet)
  4.   (cxy:Set_Var "CLAYER" (getvar "CLAYER"))
  5.   (if (setq fname (findfile (cxy:path (strcat "layers/" listname ".lsp")))) (progn
  6.   (setq file (open fname "r"))
  7.   (repeat 3 (read-line file)) ;空读三行
  8.   (while (setq line (read-line file))
  9.     (if (read line) (cxy:layer-new (read line)))
  10.   )
  11.   (close file)
  12.   (cxy:ExitSet)
  13.   (princ)
  14. )
  15. (defun cxy:StartSet ()
  16. (if (= *cxy-RESET* nil) (progn
  17.   (setq *cxy-RESET*  T *cxy-OLDERR* *ERROR*
  18.         *ERROR*      cxy:SetErrorHandler
  19.         *cxy-UNDO*   (getvar "UNDOCTL"))
  20.   (cxy:Set_Var "CMDECHO" 0)
  21.   (cond
  22.    ((= *cxy-UNDO* 0) (command "_.UNDO" "ALL"))
  23.    ((= *cxy-UNDO* 3) (command "_.UNDO" "C" "ALL"))
  24.   )
  25.   (command "_.UNDO" "G")
  26. ))
  27. )
  28. (defun cxy:path (subdir / sub ddc)
  29. (setq sub (vl-string-left-trim "\\/" subdir))
  30. (setq ddc (vl-string-right-trim "\\/" (getenv "DDCPATH")))
  31. (setq str (strcat ddc "/" sub))
  32. str
  33. )
  34. (defun cxy:layer-new (lyrprops / name color lineT lineW plot pstyl)
  35. (setq name (nth 0 lyrprops))
  36. (setq color (nth 1 lyrprops))
  37. (setq lineT (nth 2 lyrprops))
  38. (setq lineW (nth 3 lyrprops))
  39. (setq plot (nth 4 lyrprops))
  40. (setq pstyl (nth 5 lyrprops))
  41. (defun tmp ()
  42.   (command "_-LAYER" "M" name"C" color "" "L" lineT "" "LW" lineW  "" "P" plot "" "")
  43. )
  44. (if (= (tblsearch "layer" name) nil)
  45.   (tmp)
  46. (progn
  47.   (cxy:layerstate-tempsave name)
  48.   (tmp)
  49.   (cxy:layerstate-temprestore name)
  50. ))
  51. (princ)
  52. )
  53. (defun cxy:ExitSet ()
  54. (command "_.UNDO" "E")
  55. (repeat (length *cxy-VARLIST*)
  56.   (setvar (caar *cxy-VARLIST*) (cadar *cxy-VARLIST*))
  57.   (setq *cxy-VARLIST* (cdr *cxy-VARLIST*))
  58. )
  59. (setq *ERROR* *cxy-OLDERR*  *cxy-RESET* nil)
  60. (command nil nil)
  61. (princ)
  62. )
  63. (defun cxy:SetErrorHandler (msg)
  64. (if (/= msg "Function cancelled") (princ msg))
  65. (command nil nil)
  66. (command "_.UNDO" "e")
  67. (if *cxy-RESET* (command "_.UNDO" 1))
  68. (cxy:ExitSet)
  69. )
  70. (defun cxy:Set_Var (var val)
  71. (if (not (assoc var *cxy-VARLIST*))
  72.   (setq *cxy-VARLIST* (cons (list var (getvar var)) *cxy-VARLIST*))
  73. )
  74. (setvar var val)
  75. )
  76. (defun cxy:layerstate-tempsave (lname / e1)
  77. (setq e1 (entget (tblobjname "layer" lname)))
  78. (setq USER1 (cdr (assoc 70 e1)))
  79. (setq USER2 (cdr (assoc 62 e1)))
  80. (setq e1 (subst (cons 70 0) (assoc 70 e1) e1))
  81. (entmod e1)
  82. )
  83. (defun cxy:layerstate-temprestore (lname / e1)
  84. (setq e1 (entget (tblobjname "layer" lname)))
  85. (setq e1 (subst (cons 70 USER1) (assoc 70 e1) e1))
  86. (if (/= (minusp USER2) nil) (progn
  87.   (setq USER2 (* -1 LYRCOLOR))
  88.   (setq e1 (subst (cons 62 USER2) (assoc 62 e1) e1))
  89. ))
  90. (entmod e1)
  91. )
  92. (defun cxy:path-slashes (str / new)
  93. (setq new str)
  94. (while (/= (vl-string-search "\" new) nil)
  95.   (setq new (vl-string-subst "/" "\" new))
  96. )
  97. )
  1. ;_________________总图________________________
  2. ;("name" color lineT lineW plot "pstyl")
  3. ()
  4. ("Y_用地红线" 1   "dash" 0.25 "p" "Normal");用地红线
  5. ("Z_周边建筑" 4   "continuous" 0 "p" "Normal");周边建筑
  6. ("W_文字" 30   "continuous" 0 "p" "Normal");文字说明
  7. ("W_围墙" 9   "continuous" 0 "p" "Normal");围墙
  8. ("D_地下建筑" 11   "continuous" 0 "p" "Normal");地下建筑
  9. ("F_分期建筑线" 60   "continuous" 0 "p" "Normal");分期线
  10. ("Z_坐标点" 11   "continuous" 0 "p" "Normal");坐标标注
  11. ("T_退红线" 30   "dash" 0 "p" "Normal");建筑退红线
  12. ("F_附注说明" 7   "continuous" 0.15 "p" "Normal");平立面图中的附注说明
  13. ("C_参考网格" 253   "continuous" 0.15 "p" "Normal");参考网格
  14. ("C_城市道路" 5   "continuous" 0.15 "p" "Normal");城市道路
  15. ("Q_区内道路" 7   "continuous" 0.15 "p" "Normal");区内道路
  16. ("Y_院内道路" 115   "continuous" 0.15 "p" "Normal")
  17. ("R_人行道"   2   "continuous" 0.15 "p" "Normal")
  18. ("D_道路红线" 1   "continuous" 0.15 "p" "Normal")
  19. ("D_道路中心线" 40   "center2" 0.15 "p" "Normal")
  20. ("T_停车位(场)"   93   "continuous" 0.15 "p" "Normal")
  21. ("X_现状住宅" 253   "continuous" 0.25 "p" "Normal")
  22. ("G_规划住宅" 2   "continuous" 0.5 "p" "Normal")
  23. ("G_规划公建" 30   "continuous" 0.5 "p" "Normal")
  24. ("G_规划商业" 210   "continuous" 0.5 "p" "Normal")
  25. ("S_水系" 4   "continuous" 0.15 "p" "Normal")
  26. ("C_城市行道树" 82   "continuous" 0.15 "p" "Normal")
  27. ("Q_区内行道树" 3   "continuous" 0.15 "p" "Normal")
  28. ("Q_区内景观树" 213   "continuous" 0.15 "p" "Normal")
  29. ("T_填充层" 8   "continuous" 0.15 "p" "Normal")
复制代码
 楼主| 发表于 2007-11-21 21:37:00 | 显示全部楼层
谢谢版主,试了,不能运行成功,版主能不能改成通用的,如把主程序放在指定目录加载,然后加载zongtu.lsp程序,只要运行(cxy:layerset-add "zongtu"),就能生成所设置的图层
发表于 2007-11-22 21:18:00 | 显示全部楼层

建议继续优化,对图层标准话很有意义!!!!

 楼主| 发表于 2007-11-23 20:09:00 | 显示全部楼层
支持版主能够费心优化一下
发表于 2007-11-26 22:03:00 | 显示全部楼层

等待中

 楼主| 发表于 2007-11-27 14:21:00 | 显示全部楼层

再顶一下,顶出高手

发表于 2007-11-27 18:34:00 | 显示全部楼层

再顶一下,顶出高手

发表于 2007-11-28 11:53:00 | 显示全部楼层
本帖最后由 作者 于 2007-11-28 12:25:48 编辑

下面是简单的,只有一个函数。
游客,本帖隐藏的内容需要发帖数高于 5 才可浏览,你当前发帖数只有 0

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

本版积分规则

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

GMT+8, 2025-5-23 20:06 , Processed in 0.296193 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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