找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 894|回复: 0

[LISP程序]:一个一次生成 图名 颜色 线型 线宽 是否 打印 打印样式等图层特性的lisp

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

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
下面是主程序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))
  )
)

;;;;;;;;;;;;;;;
这是我的总图图层设置,zongtu.lsp

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

在命令行输入(cxy:layerset-add "zongtu")就会生成下面设置的图层

;_________________总图________________________
;("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")

不过有时会有问题,会出现大概意思,file错误的提示,有时没有问题,只能说不太完美。请懂lisp的高手们看看能不能把主程序再完善一下。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-21 15:36 , Processed in 0.298776 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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