CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
- k. @( X* \- {4 U3 M “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
6 ?. d- `1 u5 T7 a/ l提示:加载成功
. e  b8 X  m2 C2 x* A9 J然后使用CLOUD命令,
2 I. N, }! U8 }5 I- g提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”6 ?9 c  n' @# z7 W; @
请高手指点一下,这个是怎么回事?应该怎么改正?! j7 B0 I) O/ b- x1 v- n8 c
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx
" N6 I7 n- x- I% M+ l. m6 ^;;;! [' N. {1 J) E" n) d
;;;  DESCRIPTION
  r5 b+ d$ F. |;;;     Draw cloud and you can specify the globals variables listed below
, |4 O; \: G1 l! E;;;     to decide the characters of cloud
; Y1 s6 C4 M, {5 @3 _3 Q;;;/ J8 ?  [0 R: |0 _
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98( Y2 ?- b6 z7 H2 f/ C
;;;
  r1 v$ s- S9 U# }! E% F0 ^& i;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
( V$ T% ^5 m) T1 R  z;;;           Change CLOUD.001 to use CLAYER to perform the same function
: H, ?: X2 w2 r0 Q;;;           Use the common error routine UNDO.LSP to optimize this program
* b& l4 N$ }, ]" _9 ]% L& F;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE% K' X; E' o/ L  g9 P
;----------------------------------------------------------------------------
) M2 g" }- Q+ n& Z$ {;  GLOBALS:2 K- u0 z; P# _% Y$ G
;     cloud_layer -- layer of cloud
) M8 r; f* S1 C3 Y7 y, R;     cloud_scale -- scale of cloud+ h  G$ n, r5 W; `. c
;     number_rev  -- revision number5 ?$ O* B# H. I! o. G
;----------------------------------------------------------------------------% p) @* y- q( H% B* d( Q. l1 T
(defun cloud (/ locked temp first_point next_point relative_point
, E) y3 E- a- f1 O2 S; u' D               last_point point_tri point_ref corner_1st corner_2nd length_tri4 u* s; c) n/ O
               length_cloud angle_l_to_f dir_tri repeat_count
  ]. v5 ~  {$ U1 \+ Z* H  U               table_cloud )- ?3 }- T  v9 F% `2 x0 k
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))
" ~4 W! e7 n' b          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
5 Y  z6 U# H& l( d% j- U        );if
5 }+ n. g6 B# g; S+ |1 r        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"6 c3 m: P$ |5 W' J# a* C* K1 ~
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil)): f$ c7 N# p5 n) t% |
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
# {: y- X/ h4 ~  H4 Z5 A0 c5 s                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))- R1 H% Z! y0 \( @$ i! ~+ d8 t6 P
2 D" z4 {9 U. ?9 t4 n
        (if (not (numberp cloud_scale))$ G/ n3 Q$ s# I* ~& O* X, a% q
            (setq cloud_scale (getvar "LTSCALE"))
, n% k" `! F( ~        ); if
  I' W# M9 c/ \! U& [        (if (not cloud_layer)6 X7 @+ s: Q3 d, f: m" @) d
            (setq cloud_layer (getvar "CLAYER"))
, {/ I) ]. X& e        ); if! D+ S( h& N: L  F, L5 [
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
) z0 P' b% r8 C6 u. D        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
7 V2 J4 U" y4 S% _! l        (if (= (cdar (laychk cloud_layer)) "No")0 o+ x+ Q5 ^# {  ^& e
          (progn' A+ o4 ?; F4 C5 w+ H0 T. ~
            (laychk (setq cloud_layer (getvar "CLAYER")))
8 P/ H* k) Y* G- U4 D5 [5 I* j9 A            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))5 _$ q; d# z1 k1 K. J9 _
          ); progn- k/ f5 O- v6 B% _) [8 H9 E6 U
        ); if
. o, M! v8 X0 z4 y0 }5 p' C, R" f4 F/ [1 P
        (while (/= (type first_point) 'LIST)" J5 e5 L6 [6 o, ^, P( S
          (initget 1 "Layer Scale")* K$ ^1 G: Z% H  p# u% ]3 a! A" P
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)6 p( [4 h( v3 a
          (if (= "Scale" first_point)      % m) @6 X1 y8 w! V8 t
            (progn- S, y; w, T: q( ^( Y
              (setq temp cloud_scale)
. ^8 H, R3 T3 C3 _; {              (initget 6)
: x" ~0 ~4 n9 P9 k0 h! z, V) h' t* J              (cond, c/ y) w( v$ p+ l! e
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
/ X1 E: C1 {0 h8 N                                                          (rtos cloud_scale 2 2)/ \+ r7 m! [' i2 v# ]) ?1 Y7 S
                                                          "> "))))! G- L' x6 |' b4 v" r
                  (setq cloud_scale temp) ): q6 i/ C- V3 v/ `; L
              ); cond
* M9 r9 ^. L( Z7 G8 A            ); progn
2 v' T  N- t" n* H- \          ); if
4 t$ Z9 k1 S4 r          (if (= "Layer" first_point)8 t" d4 c  r0 W& j: z- Y
            (progn
& f  e: W  N8 G+ V. H  S              (setq temp cloud_layer)( [1 H6 O( M/ w/ D) Q
              (cond* g& N3 E9 _. ~/ ?1 \0 l
                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
- Q8 _1 b& N( F* j' D$ E                                                          cloud_layer "> ")))
$ M5 t" I0 x+ P8 b: `0 {                     ""); B" M- I) P: ^7 c
                  (setq cloud_layer temp)5 G- Z1 q$ x! X& _* K7 g
                )# @: c  x* C* }0 A6 j" u
              ); cond
0 n+ v5 O) ^3 X1 B              (if (= (cdar (laychk cloud_layer )) "No"): X9 R$ K1 ^, k  R. c
                (progn1 H! P- x) w" W; z5 E
                  (setq cloud_layer temp)$ U- U* \& a2 l, X8 e- ^/ i9 r
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))" s' f9 U; }4 ?
                ); progn) B" t9 O  S. R% R6 ~, q6 D
              ); if/ z/ }- V* s7 D" o; ~3 N# G% J
            ); progn
7 w. n1 U  t$ O8 d  p          ); if5 _0 |& M# l8 e7 ]
        ); while
+ p, I  Z" ]3 j: n        (setvar "CLAYER" cloud_layer)
  Z% I; p2 U( c( m4 H4 [
) _- H8 ]5 h: V6 D        (if (>= ( getvar "LUNITS") 3)6 V2 P% Q/ \9 h6 H( @2 v. k7 p8 q
          (setq length_cloud (* 0.25 cloud_scale)
, Y  X$ n! O6 o  S                length_tri (* 0.3125 (getvar "LTSCALE"))): [' b3 w: H( ]" z- w5 ]) V5 v, \
          (setq length_cloud (* 0.3406890 cloud_scale)
9 W+ m) G/ [0 p! X8 ~                length_tri (* 0.438366 (getvar "LTSCALE")))
; F& n9 }+ r" C/ F$ `$ J        )
' V  i7 j* V; q, I        (command "_.PLINE" first_point "A")5 ~8 |$ u, P! F' Q9 y# f4 @0 o2 e' p
        (while (not (equal next_point first_point 0.000001))
0 C: x' k. S" q0 ~% N, k. l          (initget  "Close")2 [: Q0 f! b: f3 U2 a# H7 U
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:")): J7 l. S: }; b
        (while (and (not (listp next_point)) (/= next_point "Close"))& o" Y  A" q9 I- n& b  b0 U  t
          (initget  "Close")
" C& w, |! V( Q+ E  z# e          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:")), M/ x$ m% i! _7 J
        )8 j# u' b8 X% K; p: T
          (if (= "Close" next_point) (setq next_point first_point))' X6 L! L4 a% F& i8 k
          (setq angle_l_to_f (angtos (angle last_point next_point))7 P$ h: M; n5 q5 i
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
" _+ [( U0 d9 Z' c2 b6 p7 q. v          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
, C$ ~2 X! q/ W3 x             (setq repeat_count 0)" _( Z- O- L0 C! O- g/ }2 a  d
             (if (>= (- repeat_count (fix repeat_count)) 0.5)+ }) c, e% V2 X- d/ ]
               (setq repeat_count (fix repeat_count))
- R, s/ b, o; O$ g' M  `               (setq repeat_count (1- (fix repeat_count))); h0 h" Y5 ]% e- y0 J3 Y
             ); if
6 {" D! `! l5 X, E( Q* v" `          ); if
. F" U- _, \) C; i; Z          (repeat repeat_count (command "A" "-100" relative_point))
( G5 y+ H4 B+ k1 ?/ a          (command "A" "-100" next_point)
2 K+ s3 s0 r; x          (setq last_point next_point)! i9 }- K0 T" _( S  z
        )
: Y& F& i  p8 \/ z" u        (command ""), v, O% w/ d! `, u+ T
        (if (= (type number_rev) 'INT)3 I# _- }- q9 T- ~; g: c
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
1 W# ^8 K/ H2 T" Z+ P' |5 u8 [! Q           (progn
: k- ^2 p3 i' L% b             (initget 5)
& c, I8 U0 z8 E3 q8 [& p             (setq number_rev (getint "\n请输入版本号:"))  c) \( z/ D. t' e$ n9 l  F
           )% X. |5 L( Q3 k+ t
        ); if
3 S4 x6 g/ n9 B9 Z9 b' f# o        (setvar "OSMODE" 512): u4 r0 y! F. z2 f
        (while (/= (type point_tri) 'LIST)
/ B- C2 ~/ H- g" m$ S2 O+ a. Z% `          (initget "Number")
; W5 S/ H8 I* _5 p/ I  T          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
) T5 u- \, U  ~6 D+ \. q4 t. k          (if (= point_tri "Number")4 e" O' Z, q' p% H0 o% A. q8 d) g
              (progn5 z( _9 n! }+ H9 D  C$ s2 o* _
                (initget 4). T. L8 P* q; Y1 O9 t2 f& m% b
                (cond! ?4 W$ o6 N: x3 Q5 t1 y/ L: X
                  ( (not (setq temp number_rev . y1 I& d( `. R! ]1 E
                               number_rev) S# K: y. Q4 `  L' x( m
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))/ i$ _3 n' ?9 |* }
                    (setq number_rev temp)
# K$ D7 I3 |' K" x                  )# n0 D6 F' Z( A, O8 e
                ); cond
6 s5 q) J, `0 k! C9 ?+ \0 o              ); progn
6 |. M7 K6 H3 \0 D/ L          ); if
1 z0 G& H% P) b        ); while
4 S$ }0 ~  v8 H6 c        (setvar "OSMODE" 0)
3 B- Y( m- I' P3 `* ~0 X* y3 z2 m8 O        (initget 1); o9 m* m5 T( W, D$ V( @# I
        (setq point_ref (getpoint point_tri "\n请选择方向:"))1 G8 l4 x1 o5 u3 A, u6 |1 x/ m3 Q
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))
6 P  d. S* s; s* C7 s        (setq corner_1st (polar point_tri
0 s* T0 Y# ~! E; p; U                                (+ 1.570796327 (* -1.570796327 dir_tri))
' {3 X; ~( _4 _2 d9 }. \$ g                                length_tri
) o- J# |0 r3 V8 k& i                         )
/ ~, J8 G% M; ]! c7 U; r+ s        )
: O) S! s' z7 k+ p: X) J. ^) }        (setq corner_2nd (polar point_tri- Y* F. U- k9 F0 y9 n: E( C. S
                                (+ 1.570796327 (* -0.523598775 dir_tri))
$ o  b1 S$ C. M3 b                                length_tri
2 s  w% U# Q' U9 A' s                         )0 q4 v- _. d) |8 J( ?2 n9 o' j+ i: q
        )
: `8 I1 r9 E& |! `6 s0 Q/ w        (setvar "CECOLOR" "2")
& x( w0 Q/ Z  @        (command "_.pline" point_tri corner_1st corner_2nd "c" )" a2 J! v7 p% P6 P! U/ ?
        (setq textstyle (getvar "TEXTSTYLE"))* B3 n2 ]- T+ T" F: E3 B* \4 g
        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
$ a3 g% \: |4 A        (setvar "CECOLOR" "7")
' R4 Y2 [. ?0 d+ \. l$ B1 H        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri)); t* T5 F* C4 V( t1 O, |  b
                  (* 0.4 length_tri) "0" (itoa number_rev))
( I4 R6 k8 O) C& }+ Q, A$ z        (layres)9 T" r' l0 `, r4 G* J3 y' W
        (err_restore)' S1 j5 G9 S) G6 i: f2 G' W
        (princ)( O& f2 j' t0 z* x; s& [5 ]
); defun cloud
# ^$ l4 h# C" C+ w" f. N# w. @* l/ [
(defun c:cloud () (cloud))' k9 S  D( h4 S' _3 G3 c6 t
(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
' B  s. G3 v: G5 N% w9 D;;;; d6 a$ _1 D, _" A. P
;;;  DESCRIPTION
& C/ G1 p8 }' V% i2 X  k4 u) R( F. ^;;;     These are general error routines which can be called by . V2 Q( t- Q' a. ~, s! ]
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference
; H' ~; U# b; ]) P4 W: p" v5 E;;;
* P1 v1 }4 y" j% M; [# m;;;  SUBROUTINE INCLUDED IN THIS FILE; @  V0 N( }1 e  w
;;;     UNDO_INIT
" w! g$ f* |# ^  H; V" V' ^3 N0 g5 n;;;     UNDO_RESTORE) q+ n( D1 l1 V( b6 @, l( X1 S
;;;     VAR_SAVE * Y$ O+ S) v9 O6 f; D4 \
;;;     VAR_SET  
, A! h* e3 b& R9 k4 ];;;     VAR_RESTORE
% S* ^& v- R4 o1 l5 E;;;     ERR_INIT # L4 k% f  t( T* i  K4 D9 ^* G
;;;     ERR_MAIN / T6 Z' e/ G" Q
;;;     ERR_RESTORE
9 \& T. X; `" F; z;;;5 I! W( N& ?2 F  h8 C
;;;  DATE: 10/17/98; 03/31/99
+ X0 q3 j* a" r! V;;;7 `6 k- s- p5 q6 m1 O
;;;  HISTORY:
. G* g" V0 \& o. J7 x* T+ p;;;    Add routine of mod_att
0 w& q$ a- v% P" _/ N;;;
0 ?# |, w3 E6 i# |, J;;;  USING METHOD& X$ A  E! B( L
;;;    ERR_INIT:
+ N2 Q3 Z( ?  a;;;      This routine initialzes the error handler. It should be called as:' _- n, Q0 |" K- L2 r/ U
;;;
. F: u( F2 U# L& L. E/ L6 @4 {;;;      (if (and (not undo_init)
4 T0 I( f5 n' m;;;               (equal -1 (load "undo.lsp"  -1)) 6 ]8 K/ u7 w7 T' K. F
;;;          );and
2 I4 j% \8 Y; J* F;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
1 g* P2 l, M  F  f) x;;;      ); if/ A/ _9 _; P3 {: g" n0 o0 i* d( ~
;;;1 C7 R4 y. K7 S/ c# |; {2 b
;;;     ARGUMENTS:! E2 F1 M; e! c) t* P
;;;       err_init Takes 3 arguments.
, s5 r" \/ p6 ^4 o;;;     1. - The first element of the argument:/ ]7 p. Z) ]0 v/ p& }+ Z1 _, Q
;;;          This is a list of system variables paired with. W! z: U& F/ v/ W6 f' T2 t
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")2 I1 G7 r# }& t% H: D: N: N
;;;     2. - The second element is a flag# `, f) R4 K1 P/ l9 t9 p$ n
;;;          If it is true, then in the event of an error 4 x  T: B; q7 b
;;;          the custom *error* routine will utilize UNDO + Y' B$ V  E, H
;;;          as a cleanup mechanism.
1 E, V; s# B* P( O7 r& b;;;     3. - The third element is a quoted function call.9 B- Y, h! G6 L& V* i
;;;          You pass a quoted call to the function you
7 ]. H" f- M7 T+ b6 ?;;;          wish to execute at the end of nomal routine if an error occurs.
& `8 K; [( a: P7 L2 f' p;;;          i.e. '(my_special_stuff arg1 arg2...)' Q% ]3 k3 x- v2 Q4 y
;;;          Use this arg if you want to do some specialized clean up
' y* g& ~; }5 u* F3 x3 I  t: v;;;          things that are not already done by the standard bonus_error 9 ]( Z! ?! X, I  y1 s/ N
;;;          function.
, V, M  m) N$ p' e;;;
% D/ X- W4 d7 |) W3 a# D1 G% F+ `$ a;;;    ERR_MAIN: Body of error routine$ S# w' e  j" `' M/ f5 o+ L2 r
;;;
0 P" u; g  k1 ~;;;    ERR_RESTORE: This routine should be called at the end of command to8 a, o: R" Q% B! q5 k
;;;           restore the VARIABLES, UNDO & *error*.6 Q, p- g' c; y+ u" R. y
;;;, ^, ]9 I% O9 t5 N
;;;    UNDO_INIT: Initialize the UNDO status6 I- s$ t1 }3 l# ~5 Q' A
;;;
+ Z8 a) v/ q6 `( W4 f6 k;;;    UNDO_RESTORE: Restore the UNDO status
  c% T' [$ s0 ]5 w- J0 w% o2 g;;;4 i. G) ?5 Z) m( h( J4 l) Y+ |$ P0 q7 i
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")7 z  g* Z* w& `+ T$ k) K8 _
;;;
/ ^% c4 E/ U6 M1 y3 I; g;;;    UNDO_set: Set the variables. the argument is like
- A, `0 I+ K& F# V3 w;;;              '(("CMDECHO" 0) ( "ATTMODE" 0)). b6 ?( b" g7 f* n
;;;+ a8 S" o3 {8 n2 v0 l" v" x
;;;    UNDO_RESTORE: Restore the variables, h/ V4 k- A4 z( W( J, V
;;;
* ^( Q+ i. t, L$ d! M; _;----------------------------------------------------------------------------- c! @2 S- ^2 |; Z& I& g$ |
;  GLOBALS:
% T4 {1 q# j# F;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
$ n* }( p9 n4 D7 y2 D;     m_lst       -- list of variables (voided by VAR_RESTORE)3 K6 c( K2 X, y1 G  q7 s$ I) D
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or( B# U6 f  z0 r/ b3 a6 G
;                    ERR_OLD)
4 n. E) R- G$ ~! a;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)3 ^% c2 }  Z* d( T5 A
;----------------------------------------------------------------------------% |& ?5 c" ~% E6 \' y% F5 ^5 Y& e

) c1 h7 t( r" A" S7 M;----------------------------------------------------------------------------
" v2 }# }( f, `- v* o1 F2 p9 F8 ^; Modify attributes according to entity name, attribute name, dxf_item8 W: G8 u$ Q& J8 K
;----------------------------------------------------------------------------) |5 `0 M* v0 g7 Y/ a
(defun mod_att(ent id dxf_item)        - s. p2 y3 a! \+ e' s
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
# d! m% t' i9 O    (setq ent (entnext ent))3 W; Z& \: {9 n  U
  ); while  ) u- d7 S8 e3 N( U9 C0 v) ~
  ((lambda (x)9 i6 b( r: H& d6 P' V$ \1 O1 {
        (mapcar '(lambda (y)
; p* l& x# {# C3 I. c* R                   (setq x (subst y (assoc (car y) x) x))
  R* o( L& Y; y# [( P                 ); lambda  M2 |# t8 `4 }$ l3 N' P; V2 ?2 _
                 dxf_item. v' A3 M+ m9 v0 h+ W' h
        ); mapcar9 @' f/ ^) P- C- @
     (entmod x); W( Z# u& b% L; n; _& U
     (entupd ent)
& q$ s1 n* N8 S" e0 o2 o   ); lambda& H0 F. x) `; f. y
   (entget ent)+ y5 P$ w" B( h7 b1 a5 ?7 f: ]8 `) i
)
) C% }% K+ H. w- |( f, h3 P); defun mod_att
) y$ d# \4 B$ F0 J, a1 v: `& S* A# V% `
;----------------------------------------------------------------------------$ {1 B; F# e- o
; Check layer status, return a association list which contains layer information
6 i: I! B% v, O7 G$ `7 m) W;----------------------------------------------------------------------------2 T& i, G& k: ?6 a
(defun laychk(lay / l_sta)9 o. k$ N8 H% f0 S+ Y7 I3 H
  ( (lambda (x): k  S0 c6 u2 M/ [1 V7 n
      (if (not l_s)1 C/ o) D: e; |; L
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
" F7 y7 T- ]2 M4 I6 j  t7 f+ e( U      ); if
5 s/ X. o/ R6 b  z, [    ); lambda 5 w* F) [# k* c9 W& O$ _* n
    (getvar "CLAYER")
2 I0 p3 C4 b6 N* [  ), L1 r7 L9 h# I  Y: a; f
  (if (not (tblsearch "LAYER" lay))
7 S5 h9 D: Y7 j) U+ D* N    (progn  0 C3 `8 v2 m3 c2 h
      (initget "Yes No")
7 a4 V. Z, Z6 |8 Z  l      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
6 ?: b# i! T; N2 b5 \        (progn, v  n$ _! N! }/ _! b
          (command "_.layer" "n" lay ""). C0 u. \& K' }% U
          (setq l_sta 0): X/ s* l- m/ E" c6 c6 W7 S
        ); progn
( d+ m. y; g! |5 w$ ^      ); if
" F, m! G8 ]+ g/ B: l( h; u    ); progn
9 u; ?# |/ t- T    (progn
$ v3 s  G$ `1 D* Z, k8 V% g      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
' `9 J$ W# x6 {      (if (= 1 (logand 1 l_sta))
" U& q+ L/ |# U& M- s, d9 e          (progn
6 k6 |, w% J$ [$ ~, u( i4 D            (initget "Yes No")  }- j& \9 p( m# M5 `7 R& J- D9 @
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")
' m& i: L1 ?9 g" v! i* H/ n' i2 A. X              (command "_.layer" "t" lay "")" o" @, O! b7 y. K
              (setq l_sta "No")  N- E+ _6 c8 f" ?
             ); if
4 x5 I& F( `2 y/ R* x% ]. g) D          ); progn
; ^$ b. v' [$ y- U; W% q( i, X  Y      ); if: o8 [0 I# ?% W$ o% V! q% P9 {9 x+ N% P
      (if (numberp l_sta) 9 A4 ~0 A; t5 h+ h1 }9 K$ a
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
% {' Z  H( Y* L) \, e# ~) h      ); if  ~# X; s1 w/ T7 V; [
    ); progn
- a5 @( T2 I/ w4 a3 `  ); if  B1 n- ], V/ I6 x( o* o$ F
  ( (lambda (x)
: P# i# O, P2 l# F' C- G. f! y      (cond
4 S% u; u% Z) ~( Z7 O' c( ]" ^        ( (not x)
# Z) R6 T/ T1 X' |          (setq l_s (cons (cons lay l_sta) l_s))
6 m( C+ V' m$ S% r, H/ u7 U5 Z3 P        )
  c1 ?9 \" Z# C0 z        ( (= "No" (cdr x))
: S) T( G6 P7 K& [          (setq l_s (subst (cons lay l_sta) x l_s))# K+ Y: Q" a/ y  g8 c" N
        )
5 e5 l& S! m# Y9 @- \+ L3 r" q- o        ( T l_s)
- u4 \2 W4 f: ?% N" _      ); cond) `, B4 x  w1 i( B
     ); lambda, F$ T4 c8 S* R3 V' c
     (assoc lay l_s)
! B- @3 y" O- i% L8 T  )
# R& W, w% L3 P4 s. s+ |) c3 y
2 _! ^( G* O$ G1 O$ J/ \$ B% g; p); defun chklay
$ J% h. }' u: X; |4 ^8 R) w, |4 Z5 S0 h; j
: R8 A8 P# X+ A; [" }; n( F. D;----------------------------------------------------------------------------
( m8 Z' F0 X3 r2 M) H7 c; Restore layer status according to association list l_s
( V0 ^1 Y9 U* S" P2 i% h, m;----------------------------------------------------------------------------! ~, g! t- ?7 f3 _- b
(defun layres()( w- [& E4 o& O# a% V# L+ k2 B
  (setvar "CLAYER" (car (last l_s)))! ~5 ^3 C& q. `# s' C1 x
  (repeat (length l_s)) f; f+ B. k, ?/ E
    ( (lambda(x)  
$ ]; W. v, A2 B( t1 \% r        (if (numberp (cdr x))$ U( w/ }* {1 j- B6 w. i
          (progn - q- [7 V. n- ?$ A0 [
            (if (= 4 (logand 4 (cdr x)))
) k* W  J9 Z) m# x. r# L4 _/ x              (command "_.layer" "lo" (car x) "")
9 P. M5 ~+ n& n8 I: n7 h0 C- U            ); if
$ E( p4 a5 ^- D& A( z6 z            (if (= 1 (logand 1 (cdr x)))+ [& K/ M# G5 A& ?! c
              (command "_.layer" "f" (car x) "")
$ G1 @2 E4 h( E- L; r6 g            ); if
/ k9 ~" M( Y0 o+ f- m) l          ); progn
5 a' I+ L) y* Q5 X       ); if  
; L$ o- X3 G4 F# J% q3 F      ); lambda
9 [" i! c0 l8 [- a& L      (car l_s)6 H( ]) p" Z" @
    )! P" D* Y/ S# m; l+ t
    (setq l_s (cdr l_s))
( @$ R5 x; @3 I9 `  ); repeat
; y& `5 Q$ o9 k% J); layres
# l0 u4 Y7 r" l# ^- \4 _; ?" b1 V8 j3 k) c
;----------------------------------------------------------------------------
5 _1 S/ w" r3 \4 h; Get DXF codes
, \2 p" p1 V; T;----------------------------------------------------------------------------
) Z! i$ ^4 }! z3 o: M7 e(defun entgetf (index ent)$ u! \& |) R( l. X
  ((lambda (e)
" D6 F  O, L& g0 q% C* p, p      (mapcar '(lambda (x)+ v# G2 |) t# T4 Y7 o) P( m: |
                 (cdr (assoc x e))8 s5 x+ |& j, H9 n* z
               ); lambda
) E1 Z5 f# w3 z: B6 {$ |               index) ; internal lambda function7 y% q; E, c2 R1 D0 n. g8 b
    ); lambda
/ \7 A2 h* v: K4 z9 P  W    (entget ent)
; F4 V, T5 K3 A, u, z  )0 U5 a( V8 b( w: R1 N! G! H# o* g
); defun entgetf: l  d/ l6 Q- K8 V5 T
- m" j% f' p! S" [2 D
;----------------------------------------------------------------------------! j& H3 E- O7 A! U5 c
; Save UNDO status) B* G$ P. Q) M0 R% d5 D
;----------------------------------------------------------------------------( y! P' T1 b! X4 n
(defun undo_init (/ cmdecho undo_ctl)   , \1 C1 _6 C9 M
  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value) @# T  `  p" q
  (setvar "CMDECHO" 0)1 s5 h* [& Q) u2 w1 Q# `* Z+ _

( c) c4 U8 [$ e7 |) {: c  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable9 J9 b6 D5 y  f% d
    (command "_.undo" "_all")! N6 @! M( p" M" d* h
    (command "_.undo" "_control" "_all")  W( f& Q- t# I3 s( }" t
  )- \+ P$ R/ S. K) S; ?
; S  U9 H+ q3 A, J
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off
# ]! G- Y$ a9 I3 G) F! u5 a# ~* y    (command "_.undo" "_auto" "_off")) Q9 u( f+ K$ O) e/ u
  )$ n! v1 N! p( t8 Y2 k7 d
, u' |8 ~! ~9 j
  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
8 ]: g* F1 ?9 A2 T    (command "_.undo" "_end")
# X- a& [# J4 F/ y/ @5 `  )
8 W- n/ k5 B2 O
1 F7 @1 ]7 ]/ d) {4 O# H  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
+ B' g/ ^+ n& Z    (command "_.undo" "_group")
1 M$ v$ }& q) }2 C  )
3 P: R# E& B6 W) J, |9 e- \8 n( }! Y: C% a
  (setvar "CMDECHO" cmdecho)
6 B+ V; a# `) a/ l$ ?* o8 C/ J" r  undo_ctl
5 z. d; E8 l. z0 P' x, S2 P0 c1 f); defun undo_init( h: M2 O9 z$ w3 S
' H$ L! o4 e! ^0 P
;----------------------------------------------------------------------------8 L5 H/ k, b% G% b, t# b2 }9 N
; Restore UNDO status; u9 Y8 e& E/ X, m* ]" J5 t$ O( _
;----------------------------------------------------------------------------
! y  {8 b* {5 ](defun undo_restore (/ cmdecho)0 i% e- ?# [$ x, C0 J
  (if old_undoctl
$ a/ O, T" B: k* |9 j# f8 |$ i    (progn
. e' Y" j, q( g6 r6 [      (setq cmdecho (getvar "CMDECHO"))( g0 d/ r8 `1 H5 Y/ W. k, v3 ~
      (setvar "CMDECHO" 0)! N% ]2 Q* Z4 {7 L/ R* I4 x

4 c# Y! t6 {3 [+ A      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
& L, \" ~0 o+ |' n5 l7 r& m8 z) F# m      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
* n- k# f7 v) \* ^        (command "_.undo" "_end")4 q! h7 z2 x1 g0 T
      ); while3 I+ f0 Z( m% X7 d7 I4 l
( M0 v  o" }& {, @+ E4 _  ]
+ R- _/ p% @" O) i  n7 Q7 d
      (if (not (equal old_undoctl (getvar "UNDOCTL"))); I) v$ k/ z, F# e
        (progn
4 M7 R& F9 y& E0 [0 b4 ~! X+ R          (cond$ l$ f5 ^: H( E" m& J  U0 t
            ((equal 0 old_undoctl)0 |, U- k1 r( y* i* d  ]/ u) B( c
              (command "_.undo" "_control" "_none")% l  m) G, l; {8 T$ b9 e1 v6 ~
            )
& d1 R2 P9 _+ ]4 Z. E, L0 c( e2 U" n# N            ((equal 2 (logand 2 old_undoctl))
" O7 x( U# [6 ~1 L# ]- a7 J" }7 ?              (command "_.undo" "_control" "_one")
% l; b& Q" F* U+ F            )
& |7 @) b) H5 a$ L  p& q          )
. K& v9 U1 q: |% |          (if (equal 4 (logand 4 old_undoctl))
* w7 u! u; ]" B( ~              (command "_.undo" "_auto" "_on"); a, |3 l2 p: T! G7 M. _" \' H$ }" N% E0 r
              (command "_.undo" "_auto" "_off"). X6 q1 |& _+ G# q
          )
- M- ^4 N- y/ T5 r        )
. _3 ~1 ^  z1 T. f      )
2 a2 C' d$ x7 J' F0 \" l! V3 K      (setq old_undoctl nil)
/ J0 ]& l. ~( K      (setvar "CMDECHO" cmdecho)
* D' [6 B- W; K9 _# g% U. O    )6 `& @# c+ l8 K
  )
' h! r) k% Z  E- ?4 g' c/ D); defun undo_restore  t: @5 V2 W) \  T3 @6 W# g

4 |/ i7 e: M! w& M0 Z1 F;----------------------------------------------------------------------------4 X! O7 p) d. r; [( l
; Save variables
0 a% F- }8 p& E. ~;----------------------------------------------------------------------------
  u" g- q( q" e  p4 P5 W! C8 ^(defun var_save (a)5 p' m. G) b  w* S
  (setq m_lst '())
0 q2 [3 k( S4 `1 }8 L5 ?, b  (repeat (length a)
2 ]% M9 `, O0 Z( c; d! }    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
# @$ b) V! _6 t: O+ ?    (setq a (cdr a))
% H' w" |  W7 S1 `. U: @2 b  )
7 j+ I7 Z9 G" a2 R, N); defun var_save
8 ^1 V; o/ j; N
5 d8 C; x+ o" T( Y& j3 O! U! r;----------------------------------------------------------------------------
3 A4 A% C5 {3 ~' w' h; Set variables# |& N" ^6 ~; _5 P+ _8 g
;----------------------------------------------------------------------------
" V6 e% j. X8 e+ `2 U% n$ G(defun var_set (m_lst)+ A# R7 J/ t6 h" U: l" d1 e
  (repeat (length m_lst)! U  A" r5 H' {' L8 G" A
    (setvar (caar m_lst) (cadar m_lst))
' {9 }( N$ m# |7 g, Z    (setq m_lst (cdr m_lst))
" E0 S' L6 ]* C/ H$ A8 f  )
6 @- S4 S; c5 C  \); defun var_set) g' m5 L3 M) c

9 \  Z% y- u) t% d, E0 y7 m;----------------------------------------------------------------------------
) R' C. g4 ^7 l5 }2 @8 S9 y; Restore variables+ v; t( q" E* k
;----------------------------------------------------------------------------9 `" y/ X6 H5 }" ^# [  _
(defun var_restore ()% f7 g8 U5 Q  Q  L* q; i( r
  (repeat (length m_lst)- _5 R# i& G% I! c# [
    (setvar (caar m_lst) (cadar m_lst))4 K5 w% }5 n1 ~( L  G, n, r& F
    (setq m_lst (cdr m_lst))/ n0 r7 T7 P+ O" O; g
  )
# D- z9 e/ `: _" c4 A0 H# [); defun var_restore5 F: @, ?0 n. I+ _6 c
) u4 l( O* b% U6 Z  y
;----------------------------------------------------------------------------
8 s' j5 z/ O4 q0 x/ W; Initialize routine ) k/ q. n# \3 A% v9 j
;----------------------------------------------------------------------------
  Q+ E3 z+ T. d5 e. @" v(defun err_init(e_lst u_enable add_fun)
; ^# _7 k( }0 B; C* V  (if err_alive (err_restore))          ; To avoid nested call5 T% m( ^: u" o6 e) k
  (setq err_alive T)
# d& n8 X- f2 S# H' t  (var_save e_lst)                      ; Save the modes* z, |& z1 ]; o4 T
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status
" e" K/ q5 q0 c7 G; k7 Y/ F! s  (setq err_old *error* *error* err_main) ; Save the handle of *error*
. M! q, d# k/ M$ M$ b  (if add_fun                           ; Add the user cleaner- |9 Q$ w. _" l
    (setq *error* (append (reverse (cdr (reverse *error*)))
. ?* L- o. g# R                          (list add_fun (last *error*))2 u% k, o% a' R7 g- O" a1 s
                  ); append
- Z3 S! G3 n+ L    )
% ?: O$ S& f1 v& Q( x( @+ N2 W  )0 H4 S/ _0 E- T$ s" N; U
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
0 v7 W) z) m/ E1 K) P; Error routine body9 G1 |1 a* @" E2 m& v" h
;----------------------------------------------------------------------------
' y% Z. G4 [! q! w# [(defun err_main( msg / )                ; Body of error routine5 {9 W. \# L$ a+ M& V
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs0 \, R+ s3 N- T* H! L' \9 N; J
    (princ (strcat "\nError: " s))      ;while this command is active...5 m4 T: a* x- G" G* H/ N
  )& F7 T  s  `3 Z
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command; v! ]# o# u5 r

' i6 W- `: Y, ?" `  (if old_undoctl& F5 ~& t% n$ Q7 F8 m6 R
    (progn+ r8 w  |: B. L! l
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
' Z7 _( |6 h2 j1 A# v$ y        (command "_.undo")              ; if it's in UNOD command
. y+ j: I2 E& i" P% z      )/ K& J, `; b$ y, ~7 w5 b* M4 W
      (command "_end")4 i2 _0 s0 e  x9 p: A) e
      (command "_.undo" "1")# C( R1 Y' c' ~% }9 G' H
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))$ W$ O% |5 `, ^9 T2 q- Y# n' l# O
      (undo_restore)                    ; Restore the status of UNDO
* Y. X2 q# w' c: p# p2 s    )8 {9 }! ?: T4 _) [* o$ g3 W
  )
9 q& d$ r2 }4 g6 e% n' ?4 \4 R* E/ D! z( K% u( |, _5 i
  (var_restore)                         ; Restore the variables
$ x! q2 R; h" h6 ^/ ~  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error* D# e8 q1 D* V* C
  (setq err_alive nil)
- T" e. m) D8 j) P; U  (princ)
8 l0 z  S. s) o6 x+ y$ N) J); defun err_main5 L7 u9 X! M# k1 U

0 Q% L3 h6 i' E;----------------------------------------------------------------------------7 A+ d8 R) a, ?3 D, S6 S0 d1 e
; Restore error status
  s/ [& }! x3 e# M- `6 ^8 l2 @3 `5 Q;----------------------------------------------------------------------------$ ~7 S; K/ @3 I! p8 Z
(defun err_restore()
1 E2 |% h( E8 `  (undo_restore)                        ; Restore the status of UNDO
% h) X/ B4 B# n+ E/ n! ]  (var_restore)                         ; Restore the variables, A; D8 q" G& v6 k6 N8 B2 C
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error4 K# q% l! d1 `7 K; l2 [
  (setq err_alive nil)
3 w7 b; O3 x  Z  (princ)
( j5 t% E9 L# Q8 }) ]8 z  r); 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-2-19 07:07

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

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

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