CAD设计论坛

 找回密码
 立即注册
论坛新手常用操作帮助系统等待验证的用户请看获取社区币方法的说明新注册会员必读(必修)
查看: 1959|回复: 7

[求助] 自己加载的小程序为什么用不起?

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
9 w2 s' b- P, q5 N# I# t “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”2 q! W8 k' w- e
提示:加载成功
& L9 d/ c* V& T# r然后使用CLOUD命令,
/ Z. b7 }1 j* T* q& S4 d! L; U提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”" S0 V1 ~7 ^% z3 B8 C# _
请高手指点一下,这个是怎么回事?应该怎么改正?# z) X, M: T3 a( t' [8 R
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx* P5 p6 W4 h" E3 U1 ^) f; p+ M. W
;;;! n- U" e0 U0 T" t7 Z
;;;  DESCRIPTION
- G- O( ?8 i) I0 T4 ?) u7 {;;;     Draw cloud and you can specify the globals variables listed below
& `' y0 B* @- e3 D9 b0 R;;;     to decide the characters of cloud
8 `- ]1 ]5 k, p; B' x8 f" b;;;
8 p  D7 W- X4 t/ H; y" e3 b: Y;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
4 k1 a: Z+ N6 q1 q;;;/ ?" q  C( t6 C' x
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed/ e' A5 D/ U" `- ~( _, B6 _0 m' `
;;;           Change CLOUD.001 to use CLAYER to perform the same function5 a& T) [. k- ~; a& [
;;;           Use the common error routine UNDO.LSP to optimize this program, ~4 h( b* v2 M8 U  [, A0 w
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE! o; l7 a" p' j- @8 Z8 M5 Z
;----------------------------------------------------------------------------, d' `" _0 ?! m4 ~/ C( q
;  GLOBALS:+ W0 V( F. o. k% N# K7 t+ ^$ c
;     cloud_layer -- layer of cloud
- [7 e; T+ w/ T# o. };     cloud_scale -- scale of cloud
" |3 N1 t8 a. w5 p& _. u" B; c;     number_rev  -- revision number0 @' o& ^6 u! e% {. c
;----------------------------------------------------------------------------
" U/ f" E9 k8 Y( P(defun cloud (/ locked temp first_point next_point relative_point2 Y6 L/ `! x1 }' ?# }, L. V
               last_point point_tri point_ref corner_1st corner_2nd length_tri
) e# S6 G6 B+ y4 W* m               length_cloud angle_l_to_f dir_tri repeat_count 0 u1 a7 _) f: y% b% x7 D$ p
               table_cloud )
; T$ k- {+ Z  h# n        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))/ W: F% Q$ F6 @+ x$ }
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))+ y* G& a) }7 [" F2 @" y9 q
        );if& ~; R9 B! a0 ]4 g- N. S
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
4 i( ^* c9 p$ q' D, f" x                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))3 V# T$ z7 d1 e/ R. j
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)* @, V- x; S$ g8 n: a+ `
                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
) T5 i9 G7 @; V. U
7 @2 {& j3 @* S! |9 h; h        (if (not (numberp cloud_scale))
! R" y$ b( S! H! z            (setq cloud_scale (getvar "LTSCALE"))
9 J+ x3 `9 p6 \        ); if+ w6 N% S, s! y4 q
        (if (not cloud_layer)
' a' F8 e1 v& j            (setq cloud_layer (getvar "CLAYER"))
0 ^) J# c( n4 y" p# j3 C/ w  f' G        ); if
2 V( Z& L7 M, E6 k9 p        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
8 w$ k" W/ \0 B! e4 ?        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
4 O" H+ U# n" {1 t        (if (= (cdar (laychk cloud_layer)) "No")
" {0 I( B& K- v, B" y, }& I          (progn
8 g" _4 i8 z) N6 h$ p6 M0 r            (laychk (setq cloud_layer (getvar "CLAYER")))
4 H2 n6 |. E  e1 v; j* N) E            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))+ g; c6 i# f- ]: l! L4 y
          ); progn
) t5 ~3 x4 C$ @; H        ); if5 v4 A2 a" \" [) J# |
6 |) j7 f  N, k+ X7 U; Q
        (while (/= (type first_point) 'LIST)
5 a9 r2 w) D8 D, {" L, U          (initget 1 "Layer Scale")# G- r3 o1 h9 d' E& P4 a+ @
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
. V) h' D+ a  N9 j" _/ n. f4 E          (if (= "Scale" first_point)      6 U: Q( G% _- o3 u5 n
            (progn
4 p7 K* c6 ~  I& W. C( a              (setq temp cloud_scale)
; l' P4 W. @7 y* M$ ?              (initget 6)
6 V  r' @; c, L7 |              (cond
- a+ w; m" j/ i* @4 b                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
; g8 p, P; m1 o8 c3 k                                                          (rtos cloud_scale 2 2)
# |1 I! v+ `0 f5 T, C. ^# i1 l+ g* l                                                          "> "))))
2 Y* m3 r2 y7 G; _( {                  (setq cloud_scale temp) )
" |* i* I6 @+ y9 f" O- q              ); cond7 t- T: i0 C0 Y' @4 g- P
            ); progn% b3 J, X# b2 h* C: i; J5 J$ y
          ); if
6 n: \& g( @9 o  b1 ^( {          (if (= "Layer" first_point)
. j; Z7 T# L  H, p/ |            (progn2 F# m' O3 `( D' Z- i7 ~8 U3 H8 d4 O
              (setq temp cloud_layer)
2 p' {5 v5 k: B4 b+ Q: D# Z; W! f3 m9 c              (cond
, ], M$ Q6 l/ v( w                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"( E  ]% {5 w5 N; U7 U
                                                          cloud_layer "> ")))
2 k) q1 j* _" C  M; z$ m5 a3 f                     "")
3 k: R* e- {& n! n. a                  (setq cloud_layer temp)
3 V2 o" q. d+ K7 n( }# _9 K& N                )8 j+ C* T1 X8 l  h' E9 v$ s  V
              ); cond
+ I* c& G1 n5 O4 Q+ u              (if (= (cdar (laychk cloud_layer )) "No")
5 W/ C6 f$ J$ k) o" o                (progn
$ [8 ~: t9 l0 L, k0 \& q5 e1 y                  (setq cloud_layer temp)" I" i6 c5 Y% \9 p) [* l/ j# L! l% O
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
& Q0 Z) i; V& }! M: W                ); progn
7 I0 W1 [5 c1 K* L" Q9 q              ); if) M9 n: j4 V7 Q4 T
            ); progn
. I  P; K+ f9 R6 ~          ); if
; p1 l, Y. y/ X0 y  }- T        ); while- u5 r, G" e4 o1 w4 \3 C5 _0 @3 L
        (setvar "CLAYER" cloud_layer)  X6 k! t! Z( q' [$ v; I
) _  `. i! K3 _5 }' B9 d1 ~6 k
        (if (>= ( getvar "LUNITS") 3), N- ^8 {# y2 K- f, k
          (setq length_cloud (* 0.25 cloud_scale)) L# d& S0 z  q2 n9 u
                length_tri (* 0.3125 (getvar "LTSCALE")))& S+ I% Y9 l- j$ B
          (setq length_cloud (* 0.3406890 cloud_scale)
" h! d. D1 r% Y. v( T+ u7 }                length_tri (* 0.438366 (getvar "LTSCALE")))7 E6 l1 F( L# i# {
        )/ v8 \% C2 K3 |( O2 A# {$ F2 g
        (command "_.PLINE" first_point "A")8 m5 H0 N- C( t& Y4 g
        (while (not (equal next_point first_point 0.000001))
5 o2 s# T+ N) x. k# J          (initget  "Close")
% k0 Z! C1 Z7 ?6 K$ m          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
: E2 ~2 B3 c' }        (while (and (not (listp next_point)) (/= next_point "Close"))
6 l8 I1 d+ d, I$ B          (initget  "Close"): k) e; ]( B8 W; e( A1 t6 c
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))- ]2 ^5 e; o) B4 b" R
        )
6 e! o1 W3 @5 i, ?* ^          (if (= "Close" next_point) (setq next_point first_point))
  ]) {) R, j* h          (setq angle_l_to_f (angtos (angle last_point next_point))
: c& v6 c) c/ K" c                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
4 ?$ w5 v. R% k( H$ c0 k+ {          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)" `6 G+ b& Q, I
             (setq repeat_count 0)
5 b& u# g! x  D7 |2 e             (if (>= (- repeat_count (fix repeat_count)) 0.5)
1 z: Z# D- B$ H1 ~               (setq repeat_count (fix repeat_count))
8 i8 N* N  y0 ^4 a0 e% G( Y               (setq repeat_count (1- (fix repeat_count)))
+ i) z' ?* S+ I$ `             ); if * }8 u/ R& @% r/ U+ E. z7 k4 D
          ); if
3 g2 @  u9 y9 B: p0 ~          (repeat repeat_count (command "A" "-100" relative_point))' j- b" o+ L' U* y8 c. y0 ~4 p9 `7 A
          (command "A" "-100" next_point)) Z$ h- p4 C$ `# c
          (setq last_point next_point)
. V0 x; l) p9 y9 D  T: \& S        )- S  G. [9 Q1 Q; K5 l8 `: Z
        (command "")0 F, }( o- V2 M: `) k
        (if (= (type number_rev) 'INT)
: {# J: c. Q1 H0 G# M1 l           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))& M5 C. a% x9 u9 m% {$ @& |
           (progn! q& D* w1 o% h9 r! {
             (initget 5)
; b& V5 Y! \( k5 \. }4 m. }! B) x             (setq number_rev (getint "\n请输入版本号:"))) n+ r! h: c8 s$ |# ^) }% Q
           )9 ?9 ^/ e( b- t6 G: J' G
        ); if; V  r' q. W& M
        (setvar "OSMODE" 512)2 O6 ]! G3 K, x2 y( c
        (while (/= (type point_tri) 'LIST)! Y9 v, y2 x  h5 }$ j
          (initget "Number"); Q1 Y( ]0 ?" a% w. C
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))- G7 I$ t: {( M. G
          (if (= point_tri "Number")
- f% k2 {$ v/ f/ g- x! p. j  U              (progn
) A, z/ D- f9 |4 |2 g8 _0 P8 p% R                (initget 4)1 s' @. D) G3 n, i3 v4 y  q* f( p
                (cond  U( z$ D& i: k9 N. c
                  ( (not (setq temp number_rev
4 G; U0 _! D2 q, ?, H1 S                               number_rev" o/ {1 D& s7 u( K% o! B
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
) [, M4 V' o9 Z8 g! E8 E5 t5 `                    (setq number_rev temp)
3 m8 G# s1 I+ {5 s6 p                  )
' k* ^: ]# A+ D0 A                ); cond1 B( x0 p# ^: g4 ^/ c6 x
              ); progn/ J6 n6 E( f' c7 T) f5 ~; M
          ); if" X1 o' E7 b. Z" l" T( Z; I
        ); while8 u. u& _+ ~# x# c1 L# f
        (setvar "OSMODE" 0)' k9 G+ n: I* W6 `6 k- c' i5 J6 Y
        (initget 1)
6 d' F5 Z$ W7 o$ L. Z) W        (setq point_ref (getpoint point_tri "\n请选择方向:")), d$ f* R# B; m8 u% m" W
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))7 C' p9 @& z3 b0 J9 |
        (setq corner_1st (polar point_tri
4 F. J. R3 F9 b8 B) C, P                                (+ 1.570796327 (* -1.570796327 dir_tri))
- R. K8 l' _  }  t/ i5 z5 E, ]                                length_tri7 u4 r" I) J& y5 E9 w* Z3 S
                         )! s# g! A. r, b9 {" x3 w4 c
        )) g9 h* C7 ~( {6 }; d" c
        (setq corner_2nd (polar point_tri" Y3 S& t! O. H7 P: a
                                (+ 1.570796327 (* -0.523598775 dir_tri))
# [5 l. R0 o+ w' O                                length_tri
$ Z9 d* l: E8 o$ N9 g                         ), E& ^) Y* N2 f/ }( y& f" {
        )5 C* D% N" O7 |
        (setvar "CECOLOR" "2")
" G; Z" r. Q1 o9 ^        (command "_.pline" point_tri corner_1st corner_2nd "c" )# l, C1 e8 G$ C5 S- [' J+ `
        (setq textstyle (getvar "TEXTSTYLE"))
5 k' E' Z* T1 z1 N! @        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
3 }8 V' K, \6 U3 [        (setvar "CECOLOR" "7")
4 l' @1 k, o7 K1 T, R        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
$ f7 T+ R' J1 p! L                  (* 0.4 length_tri) "0" (itoa number_rev))
9 U$ _. Q& I! j5 F        (layres)
- i) ~3 b, F, C4 v        (err_restore)# A, {3 C/ l; [+ w! j8 N3 b
        (princ)
& X8 C5 a! K3 N; s( H) q); defun cloud* W! J, _- t/ O; s/ A
# ?2 Y- \9 ?2 V) {, L2 ^* C
(defun c:cloud () (cloud))) H+ H$ r& B& J# }
(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy0 W- [4 a* X' B2 P9 _0 V
;;;2 {5 p, d5 c; T* S6 D( D  S1 a* G
;;;  DESCRIPTION
5 O0 J7 A/ e% z" F. W;;;     These are general error routines which can be called by 1 x+ o( O& S5 a- M) T
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference4 B& i- D4 g# U- X7 C0 a1 m( ?
;;;
! g& I1 {: h+ A) u;;;  SUBROUTINE INCLUDED IN THIS FILE* d# d- i8 `7 }7 n" G& U, z
;;;     UNDO_INIT
: }) m+ ]3 Q3 d1 q$ J;;;     UNDO_RESTORE4 j& q+ Y7 V! b# D
;;;     VAR_SAVE
9 i; p1 U* u- A- I9 p$ ~4 [;;;     VAR_SET  
+ b4 C4 m9 D7 V0 c! T. A: s;;;     VAR_RESTORE
+ u: I: c- V/ u4 c;;;     ERR_INIT
( c5 G0 R6 w  J5 j- s: k) J" w;;;     ERR_MAIN
3 a/ a  B$ v; D7 X$ X; X% [;;;     ERR_RESTORE
0 ]. U2 j0 o2 x, f' ];;;
8 l$ N/ @: a: n' v;;;  DATE: 10/17/98; 03/31/99
# s+ ~, b, {4 E;;;
# J) Y, e: v7 E9 f( G;;;  HISTORY:
  U( E6 c6 a7 i$ `' _( O;;;    Add routine of mod_att
, u  ?# D5 P- k! B;;;
" d, F. S; L. A! @# `$ I;;;  USING METHOD$ [2 _4 k3 P; E) ?* U/ d- q
;;;    ERR_INIT:6 ^" T, E6 a' T  y$ G( {1 Q
;;;      This routine initialzes the error handler. It should be called as:
# C$ M# r$ S8 `( [5 {$ `;;;( C0 q: X: K2 ]
;;;      (if (and (not undo_init)% j4 o+ G  g4 o& w8 @& X
;;;               (equal -1 (load "undo.lsp"  -1)) : }2 a1 n4 s; C+ x# y0 V1 S2 l2 U
;;;          );and
8 q" e: t; ?  |;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit)), ~8 O! ^( I+ l& v) Y2 v) ]
;;;      ); if" e, U5 T: h' V
;;;
2 ?- ?+ F  y  M;;;     ARGUMENTS:
$ J; q/ y! |2 \2 _) C2 m;;;       err_init Takes 3 arguments.
6 t3 L0 G( s9 n* g7 Q6 i;;;     1. - The first element of the argument:7 K  B. D' |# F3 M1 P
;;;          This is a list of system variables paired with& C! Q  y0 a# o* O( G
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE"). Y0 K/ i6 G* e  b* U4 `
;;;     2. - The second element is a flag
9 G2 c0 D3 ~/ v) N0 N" f, O. |4 E& i;;;          If it is true, then in the event of an error ; [/ {+ R5 b: F- O$ f0 j4 Z, a
;;;          the custom *error* routine will utilize UNDO
: G% S! L0 {6 X3 K& f" m;;;          as a cleanup mechanism.
# H8 o4 m; J% ^9 r8 C; }* @7 K;;;     3. - The third element is a quoted function call.
' W+ X; a7 I* I, x/ J3 {6 G;;;          You pass a quoted call to the function you
2 C3 d( o% B  h# I# \3 P;;;          wish to execute at the end of nomal routine if an error occurs. # s  ]9 Y* E8 m3 R/ j
;;;          i.e. '(my_special_stuff arg1 arg2...)
- u' x/ J7 w% p;;;          Use this arg if you want to do some specialized clean up * e% ?7 R& b6 f; t/ p; A+ j7 H3 _6 S4 R7 p
;;;          things that are not already done by the standard bonus_error
& x# g7 E& I0 R% n) b% f;;;          function.3 Y! a: g9 `: h) @
;;;
) ?9 A$ `+ b) w# A% f( b;;;    ERR_MAIN: Body of error routine
- W! h8 \( Y  i;;;
5 K* r* j; r  @3 Z  d& p1 ];;;    ERR_RESTORE: This routine should be called at the end of command to
$ X* D3 c5 B. j" t, {$ b; [/ l;;;           restore the VARIABLES, UNDO & *error*.5 P& s2 H: ^* W4 M/ g6 H
;;;3 N& [' B8 P8 O8 B
;;;    UNDO_INIT: Initialize the UNDO status! u4 {1 N" G2 U8 [% l
;;;
% E! {$ ~) V7 r# s' x" c: B; Y;;;    UNDO_RESTORE: Restore the UNDO status! e. g5 C7 n6 j. k9 ^( {
;;;
5 k4 `: j  d6 y9 E  o! c7 N* l. c;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")/ X0 k2 s7 c' U: e
;;;
" |$ n/ s" T- z$ C% I$ t8 `;;;    UNDO_set: Set the variables. the argument is like
6 L0 ~; w" i8 k5 L" m/ s- B;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
7 y3 m- K1 l3 P4 y2 r& \;;;: D7 A1 l! z7 p  [3 Q+ U! g
;;;    UNDO_RESTORE: Restore the variables
9 Y. }) }) X* \& X3 Z;;;
  `6 {; U* v" D7 O8 F$ u;----------------------------------------------------------------------------
: r* v/ f" z0 e6 d$ C% B;  GLOBALS:9 U3 A* p7 o6 E% [  Y1 `- Q: Z
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
7 A& I9 N$ t3 ]" @0 `$ L% e# I7 }4 v;     m_lst       -- list of variables (voided by VAR_RESTORE)
3 Y7 c& q& |( ?, ]5 z;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or. Z9 D" u- u  x
;                    ERR_OLD)" ^, m, K& I+ Z- w9 H: w
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)8 U" \9 \4 D7 K
;----------------------------------------------------------------------------
! y- p, Q% R. d* a# Z$ L8 K! n. ?
! q, J# h8 F# Z' u* J;----------------------------------------------------------------------------; G6 O( Q; ]) Z1 l4 T7 R
; Modify attributes according to entity name, attribute name, dxf_item) G. B( G: |( o
;----------------------------------------------------------------------------+ I1 q* H  S- e" Y6 `( D  {
(defun mod_att(ent id dxf_item)        3 z9 ]" Y# E; W, @
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
/ {" G3 a6 u5 Q" C* H) U& A6 q    (setq ent (entnext ent))3 m- C5 D* _+ J% P3 }/ l; H8 i
  ); while  
, W2 P, o8 h  h, w- p" e& z  X  ((lambda (x)
% A8 m8 X" s9 f8 f6 o7 }6 v        (mapcar '(lambda (y)0 ?' z/ N# W4 f* X* ?
                   (setq x (subst y (assoc (car y) x) x))1 {. K5 x; ~. E& y. X2 s! {
                 ); lambda) j( V$ d. ~. g- L
                 dxf_item* r1 O* z! m0 j& \9 Y& t; m& d
        ); mapcar
6 A; m  C+ L, s6 o# p* T$ p     (entmod x)
' i1 X9 L1 C) u0 k9 @* j     (entupd ent)
  r5 e" n8 Z1 q3 m   ); lambda
, F$ v6 W/ U8 ^   (entget ent)
7 B( B, d5 R& K7 A* ?0 s5 u: b, V: J ): U( ~+ j& h  ]3 K, O$ k
); defun mod_att
) S  W/ Z+ O# n' Z1 F( w! N  r' W5 ]/ |% v' {- j7 w
;----------------------------------------------------------------------------
4 r6 E! O+ N# c& a1 k; Check layer status, return a association list which contains layer information
: Z4 @3 S7 s1 W( H- O" s( K;----------------------------------------------------------------------------
5 [( N( H  z, e(defun laychk(lay / l_sta)/ d( F5 [4 D, h
  ( (lambda (x)
; t9 y; o* C, Q5 f+ y& w$ ]# X" P5 f      (if (not l_s); v& X( {; O  D. E3 n# A
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
) J* o; @& S4 Y4 A5 b. q, L      ); if, ?9 N2 D7 B" J5 ^/ S9 R" B9 n
    ); lambda ' \3 [. A1 L* G4 O; y
    (getvar "CLAYER"): g, B) _2 S/ T4 A5 ?
  )! T7 j3 ^# ?7 ?- \& ^
  (if (not (tblsearch "LAYER" lay))  \) V: W5 u4 v* H; _
    (progn  # q7 z0 }; f6 l0 v" N2 t2 p
      (initget "Yes No")
* X! o& _  @5 l; @" c/ j2 d' p      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
& a1 _, I& Z8 b5 s        (progn
8 u# f; X  i6 k1 I7 o6 W          (command "_.layer" "n" lay "")
4 C+ _4 x" d0 B3 x3 `- m! R* V          (setq l_sta 0)2 B# B  K6 [2 ^3 ~
        ); progn
1 z- b, o% Y- K! v, e! H      ); if
6 g) Q! e( u0 L: N7 k    ); progn
6 U' j( N, J! V' e! D* a' m: I    (progn8 d3 u& D4 h$ f
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
5 v6 R% X, I# A3 Y! @      (if (= 1 (logand 1 l_sta))9 {$ m/ Z: W% A2 K) k0 ~
          (progn
+ g6 Z- l. W& P9 l+ M# D            (initget "Yes No")
3 V1 K/ m- ^* q            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")& x+ ?7 B  Y7 R, i6 E- U5 ]' D
              (command "_.layer" "t" lay "")  M7 S. _: K; i1 o8 g8 ?
              (setq l_sta "No")3 f: O$ @3 {/ q* J9 T
             ); if+ K5 g; b. T# K* q9 L
          ); progn8 P2 R2 E9 {; p- |2 P
      ); if# h/ t/ E0 s! O# F
      (if (numberp l_sta) ' E$ Q$ ], L# O9 c# T; @
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if: M& ]2 Q" M) P- A
      ); if0 k* i3 f9 n3 h* v+ @3 w% h6 A
    ); progn" _9 U: [/ ^+ E
  ); if: n# b$ \" S1 d) R
  ( (lambda (x)# N( a$ G+ l2 }8 ^
      (cond
6 G# @1 V7 G9 i5 ~: M- g        ( (not x)
! i; c2 T6 N  W+ z3 [/ S2 L          (setq l_s (cons (cons lay l_sta) l_s))# L! o3 M. M  Q( l# q
        )5 G' G3 C0 Y/ S; e+ t
        ( (= "No" (cdr x))
1 N1 q% J& m  V          (setq l_s (subst (cons lay l_sta) x l_s))9 \( f* u3 N$ ^9 ~' @: A) ]) R
        ); ~1 Y" o% k, V# u. K7 K
        ( T l_s)$ V% [2 I" F3 H# k) V
      ); cond
1 i3 x& h1 n/ P     ); lambda6 k( k6 U5 w7 d. ^& q: \
     (assoc lay l_s)
* j0 H6 O$ F9 @9 p, m3 v, I  )+ e" r+ z8 Q$ I, U. E# a- [8 `' A
; a* `% n8 B$ G* v! `
); defun chklay
( T6 B! f7 z. U; S4 E
6 y" a) `: k: U4 `  w7 x' q. T;----------------------------------------------------------------------------8 X0 v- \" J, r" {4 d6 m8 _
; Restore layer status according to association list l_s& w3 ?; D0 O/ ]' r' R
;----------------------------------------------------------------------------
3 }. N% r; H  K  V9 n(defun layres()8 \3 w+ ^8 \) K( g! F3 p: x8 |
  (setvar "CLAYER" (car (last l_s)))
( d8 M, R8 F) s3 k1 x3 e8 t) D  (repeat (length l_s)
: |- S5 `0 ~- S: D2 H    ( (lambda(x)  
9 R, k9 w- g! r& `. C) I) O# L        (if (numberp (cdr x))7 r( ^: m- ^( ?! y$ k* a9 X, e
          (progn 9 K. j! a# _* Q, |5 `) U2 g# g
            (if (= 4 (logand 4 (cdr x)))# P% T6 u' N+ p
              (command "_.layer" "lo" (car x) "")
  z; H/ n: A% @8 F1 ^3 Y            ); if5 l/ O( I) H& M- f3 ]
            (if (= 1 (logand 1 (cdr x)))7 h! c" L$ O1 ^$ y# C% ]
              (command "_.layer" "f" (car x) "")
& J/ T6 f5 q+ x+ u8 {) @; _8 J            ); if# `+ m8 {8 N/ C
          ); progn  Y, I$ i) t" w# U- v* C- n# L9 X
       ); if  ) N9 `; \# G' {9 Q9 v( w/ I" J: ]
      ); lambda
( }/ ~: o  [% G5 G1 `: i" N      (car l_s)/ y) j" V; r3 k) W5 Z4 H( s. l; Y
    )6 M8 l) B- v7 s5 f1 a! E8 A6 B% ~
    (setq l_s (cdr l_s))8 p: b$ y3 {* d: R7 D
  ); repeat
- c& ^, {: u9 J. `) j0 j9 e); layres! T6 |1 ]* M. m  O5 H1 ]8 H
, m/ l. o0 h4 ?. e7 m3 B
;----------------------------------------------------------------------------/ S  K, U! C4 I) O( x- ^9 L8 H
; Get DXF codes) j3 h  Q, o/ Z
;----------------------------------------------------------------------------+ {8 T& j* E5 B2 {# \' D& B
(defun entgetf (index ent)7 A/ v% z  g8 p: y' K1 {+ k  `
  ((lambda (e); I$ M; p5 T4 L$ z0 G4 Q
      (mapcar '(lambda (x)
. L( v! k3 j& B; N                 (cdr (assoc x e))) r  _4 r; \! M7 T
               ); lambda
: I9 n, G, b% ]$ W) h; t" F( c% T               index) ; internal lambda function4 Z, M: V" [& l! T! ~, B& J* l/ M
    ); lambda# f: Q; n. |, ^* n7 z; }. g
    (entget ent)
) r1 @1 e9 a6 a/ V, a: r5 U! _  ): I" F+ j& d% G" }; H
); defun entgetf
$ Y% m  e- O/ z# w0 K! |* _; l9 M  U8 w3 V; Q' s0 @
;----------------------------------------------------------------------------
3 R. J8 y$ R- P) b3 s; Save UNDO status  ^  ?& V& M7 y5 ~5 U  Q
;----------------------------------------------------------------------------- Q9 h+ @: t, Y4 h+ A- W
(defun undo_init (/ cmdecho undo_ctl)   0 \" V' w8 d& w) }4 {! Z9 \
  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value5 s7 W" {, R* V( y$ \9 u- i
  (setvar "CMDECHO" 0)
* \2 U& \7 B$ @( Y, [) T1 ~; x# o4 z6 O8 C( F
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
; }- R$ {' U/ A5 N    (command "_.undo" "_all")
0 W; O1 [1 |' ^+ A$ m) e    (command "_.undo" "_control" "_all")
5 |" \* Q# W/ M/ n+ K& `  )9 b1 q' d* H, e5 v, V: T1 y
/ k' }5 O" ~/ J: Z$ _+ |
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off, |6 c. u/ w# }0 s: \, v1 N) c
    (command "_.undo" "_auto" "_off")
. L' m6 x3 z- R- y1 w- p; c4 |  )+ l" H0 B. r0 p; ~) F- j2 O

. M* [& e5 v; d4 J3 m" F  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
( p+ e6 G' A& O! b  O    (command "_.undo" "_end")8 f% j: T* H' i* {2 S# W
  )# {% ?# w, k: d; i
$ U$ y( k' U0 S* U5 \3 H- N
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))5 g" W1 u; E7 {2 D. [1 p
    (command "_.undo" "_group")
) D0 ~2 O) {/ s/ o- H; e: H  )( v( {, C- v9 W2 l& |3 ^

- h1 L8 W& ]( X0 n- R  (setvar "CMDECHO" cmdecho)5 m& u% I" U0 R9 H2 a
  undo_ctl; n2 V, [: @0 _1 i, o, c
); defun undo_init; u; u# a7 [7 l5 C1 W! q
8 x8 E7 ]- M6 S) A) i
;----------------------------------------------------------------------------# S% m: ~4 `9 i: i- u- ]- W# ^
; Restore UNDO status
( k2 y" K5 j1 o( D;----------------------------------------------------------------------------- r) f- k  ?% n
(defun undo_restore (/ cmdecho)% P) c8 a4 H3 Q1 L* `
  (if old_undoctl
8 m3 w7 g: X) n2 k' g    (progn
/ _# M# L& V9 y* j& j% G3 g. t      (setq cmdecho (getvar "CMDECHO"))* o4 c& `6 }$ \3 |# A* K
      (setvar "CMDECHO" 0)9 O% y* J4 P5 Z' u5 o5 C
0 J6 C! B. w! i" P9 }" X" M
      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
- l3 z' @* b  v3 ^7 @6 d      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
, w  Y6 G4 B6 m. x8 @        (command "_.undo" "_end")
6 z$ y' ~: s% H      ); while
5 V# z' f! k5 l+ H$ v7 }& e; R& Z/ @" D

6 `* ^: T$ t7 z" E      (if (not (equal old_undoctl (getvar "UNDOCTL")))
% l2 ~1 s2 t3 [+ X1 C2 F) Q: A$ m0 s        (progn' R( H: G6 _+ l
          (cond6 h9 U: f  k, N! C9 ]) x- L/ ]
            ((equal 0 old_undoctl)9 K( G$ ]4 O: ?" z  [; c$ v
              (command "_.undo" "_control" "_none")
; m' n# {; t* l0 g- I+ S            )
  {' A7 J: ~1 e  m2 i+ j            ((equal 2 (logand 2 old_undoctl))
% ?6 s/ v9 d" s              (command "_.undo" "_control" "_one")
/ k( [! {# S+ o* {            )5 `5 \' ?: c7 m: \5 l
          )& K3 W: ^1 X. o
          (if (equal 4 (logand 4 old_undoctl))
5 k3 B: R( {  D              (command "_.undo" "_auto" "_on")
( i& Y  e( O, f: @. a" k* m. |              (command "_.undo" "_auto" "_off")
; w5 J) H2 j) S! v! w6 I3 W1 z          )
1 f2 E. G3 H2 L        )
; {  l( k" ^# ]& l% B, u      )3 ~2 Y0 @6 Q; B9 U& `- t# }
      (setq old_undoctl nil)
! `, K2 V9 C# r/ u' e5 q6 Y  W      (setvar "CMDECHO" cmdecho)3 E  Y4 V, C8 `5 F
    )3 D- H: |) P* y0 w2 I
  )
  w0 J& I8 ~8 h5 u* f: N6 C); defun undo_restore
9 w3 D' v. T. u' c. A, P8 d  f4 Y) [# W* J& x# X( }( K; W
;----------------------------------------------------------------------------/ [: \! L9 J8 O# u
; Save variables4 s# q. M) G# b
;----------------------------------------------------------------------------5 K; U( b( M: c7 p0 H
(defun var_save (a)
8 R9 L( R  ^$ I9 Y5 Y  (setq m_lst '())( X1 M! P4 k& R& b7 W
  (repeat (length a): ]/ \4 G; z' ~. P
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
, q9 S) W$ o) q6 i    (setq a (cdr a))
* r5 w" ]4 z) u! V) [! s" A) c  )
2 F/ E- V) W/ G2 |8 a1 _); defun var_save
& s% b! ^( q- q$ f% ]$ h  j, ]: l: K' @/ I# t- ]* B
;----------------------------------------------------------------------------
9 O" X8 {+ r. y# r& Q; Set variables
/ D6 {8 @9 W2 G% e1 V  K' F6 q8 q;----------------------------------------------------------------------------) ~3 v0 F; y1 h. x
(defun var_set (m_lst)9 Y% l. l2 c+ T, ?8 }
  (repeat (length m_lst)
( q' i) f  T! d* b    (setvar (caar m_lst) (cadar m_lst))
( W" X" [3 i& s8 C1 B    (setq m_lst (cdr m_lst)): r) Y0 N7 Z7 K- J! o
  ). a5 i) b$ H/ L/ q9 e
); defun var_set8 I- t, t! B% x) C  r1 j
$ R" Y% ~( c0 N. w
;----------------------------------------------------------------------------
3 H: G3 [% I' J0 V* E/ Q' u% X4 J; Restore variables: D2 q/ d/ A* Q4 K8 ?/ H
;----------------------------------------------------------------------------
, d) x/ t$ p& v7 r; y* \! W(defun var_restore ()0 i' [  A/ F( ]% j% u& M, W
  (repeat (length m_lst)* I4 M/ N2 h' N/ F$ B+ i4 m* P
    (setvar (caar m_lst) (cadar m_lst))
2 v2 d- ~7 l5 ?; w/ v    (setq m_lst (cdr m_lst))7 V( H; Z1 Z9 V: d. s) w0 ~8 j$ O
  )! N; x! u; \. s9 r
); defun var_restore! q. \+ h+ q- g: _% u

/ ?9 l+ ~* `: T/ R6 Y: b. S;----------------------------------------------------------------------------
1 v5 G  a# B+ Q6 O3 y5 |8 o; Initialize routine $ E% S5 v8 W+ M1 o
;----------------------------------------------------------------------------
7 f; l1 S, {' l( @(defun err_init(e_lst u_enable add_fun)+ v$ j$ G$ }# V0 s, e7 N
  (if err_alive (err_restore))          ; To avoid nested call
6 |) u4 v, J' |5 w5 @  (setq err_alive T)4 b1 Q$ t& T6 C: B
  (var_save e_lst)                      ; Save the modes& x6 u. r/ H' v! Y
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status4 O& F; z% G# k: c: K2 X
  (setq err_old *error* *error* err_main) ; Save the handle of *error*
# W2 e  z( D( e, f# F( \  (if add_fun                           ; Add the user cleaner
) Z. K, j; e/ k/ Z# B9 Q) q! O    (setq *error* (append (reverse (cdr (reverse *error*)))+ b! R1 C0 L2 O5 X: ^! M
                          (list add_fun (last *error*))
) B5 x( I6 N8 R                  ); append! e$ m" n# W$ q, a
    ). D2 v* X4 Q' w; K! b
  )3 e2 |6 R6 K; I9 y2 c2 {( t
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
# Y, n6 ]4 x8 p; @( B' f# |2 [; Error routine body
" @: Z2 i: j6 s) H9 a; ^" V;----------------------------------------------------------------------------0 B1 z% B  {( |: O6 C+ t
(defun err_main( msg / )                ; Body of error routine2 U  p$ v! Q! o. ?; d  A
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs( f8 D* n. Y# Z! `8 h- c8 `1 o
    (princ (strcat "\nError: " s))      ;while this command is active...
; Y, @3 G, n# m+ x; ?$ I/ w& w  )8 U! \9 V, U7 U- u' V
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command+ K6 C, C1 o' {  m' D; X

6 P7 l' w4 B6 `: l" E5 E# a- X) U  (if old_undoctl) V# z% B- B5 ]+ K  h4 C
    (progn
) }6 J; u0 Q% Y/ \/ ]9 P+ o      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See5 K- J  X& B  |& f' L/ P% {
        (command "_.undo")              ; if it's in UNOD command" J8 S5 Q1 `" G" m; a
      )& Y/ l7 X3 s" {2 s( D
      (command "_end")2 v! Z! F" z, b2 D9 C! k
      (command "_.undo" "1"); y+ Z4 y1 U. ~  O  s
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))5 v& y, n3 c, U. j- Y( V) w
      (undo_restore)                    ; Restore the status of UNDO% I: b' d% n; ?- f- {2 U* R" r: C) h
    ); d' y- r8 }' w0 K; L
  )
2 o6 W; ]# h! e. m, t4 l$ ]" ?2 b  r7 u, ?% u
  (var_restore)                         ; Restore the variables2 \( E# A) G2 t. b& B& x
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
+ i# G- `: N% M  (setq err_alive nil), b1 P7 P' D6 z' u
  (princ)
8 V% i- S8 Q9 p& a" \); defun err_main
: L* e* R9 I( A. z8 p
5 e  X9 |" r+ B;----------------------------------------------------------------------------
4 |0 Q& |, g  q* v( u5 n- [$ {) q: ?4 ~; Restore error status3 s2 M- v  ]5 W
;----------------------------------------------------------------------------
( N" I# k* K' Q  k7 [(defun err_restore()
9 W- s" q: w. W+ o+ Y  (undo_restore)                        ; Restore the status of UNDO! T$ F9 n/ O- R* u9 q
  (var_restore)                         ; Restore the variables
4 S8 ~: {- `' s) [  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error) J6 s$ L' k' d4 Q. B5 S
  (setq err_alive nil)
9 d1 r/ Y5 H+ J; w% @9 s  (princ)) P! F8 i4 ^! ?* i9 G) M. w0 x8 ^
); defun err_restore
 楼主| 发表于 2007-3-13 08:40 | 显示全部楼层
以上两个程序同时加载,在R14版本下面是可以使用的,这点我确定;但是在07是否可以使用,我现在也不确定了,因为这个命令在我用07的时候用的不多,请问版主怎么修改一下可以在07里面使用呢?谢谢指点!
发表于 2007-3-13 08:49 | 显示全部楼层
敢问楼主是否懂得CAD外挂小程序的编程?日常工作中确实有些不太方便的烦琐的操作,我想学习一下,请楼主赐教~~
 楼主| 发表于 2007-3-13 12:23 | 显示全部楼层
楼上的朋友,不好意思哈,我也是菜鸟,不然我就可以自己修改程序了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于|免责|隐私|版权|广告|联系|手机版|CAD设计论坛

GMT+8, 2025-4-24 05:24

CAD设计论坛,为工程师增加动力。

© 2005-2025 askcad.com. All rights reserved.

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