ZZXXQQ 发表于 2007-11-20 21:05:00

<p>1、将程序放入ACAD.LSP或ACAD.MNL中,函数名写成S::STARTUP就可以自动运行了。</p><p>2、将要执行的程序加入启动组,程序名同上。</p>

zhongzilei 发表于 2007-11-20 23:36:00

本帖最后由 作者 于 2007-11-20 23:38:32 编辑

谢谢版主的解答。不过这个程序,是我跟我以前的同事要的,现在失去联系了。我试了多次不能成功,请版主把这个程序改好发上来好吗?

ZZXXQQ 发表于 2007-11-21 08:25:00

程序写得太繁琐。改了改,未调试。将程序写入ACAD.LSP或其它文件名加入启动组即可。

(defun s::startup () (cxy:layerset-add "zongtu"))
(defun cxy:layerset-add (listname / file fname line)
(cxy:StartSet)
(cxy:Set_Var "CLAYER" (getvar "CLAYER"))
(if (setq fname (findfile (cxy:path (strcat "layers/" listname ".lsp")))) (progn
(setq file (open fname "r"))
(repeat 3 (read-line file)) ;空读三行
(while (setq line (read-line file))
    (if (read line) (cxy:layer-new (read line)))
)
(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))
)
)

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

zhongzilei 发表于 2007-11-21 21:37:00

谢谢版主,试了,不能运行成功,版主能不能改成通用的,如把主程序放在指定目录加载,然后加载<font color="#ff00ff">zongtu.lsp程序,只要运行</font><font color="#ff0000">(</font>cxy:layerset-add <font color="#ff00ff">"zongtu"</font><font color="#ff0000">),就能生成所设置的图层</font>

lixiang_sh 发表于 2007-11-22 21:18:00

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

zhongzilei 发表于 2007-11-23 20:09:00

支持版主能够费心优化一下

lixiang_sh 发表于 2007-11-26 22:03:00

<p>等待中</p>

zhongzilei 发表于 2007-11-27 14:21:00

<p>再顶一下,顶出高手</p>

lixiang_sh 发表于 2007-11-27 18:34:00

<p>再顶一下,顶出高手</p>

ZZXXQQ 发表于 2007-11-28 11:53:00

本帖最后由 作者 于 2007-11-28 12:25:48 编辑

下面是简单的,只有一个函数。


(defun cxy:layerset-add (listname / fname f dl)
(setvar "CMDECHO" 0)
(setq oldla (getvar "CLAYER"))
(if (setq fname (findfile (strcat "layers/" listname ".lsp"))) (progn
(setq f (open fname "r"))
(command ".undo" "BE")
(repeat 3 (read-line f)) ;空读三行
(while (setq dl (read-line f))
   (if (setq dl (read dl)) (progn
    (setq name (nth 0 dl))
    (setq color (nth 1 dl))
    (setq lineT (nth 2 dl))
    (setq lineW (nth 3 dl))
    (setq plot (nth 4 dl))
    (setq pstyl (nth 5 dl))
(if (/= lineT "continuous") (progn
(command "-linetype" "l" lineT "acad" "")
(WHILE (NOT (ZEROP (GETVAR "CMDACTIVE"))) (COMMAND ""))
))
    (command "_-LAYER" "M" name "C" color "" "L" lineT "" "LW" lineW "" "P" plot "" "")
   ))
)
(COMMAND ".UNDO" "E")
(close f)
))
(setvar "CLAYER" oldla)
(setvar "CMDECHO" 1)
(princ)
)

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

页: 1 [2] 3 4
查看完整版本: [求助]一个很好的生成图层的lisp,有问题,如何修改