明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 8130|回复: 30

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

  [复制链接]
发表于 2007-11-5 20:36:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2007-11-20 1:25:14 编辑

,能一次生成 "图名" 颜色 线型 线宽 是否 打印 打印样式等图层特性,以前一个同事给的

下面是主程序layers.lsp

;;(cxy:layerset-add "zongtu")
(defun cxy:layerset-add (listname / file line lyrproperties)
  (cxy:StartSet)
  (cxy:Set_Var "CLAYER" (getvar "CLAYER"))
  (setq file
  (open (cxy:path (strcat "layers/" listname ".lsp")) "r")
  )
  (read-line file)
  (while (setq line (read-line file))
    (setq lyrproperties (read line))
    (if (/= lyrproperties nil)
      (cxy:layer-new lyrproperties)
    )
  )
  (close file)

  (cxy:ExitSet)

  (princ)
)
(defun cxy:StartSet ()

  (if (= *cxy-RESET* nil)
    (progn
      (setq
 *cxy-RESET*  T
 *cxy-OLDERR* *ERROR*
 *ERROR*      cxy:SetErrorHandler
 *cxy-UNDO*   (getvar "UNDOCTL")
      )
      (cxy:Set_Var "CMDECHO" 0)
      (cond
 ((= *cxy-UNDO* 0)
  (command "_.UNDO" "ALL")
 )
 ((= *cxy-UNDO* 3)
  (command "_.UNDO" "C" "ALL")
 )
      )
      (command "_.UNDO" "G")
    )
  )
)
(defun cxy:path (subdir / sub ddc)
  (setq sub (vl-string-left-trim "\\/" subdir))
  (setq ddc (vl-string-right-trim "\\/" (getenv "DDCPATH")))
  (setq str (strcat ddc "/" sub))
  str
)
(defun cxy:layer-new (lyrprops / name color lineT lineW plot pstyl)
  (setq name (nth 0 lyrprops))
  (setq color (nth 1 lyrprops))
  (setq lineT (nth 2 lyrprops))
  (setq lineW (nth 3 lyrprops))
  (setq plot (nth 4 lyrprops))
  (setq pstyl (nth 5 lyrprops))
  (defun tmp ()
    (command "_-LAYER"    "M"   name  "C" color  ""     "L"
      lineT  ""    "LW"   lineW  "" "P"    plot   ""
      ""
     )
  )
  (if (= (tblsearch "layer" name) nil)
    (tmp)

    (progn
      (cxy:layerstate-tempsave name)
      (tmp)
      (cxy:layerstate-temprestore name)
    )
  )
  (princ)
)
(defun cxy:ExitSet ()
  (command "_.UNDO" "E")
  (repeat
    (length *cxy-VARLIST*)
     (setvar (caar *cxy-VARLIST*) (cadar *cxy-VARLIST*))
     (setq *cxy-VARLIST* (cdr *cxy-VARLIST*))
  )
  (setq
    *ERROR* *cxy-OLDERR*

    *cxy-RESET* nil
  )
  (command nil nil)
  (princ)
)
(defun cxy:SetErrorHandler (msg)
  (if (/= msg "Function cancelled")
    (princ msg)
  )
  (command nil nil)
  (command "_.UNDO" "e")
  (if *cxy-RESET*
    (command "_.UNDO" 1)
  )
  (cxy:ExitSet)
)
(defun cxy:Set_Var (var val)

  (if (not (assoc var *cxy-VARLIST*))
    (setq *cxy-VARLIST* (cons (list var (getvar var)) *cxy-VARLIST*))
  )

  (setvar var val)
)
(defun cxy:layerstate-tempsave (lname / e1)

  (setq e1 (entget (tblobjname "layer" lname)))

  (setq USER1 (cdr (assoc 70 e1)))

  (setq USER2 (cdr (assoc 62 e1)))
  (setq e1
  (subst (cons 70 0)
  (assoc 70 e1)
  e1
  )
  )
  (entmod e1)
)

(defun cxy:layerstate-temprestore (lname / e1)

  (setq e1 (entget (tblobjname "layer" lname)))
  (setq e1
  (subst (cons 70 USER1)
  (assoc 70 e1)
  e1
  )
  )
  (if (/= (minusp USER2) nil)
    (progn
      (setq USER2 (* -1 LYRCOLOR))
      (setq e1
      (subst (cons 62 USER2)
      (assoc 62 e1)
      e1
      )
      )
    )
  )
  (entmod e1)
)
(defun cxy:path-slashes (str / new)
  (setq new str)
  (while (/= (vl-string-search "\\" new) nil)
    (setq new (vl-string-subst "/" "\\" new))
  )
)

"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2007-11-5 20:38:00 | 显示全部楼层

这是我的总图图层设置,zongtu.lsp,使用时建立一个layers的文件夹,然后zongtu.lsp放入其中,

依次是"图名" 颜色 线型 线宽 是否 打印 打印样式,同时加载zongtu.lsp和layers.lsp

在命令行输入(cxy:layerset-add "zongtu")就会生成下面设置的图层,当然你可以做成下拉菜单,就方便多了,例如:

[平立剖面]^c^c^p(cxy:layerset-add "pinglipou")^p;
                   [门窗表]^c^c^p(cxy:layerset-add "menchuangbiao")^p;
                   [详图]^c^c^p(cxy:layerset-add "xiangtu")^p;
                   [说明目录]^c^c^p(cxy:layerset-add "shuomingmulu")^p;
                   [总图]^c^c^p(cxy:layerset-add "zongtu")^p;

;_________________总图________________________
;("name" color lineT lineW plot "pstyl")
()
("Y_用地红线" 1   "dash" 0.25 "p" "Normal");用地红线
("Z_周边建筑" 4   "continuous" 0 "p" "Normal");周边建筑
("W_文字" 30   "continuous" 0 "p" "Normal");文字说明
("W_围墙" 9   "continuous" 0 "p" "Normal");围墙
("D_地下建筑" 11   "continuous" 0 "p" "Normal");地下建筑
("F_分期建筑线" 60   "continuous" 0 "p" "Normal");分期线
("Z_坐标点" 11   "continuous" 0 "p" "Normal");坐标标注
("T_退红线" 30   "dash" 0 "p" "Normal");建筑退红线
("F_附注说明" 7   "continuous" 0.15 "p" "Normal");平立面图中的附注说明
("C_参考网格" 253   "continuous" 0.15 "p" "Normal");参考网格
("C_城市道路" 5   "continuous" 0.15 "p" "Normal");城市道路
("Q_区内道路" 7   "continuous" 0.15 "p" "Normal");区内道路
("Y_院内道路" 115   "continuous" 0.15 "p" "Normal")
("R_人行道"   2   "continuous" 0.15 "p" "Normal")
("D_道路红线" 1   "continuous" 0.15 "p" "Normal")
("D_道路中心线" 40   "center2" 0.15 "p" "Normal")
("T_停车位(场)"   93   "continuous" 0.15 "p" "Normal")
("X_现状住宅" 253   "continuous" 0.25 "p" "Normal")
("G_规划住宅" 2   "continuous" 0.5 "p" "Normal")
("G_规划公建" 30   "continuous" 0.5 "p" "Normal")
("G_规划商业" 210   "continuous" 0.5 "p" "Normal")
("S_水系" 4   "continuous" 0.15 "p" "Normal")
("C_城市行道树" 82   "continuous" 0.15 "p" "Normal")
("Q_区内行道树" 3   "continuous" 0.15 "p" "Normal")
("Q_区内景观树" 213   "continuous" 0.15 "p" "Normal")
("T_填充层" 8   "continuous" 0.15 "p" "Normal")

 楼主| 发表于 2007-11-5 20:39:00 | 显示全部楼层
不过有时会有问题,会出现大概意思,file错误的提示,有时没有问题,只能说不太完美。请懂lisp的高手看看吧,能不能完善的更好一些
发表于 2007-11-6 19:19:00 | 显示全部楼层
 楼主| 发表于 2007-11-8 07:00:00 | 显示全部楼层

是加载线型有问题,有没有愿意写一下这个问题

发表于 2007-11-9 16:33:00 | 显示全部楼层
很好很强大!
发表于 2007-11-10 09:39:00 | 显示全部楼层
可否在cad啟動時,不用輸命令,而自動加入圖層.
 楼主| 发表于 2007-11-20 01:26:00 | 显示全部楼层
看看哪位高手,能出手一下
发表于 2007-11-20 08:43:00 | 显示全部楼层
hjiea发表于2007-11-10 9:39:00可否在cad啟動時,不用輸命令,而自動加入圖層.

还要编程序吗?可以直接用模版文件。
 楼主| 发表于 2007-11-20 12:56:00 | 显示全部楼层
这样编程序时,可以把别人画的图改成我所习惯的图层,用程序可以随时生成我的图层,用模板就不太方便了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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