CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:4 m; T4 Q9 t# T
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
' `, x- j, m( e. s* b- C, O6 g提示:加载成功
$ A' U* z) v+ S5 A: [5 M/ m1 S然后使用CLOUD命令,3 b: u$ |0 Y, c1 L# z; \
提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”% Z5 }: f+ e  M% o% Z
请高手指点一下,这个是怎么回事?应该怎么改正?( C. f) V! a9 _$ g% ~
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx
& M5 H8 p3 R1 o4 Y# X, b8 Y: o4 H;;;' I& l' `% \; }" p0 L
;;;  DESCRIPTION
9 i+ i/ V- k, t' {+ Z;;;     Draw cloud and you can specify the globals variables listed below
5 f- v8 X1 ^4 Q. }& y9 i;;;     to decide the characters of cloud
, A1 u; \% l: h  r* t/ h;;;% q% s0 |6 ?8 Y8 R" X' h( q
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98. ~' g1 L8 x- I
;;;
0 q- F/ X5 _) U/ U  j0 W  @;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
7 B" r6 ^( u% i/ j4 C! M- P0 F* A;;;           Change CLOUD.001 to use CLAYER to perform the same function
( l/ F5 O' @9 I4 V;;;           Use the common error routine UNDO.LSP to optimize this program; {( d6 @# j& e
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
# B/ I6 M4 b) [;----------------------------------------------------------------------------( }% e: E& v: `# \/ v
;  GLOBALS:! Y  p2 A8 ]) R4 t- `+ E0 {4 o
;     cloud_layer -- layer of cloud8 [9 Z6 E% F. [. ]& Q- {
;     cloud_scale -- scale of cloud7 n  @1 x9 Z! L
;     number_rev  -- revision number
& ]9 L9 m* G9 {2 K;----------------------------------------------------------------------------3 r/ g4 E% M4 u5 U  R8 _) P% q$ R( X
(defun cloud (/ locked temp first_point next_point relative_point
" E0 V0 D: T& s               last_point point_tri point_ref corner_1st corner_2nd length_tri
3 E! L- q& ^+ A/ F, T/ ]: `4 d               length_cloud angle_l_to_f dir_tri repeat_count % ?1 {+ a4 h. G! U: t3 w. @
               table_cloud )! b% ~! q: ~; U: p
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))
& Z3 b# x: x8 \          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
: a! ^% x, l" z/ I        );if* {4 E; {2 G8 R4 G, X
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
0 Z8 M. n% P5 H' y, w: g- J, {: p0 ?                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))0 n1 A7 E% Q+ A8 p# ?& Q! V; y
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)" j7 c. D* s6 @: |, x
                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))* j: W+ ?6 x3 v- }' T
  ^. v! k( O5 Z* N) W
        (if (not (numberp cloud_scale))# Z7 n; G! Q+ M5 n8 B& f
            (setq cloud_scale (getvar "LTSCALE"))1 E( k5 X4 B7 x+ R) @
        ); if; K$ x- Z# @8 B# h6 ]4 j% S
        (if (not cloud_layer)- x# t  A" a% u' [& I  v% Y# m: l( {
            (setq cloud_layer (getvar "CLAYER"))2 v' A4 k4 l: l2 w$ o4 J
        ); if1 ]4 ?; ^$ N! V
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))+ h% ]+ H) {0 ~3 V- ~
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))7 b0 ^0 n8 i# ]
        (if (= (cdar (laychk cloud_layer)) "No")
7 _: L: ~8 C; }" R4 A4 O' g5 X          (progn
% Z( B! l, Q( d# C' Q            (laychk (setq cloud_layer (getvar "CLAYER")))
4 b9 y3 ^$ F  |( w            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
0 y  b' m' [  {3 q% G: q          ); progn
- V( {6 `+ O: p# ]        ); if0 r) Y* K* E8 n9 H! r# q" s; ^

- q% P/ M* g+ h8 t- d/ O        (while (/= (type first_point) 'LIST)
! k( i# n  ?% q% O! o4 E3 c          (initget 1 "Layer Scale")9 V  @% }) Q) \% }( P
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
" [# Z4 z7 I( Q+ x" f          (if (= "Scale" first_point)      2 P: X2 W% y4 D0 N$ U
            (progn
2 ]( ]0 t# G" r! y+ v. D              (setq temp cloud_scale)' R2 e- w3 i- k  q( \) q
              (initget 6); W" C2 O& t0 \0 N# O2 ]3 W
              (cond$ l( t' e% ]+ i& g) `$ N, P; I
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"0 t9 t4 S+ x2 `; F
                                                          (rtos cloud_scale 2 2)
/ ]1 C- Y2 K; p: |0 \                                                          "> "))))3 @1 D# ?: W& z0 M
                  (setq cloud_scale temp) ). i8 w" L8 b( L( q1 H& M- H3 c
              ); cond! X  P0 e( h( E( R
            ); progn
& P# _; U- `# W. y0 q8 u5 c          ); if
  _7 F/ }, g1 v5 s5 H          (if (= "Layer" first_point)
" D" W. u$ q$ N7 r! U- Q9 k            (progn) l& P! d3 A/ q, O4 F
              (setq temp cloud_layer)
  u8 ^* _9 h$ _" @/ ~% |0 R+ ~+ K              (cond
. A8 k  n) l3 |2 B0 s                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
! r4 k% z$ q0 i0 f" t( x7 ?                                                          cloud_layer "> ")))4 @7 {% J+ \+ ~  x1 C0 K1 a
                     "")9 z8 D/ T, Y$ j9 W2 T4 V
                  (setq cloud_layer temp)
/ i6 Z' f! \7 W4 K6 c& C- x( n5 H# [9 C                )
) i+ t+ q, t2 G4 l, t              ); cond
3 M# B; n! n/ ?( V8 g              (if (= (cdar (laychk cloud_layer )) "No")9 v. L, Y+ M! j3 W, ~
                (progn1 M( x6 k  l9 M
                  (setq cloud_layer temp)' q' U6 l' {+ _7 s
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
2 F+ R. J' |9 h2 M" u$ A7 J                ); progn. Z+ K4 V, H. k5 L/ N
              ); if
1 ]# W: p/ i+ o  |            ); progn9 ]8 Z' `5 U0 f, L3 b( r1 d4 p" y
          ); if) h5 I6 ]6 V& k7 }6 v, r
        ); while8 j8 L7 l8 W1 j, I# v9 v
        (setvar "CLAYER" cloud_layer)$ d6 ^2 g3 d+ H: A% _

! y0 h7 V7 n. z5 Z2 j        (if (>= ( getvar "LUNITS") 3)
  H" z" t( c1 T' f  B  y# g! H% y) \          (setq length_cloud (* 0.25 cloud_scale)
- |" O+ I: u  ~, ]. f                length_tri (* 0.3125 (getvar "LTSCALE")))+ L" N3 h/ L! _# K% [
          (setq length_cloud (* 0.3406890 cloud_scale)+ A2 X2 d! A1 ~8 Q8 B6 C
                length_tri (* 0.438366 (getvar "LTSCALE")))% {* m! m; e& U1 N
        )
, L" S( u/ K0 f! h* ?) r2 n        (command "_.PLINE" first_point "A")8 ~$ i; f2 g9 }9 D) h
        (while (not (equal next_point first_point 0.000001))0 t  n+ L5 m, Z
          (initget  "Close")  c) H6 _& F; d! J+ p
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:")). U5 f/ O4 `3 N& S& V; B
        (while (and (not (listp next_point)) (/= next_point "Close"))
! k$ E0 e1 r( }7 S* w7 ~4 i          (initget  "Close")
9 h$ v5 F2 S$ N          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))) g9 L, u% N* H4 v2 ]
        )$ B* m) Q# V+ J& V4 X( r+ J: I8 u4 v0 J
          (if (= "Close" next_point) (setq next_point first_point))
. L3 D. V* ~* X8 }5 o- H          (setq angle_l_to_f (angtos (angle last_point next_point))  ]7 c$ `3 _9 d; ~
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))3 b2 j( p4 y1 H4 ^; }3 @) T
          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
. U) Y# i: j! h" J; A             (setq repeat_count 0)0 J" v( n1 d4 j; p0 d
             (if (>= (- repeat_count (fix repeat_count)) 0.5)8 e7 F7 p) G; B) F, X: k1 g
               (setq repeat_count (fix repeat_count))
) ~+ ~; o' |" t               (setq repeat_count (1- (fix repeat_count)))# q* Y! e; Y7 k* P' M8 d
             ); if 0 X: X+ ^1 y$ H+ r, S% q3 ^0 ]
          ); if. O9 p3 z7 h5 T- Y  p; }
          (repeat repeat_count (command "A" "-100" relative_point))
! a0 s& V/ d4 ~) s          (command "A" "-100" next_point)
( ~; s, }4 V7 j9 g- E! |* O          (setq last_point next_point)
' m6 U) M5 c' U9 Z4 }. N$ S        )* Z/ D6 i$ ~: U4 k5 D  g/ M7 J
        (command "")
4 T* y" _: j# a& u2 f& O        (if (= (type number_rev) 'INT)7 F7 }( [% ^8 h/ P6 w
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))7 r5 W5 _7 o$ e; r
           (progn) j% J4 V7 ^0 J: c& Q) M
             (initget 5)
$ J- N5 V$ d% m5 g0 `             (setq number_rev (getint "\n请输入版本号:"))
5 k8 ^/ t8 Y' t) d4 z. q; p* O9 C           )
+ ^5 z1 @3 N7 @1 q! _2 b6 S% X1 C* L        ); if6 Y7 t1 m9 _: Y8 e& R+ Q
        (setvar "OSMODE" 512)3 i) g( G' V0 n- v
        (while (/= (type point_tri) 'LIST)
  s; n0 G4 @+ k; u4 w          (initget "Number")
' T' `, m. O( ^  P1 K! c          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))4 [& ]. W; v- w$ }* h
          (if (= point_tri "Number")& q" u0 y9 O+ D( x! I+ E0 p
              (progn* |, {; N+ y' y/ }# m
                (initget 4)
; m% [1 `9 P0 z                (cond2 m5 t8 V7 P* f  l! c6 h4 k
                  ( (not (setq temp number_rev
7 ?- O% Z' h* V  ~                               number_rev: N* I" s5 W3 c8 `  g& t
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))* `7 O9 F# o; M7 U! s2 f9 p
                    (setq number_rev temp)
, x5 {9 c6 P" ~. ]/ p+ L                  )% |; b$ o$ ~5 b" i- U  y/ M0 R- A
                ); cond9 L' F9 A) M6 {- m9 N- \; @1 D
              ); progn& q& r& A, G1 a% a0 B# N; ~
          ); if% w0 F$ Z: g; d$ _& o# ~* v
        ); while0 B$ t: T/ ~% F( c: `7 J5 x
        (setvar "OSMODE" 0)0 v. B( _5 k; s$ |. R
        (initget 1)$ y+ i" A' g% t0 C
        (setq point_ref (getpoint point_tri "\n请选择方向:"))( _. @7 X) ^* g
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1)), @/ U1 j( p' C: p. ~
        (setq corner_1st (polar point_tri
+ d- b* j0 G: L                                (+ 1.570796327 (* -1.570796327 dir_tri))  a6 ?$ k1 n" C; u, o
                                length_tri
3 r( z: W! Q( B! E8 S* R) C" \, l1 o                         )6 V9 U, p/ ]$ g- p, N
        )
$ H  F, o% @% q3 G/ a5 y7 ^        (setq corner_2nd (polar point_tri
* J7 Q9 V7 S! _* m$ `                                (+ 1.570796327 (* -0.523598775 dir_tri))
, Y( Y1 \3 M0 V                                length_tri' e3 z0 w& K- \3 e9 g1 K
                         )6 `9 j! |8 K0 b! k6 ?4 f0 k
        )9 e& z  y) ^: r, I3 `- P  D
        (setvar "CECOLOR" "2")9 G& i" l$ d$ b. p2 v- Q6 ^/ ?
        (command "_.pline" point_tri corner_1st corner_2nd "c" )) j2 C0 J9 N* l6 f" D& _2 w# Q
        (setq textstyle (getvar "TEXTSTYLE"))
' h. U( D. J- m2 {+ O. k        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
: Z; h4 n6 p( M" x! m. b( U  C7 Q: b9 T        (setvar "CECOLOR" "7")
2 R" y* l$ s2 T, ~        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))4 a0 [7 A( J# p1 l+ A1 p5 `# E
                  (* 0.4 length_tri) "0" (itoa number_rev))
- O! A6 [7 S( _7 g2 i9 R1 b2 W        (layres)
$ p+ i% e# b2 f9 G. u0 {        (err_restore)1 C9 T! [$ K) s. J( A7 \# g; R
        (princ); s: `5 y+ x; Z5 q) u( L  E2 S% o
); defun cloud0 o1 ~! {7 ^; ^' Z

3 p- N  W8 p; N% ^(defun c:cloud () (cloud)); }, {( g# I4 ]" @: z" _4 G
(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy, G7 j" S  n& O9 L& |" m% Q  `
;;;/ w" x0 U7 I, Z3 A
;;;  DESCRIPTION0 }* z% F/ W5 `. }
;;;     These are general error routines which can be called by
3 z6 N" ?( m3 ?& b3 E;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference9 \3 q: k8 ~7 C. A
;;;) Q% P/ H. ]4 a2 H
;;;  SUBROUTINE INCLUDED IN THIS FILE
4 {) f, L" q# b0 i;;;     UNDO_INIT
# l# t. b& m2 W( _3 f;;;     UNDO_RESTORE
  A; R! t* x2 P1 t7 }0 _2 o# };;;     VAR_SAVE
' R+ G6 w- [" {# {;;;     VAR_SET  
5 d* v, p; r0 J! q8 M;;;     VAR_RESTORE
, J/ X9 {% @3 i$ p) D;;;     ERR_INIT ! g0 K9 [% F& g- k
;;;     ERR_MAIN
5 o" n6 M) |5 q1 k9 V. E$ V;;;     ERR_RESTORE
% O9 J% i+ V: f5 [. d;;;* V9 u$ |7 p: G5 f+ ]6 D$ s# d# A+ K" ?- X
;;;  DATE: 10/17/98; 03/31/999 k* Y. Y1 j7 E
;;;
4 K5 M, e% _0 J6 ~;;;  HISTORY:
. f6 |- y4 w- |* R6 X;;;    Add routine of mod_att
' w9 S6 {$ C! F; V;;;5 I3 E$ D$ [% q; q+ V3 @1 H
;;;  USING METHOD" {7 s0 B1 ?- X* _6 z+ v, l6 X
;;;    ERR_INIT:* ]! T& p' }: p; c4 V
;;;      This routine initialzes the error handler. It should be called as:9 _7 ?8 h6 Y$ t- @/ q
;;;( _0 H# N9 J9 n' ]% W# U/ X) |
;;;      (if (and (not undo_init)# E. e' L: k9 {& z9 V6 r$ V( o
;;;               (equal -1 (load "undo.lsp"  -1))
3 D0 r& R+ K5 Q9 @+ R4 A* ]$ _' j) a) q;;;          );and
$ j2 F3 @" R9 X, a; J$ [4 U;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))7 V% a( j0 ^4 _3 S! k' a. `
;;;      ); if
2 D7 ]! X, A- D( Z3 ~* F;;;
* c& w. c+ `# ]- w+ X' y* n8 g;;;     ARGUMENTS:' O8 O1 ?, H1 f* b: p2 p: T
;;;       err_init Takes 3 arguments. 4 y) Z; R# i4 Q  U
;;;     1. - The first element of the argument:# q2 |' g2 {% d9 b' e
;;;          This is a list of system variables paired with
$ i; g7 M) u& \;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE"). x6 e- o) p1 o
;;;     2. - The second element is a flag8 a# d! W4 t5 O" z" }. k
;;;          If it is true, then in the event of an error
- K6 p9 Q& p  U' S( F$ o6 O;;;          the custom *error* routine will utilize UNDO
5 Y. Y* s/ ?& Y0 S# `3 A: _;;;          as a cleanup mechanism.
1 ?( t5 e9 |, Q  S& C' R;;;     3. - The third element is a quoted function call.
$ F/ H! M* h" C1 J( m! T8 A! |9 E;;;          You pass a quoted call to the function you6 j3 E" F( p8 v& p, |% c+ _, C+ T1 M
;;;          wish to execute at the end of nomal routine if an error occurs.
2 y# R/ Z/ H3 z/ J' u;;;          i.e. '(my_special_stuff arg1 arg2...)8 J* ~% W; y0 t$ _6 I# |7 X+ @
;;;          Use this arg if you want to do some specialized clean up
7 ^8 x. ~1 L# {! H% z;;;          things that are not already done by the standard bonus_error ! F% Z- N, h; k6 C1 t& I
;;;          function.
1 w; [6 N/ z3 B& `( q;;;
' ?, d4 {, t; b;;;    ERR_MAIN: Body of error routine3 \2 W3 G2 t  X; B
;;;8 _$ _, v! P$ I* q" @1 |6 I" k5 j& P
;;;    ERR_RESTORE: This routine should be called at the end of command to
3 ^% w" u1 W3 ?8 ~3 j9 c;;;           restore the VARIABLES, UNDO & *error*.
5 S& v4 ]. x# e; u2 G% K$ V;;;
6 s2 I2 P7 s' X;;;    UNDO_INIT: Initialize the UNDO status
7 G8 e: T. X4 Q) y0 @7 [! d;;;1 a; @2 {* S5 S& s
;;;    UNDO_RESTORE: Restore the UNDO status8 O& f' l2 _  \  g  j- A- z1 a# r
;;;1 G. Y* ]" f# k4 \
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")# w  O7 _7 |$ i$ j& N: O
;;;
# p4 f" }: O( \. y3 e- V- b;;;    UNDO_set: Set the variables. the argument is like
# I  L( C4 g4 F;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
, o6 H2 ?3 V' G: X5 _;;;- m3 S- s1 ]5 b0 }6 R4 D
;;;    UNDO_RESTORE: Restore the variables. c+ f1 T8 g# p2 P
;;;
& U5 [+ T" v8 x) b1 y9 L9 e8 P9 E;----------------------------------------------------------------------------
, e5 i0 o3 K1 H;  GLOBALS:# V+ r7 L5 d7 g# ~5 N  R- H3 J* G
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
4 m" ~/ c8 a8 d' t& m  w$ r. ~' s4 y/ F;     m_lst       -- list of variables (voided by VAR_RESTORE)
: o* O% [+ Z4 I9 \- F- T;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or7 k1 D& L; G( F7 F( `* ^8 W
;                    ERR_OLD)  h. k- T, p* w& D% H
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)( y3 r: L* t7 s8 |( o* e
;----------------------------------------------------------------------------
7 W0 q  h4 @1 [, b# b
6 R4 R3 k1 P" b. ?  {: r;----------------------------------------------------------------------------
$ c  N2 e) k, ]; G# Q" K  H; Modify attributes according to entity name, attribute name, dxf_item1 W: s& D7 D+ P$ I3 T% j- o+ Q
;----------------------------------------------------------------------------$ [. E2 o' W3 O- C& ~- a5 c
(defun mod_att(ent id dxf_item)        $ [/ e$ D- Z- R" d; y0 h
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
. l( S5 I; J2 w- b  U& G+ w) ?    (setq ent (entnext ent)): M) Z/ Q9 f( T. A* c5 }
  ); while  
# \7 U( d: U: e' V  ((lambda (x)
6 O; ^4 T( d: i. a6 I! Z8 Y        (mapcar '(lambda (y)8 f2 N( k7 C9 K# h/ M/ J7 ^. u
                   (setq x (subst y (assoc (car y) x) x))
/ f! X4 ~$ Y% d                 ); lambda
* p8 V0 {7 V# @& o5 Z' ^( o                 dxf_item
" i9 ~9 [) B! d9 c; L2 ]        ); mapcar' n) P: U4 `  N) C( O
     (entmod x)
- L) Q1 r% W- C7 n     (entupd ent)
5 {7 w; M: [# Z* V   ); lambda
" N4 r9 y. a+ I2 O; J   (entget ent)
1 t' G, B( }  R( B )
7 d$ t( A! T% E& {  i); defun mod_att: ]7 u, U) P5 }7 A4 O  Z
- |$ b. y& f4 T; M& L5 C% o
;----------------------------------------------------------------------------. f* ^9 [  ?" W
; Check layer status, return a association list which contains layer information
2 t' M0 t5 ]) B5 f) _; O;----------------------------------------------------------------------------
+ i8 C) V& \, S: E(defun laychk(lay / l_sta)
! j3 T- n" K! b7 C2 e  ( (lambda (x)/ a- O7 v5 O! ?. c4 X$ M
      (if (not l_s)- b# B3 M" V0 ?; R. U- \, H- Y* \
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
# H8 J% N, C6 i8 Q+ c7 e2 l& {      ); if
, L' Q1 A4 M+ I    ); lambda
# P) w# {/ C9 d6 c& L, F    (getvar "CLAYER")
5 i0 W) ]# M' z7 D& ]  )
! `7 \0 M, r" }7 |8 w2 ]  (if (not (tblsearch "LAYER" lay))
- q8 j. G& f9 n2 Z  p    (progn  
/ C- x' E  N  i. I      (initget "Yes No")
7 D: t$ Q0 F" Z, \+ d      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")" r, v- l; h8 }8 i( ?$ C
        (progn
/ w6 _  n1 L  L% L  C% k+ J5 N          (command "_.layer" "n" lay "")7 h. O  `5 M, t+ m$ M
          (setq l_sta 0)
. {/ ^8 Y" B" q# a5 Y- Z( y, \        ); progn
( \9 s) S4 x% q! E% m      ); if4 J0 Q" x1 U, }% c; L
    ); progn2 ~" n7 I$ U. J. n7 n, p' A; g
    (progn
! ^" p9 N* S9 [- q# g7 ^$ w( w      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
, _, W, b& g9 \( _, \; H( f      (if (= 1 (logand 1 l_sta))
( N& S+ k- B7 W& [          (progn
, R- ^+ E; A2 X' c0 h            (initget "Yes No")! P6 k: @% P/ d% Q& }
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")
' E1 A( G- q. e) P, |: y              (command "_.layer" "t" lay "")
" D: H, ~- t( J2 K, f              (setq l_sta "No")( J$ |. h' W' ~5 E" C/ e
             ); if
% O; R  }( f1 z          ); progn
3 n& b# a/ Y# E      ); if
7 q3 M4 r' R% F! J      (if (numberp l_sta) 0 j1 ~! Z4 b9 W" o& Y2 x4 Q; q
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if$ x7 }4 [! m% c
      ); if
9 t9 C4 e  q) |- [+ y3 h    ); progn
: C  m  L0 z/ @! B# C8 m3 g  ); if6 C4 M( l, [* h  K% r
  ( (lambda (x)
7 |# I  E% j: |9 T2 F      (cond 1 r% X4 o5 k$ J8 x0 b
        ( (not x)
: n. }8 P" f5 o2 {, l          (setq l_s (cons (cons lay l_sta) l_s))
# w, D* _" D- L        )
+ m( ^5 E8 U2 H3 d7 s        ( (= "No" (cdr x))
5 o, f2 L/ a% ^0 b7 U          (setq l_s (subst (cons lay l_sta) x l_s))3 h" _8 }* w) U, ^# I
        )3 p( ~8 Y( C1 D2 q1 V
        ( T l_s)+ Q& j( y; ~# u# W0 ~
      ); cond% o/ W( Y" U2 O/ J+ ~! B- Z5 M
     ); lambda
6 }' S1 r1 e% p5 Z3 b- Z1 d* f     (assoc lay l_s)/ A7 ]+ O# u9 }3 `" y1 J, S
  )( k" z) N& \5 L9 a5 u

: t; M" G$ m) _5 @# B. j; t' r); defun chklay
$ O  I4 P# ]# Y9 W  s% [  V! l! ~% f9 Q7 v# b  B( B$ \
;----------------------------------------------------------------------------6 h6 J3 e, u& J, q; V0 S* a
; Restore layer status according to association list l_s
- j& ]* s+ c" p' c" C! q;----------------------------------------------------------------------------1 m, k  i+ @, z! ^( A1 w4 a2 O- s. n
(defun layres()
0 L: N  e. H8 d. |4 I8 @  (setvar "CLAYER" (car (last l_s)))
* o0 a5 y  n/ O4 h  (repeat (length l_s)
! A" Q$ l- n2 H    ( (lambda(x)  - y0 M5 B6 `# K6 \
        (if (numberp (cdr x))
  E& L- B6 r4 _  t          (progn 2 `1 Y  s! d7 g/ ]1 |/ a6 D( p7 M0 \
            (if (= 4 (logand 4 (cdr x)))
" L6 n, e; I# _% O              (command "_.layer" "lo" (car x) "")
  `9 y' d' ^( X( e8 C8 A! |1 N            ); if/ L% H1 M5 |: E) k  B, t" d1 e
            (if (= 1 (logand 1 (cdr x)))
, U, v( B) E. X/ w* p5 ~( a5 J              (command "_.layer" "f" (car x) "")
$ P& e! A0 }9 j" ]' d            ); if
& R6 }* V% N/ T9 _& P          ); progn! D* H9 L6 `5 |8 K' q
       ); if  
5 w( |0 a7 u/ }2 h6 }: [      ); lambda& L1 ~1 c; A% l
      (car l_s)/ s- A& V# q; z# A% t: `. W( J5 J
    )7 R1 |6 Y: z6 f) \( H# a8 L9 \
    (setq l_s (cdr l_s))+ `) F0 C, `% Q+ M5 I; g% R
  ); repeat
  i7 j+ E4 k7 m); layres
% S* @0 }( C* P
' u  m9 V% O4 |6 O! \: O;----------------------------------------------------------------------------
% l# W9 T3 w$ ?. l/ J; _; Get DXF codes: g% D2 h' M6 u- Q& x* X
;----------------------------------------------------------------------------
. E( P4 Z  z9 x: r7 z, c/ [6 B(defun entgetf (index ent)
  j+ g; x" `0 J3 u  ((lambda (e)
  h$ ]1 s+ t- @7 i/ I* k4 A( H      (mapcar '(lambda (x)
9 O" S' {' f; Z' f/ `6 L& G6 c                 (cdr (assoc x e))* g: H  `( l0 y/ m+ P5 x
               ); lambda" Q# J% Q- d( W  s, N. g
               index) ; internal lambda function
0 T* v: Q. P! q( _4 @    ); lambda5 B$ F7 X  q, }
    (entget ent)
; c  N, q# w  g/ G% k; [1 _  ), Q% X" s  G8 z( \% E0 M$ K
); defun entgetf
! p: q$ L9 g/ Q  Y
. W8 u9 y/ _. ]3 o" h;----------------------------------------------------------------------------
6 u6 d8 ~& C; S" P& ]; Save UNDO status
! T" l' p* |! I3 ?;----------------------------------------------------------------------------
; j' t: {4 }3 S) v(defun undo_init (/ cmdecho undo_ctl)   
4 Z6 I+ q) ]% m$ B3 w  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
7 I; K# C2 u& K5 g  (setvar "CMDECHO" 0)
7 G: k' u! k0 N" C8 _) E
' J) W' _/ h3 T& x. \, G6 u- S9 x3 D  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
/ @1 ]2 o+ w3 E+ {: c    (command "_.undo" "_all"); v. m& T! N6 [; N/ d+ I+ N
    (command "_.undo" "_control" "_all")  ~) x( r$ X+ [; D/ w4 v
  )
' B2 U7 u' g( ~' P/ _2 ~2 G& ~- g* X3 o2 a
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off
. w! B( @& c7 e5 ?# W' Z    (command "_.undo" "_auto" "_off")
( K1 H% R. Y) s( y+ t1 c4 w  )' L: e$ k5 o* N- a+ ]+ m
0 _) L3 _0 b  q& U1 a
  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
* {2 ?& U0 y* V1 B/ @& y* E6 i8 w    (command "_.undo" "_end")
/ U; A! z4 b& A3 z' B  )
, y) A3 y, Q+ N+ S  J0 I2 ~
6 a( h0 F% d, i! R% x8 p  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))) k" z1 e8 t$ r, {7 n$ A9 O
    (command "_.undo" "_group")# `) k% h& ~" ^3 B
  )
$ d1 ~) K0 q0 {- V
' J! V2 n& C! v" A3 x  (setvar "CMDECHO" cmdecho)3 _' u  T+ E1 }/ z# U7 E8 w
  undo_ctl# o9 U* I( i. a/ H) O& X! X8 {
); defun undo_init
- G( Z: N- a/ ]' k7 q3 D$ G; I% ]* G; L% t% V; r
;----------------------------------------------------------------------------1 K! w! N2 ]/ `8 F) m
; Restore UNDO status6 J! U2 O2 a0 u( p" p
;----------------------------------------------------------------------------3 Q. ]! r. ?+ h
(defun undo_restore (/ cmdecho)& D& {( M7 Q) o, w- f
  (if old_undoctl
: h$ K& A9 }/ |& k& V    (progn
$ f' F6 {% ]' ~# r. W8 _      (setq cmdecho (getvar "CMDECHO"))
) j2 }- j3 h0 P3 A; H      (setvar "CMDECHO" 0)
* Q8 l! \* |, H4 o% ]- M) |8 G, I' n/ E
      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) . |* w6 I9 ^* i
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
: q' w8 C8 b3 g/ ~( ?9 G        (command "_.undo" "_end")
0 ?8 h$ g8 J5 d0 t2 H. k      ); while
  v# e( H5 ?' _- Q. e. d+ R5 y% e8 W1 u4 n# I
4 c- W2 d' q: I5 }: Q
      (if (not (equal old_undoctl (getvar "UNDOCTL")))1 W% ~- b0 y- J; v2 p  l3 |4 C
        (progn
, r/ Y$ L% i4 a# N4 a) G; C9 W& Q, b* G          (cond
3 m( d1 h# X  e( D; l# x" P1 d            ((equal 0 old_undoctl)
8 B8 @8 \  T8 g              (command "_.undo" "_control" "_none")) s. ]5 p; O! ]; N- d! a; n6 j
            )5 E0 ~0 }/ z# C& A3 X1 N
            ((equal 2 (logand 2 old_undoctl))
% A3 x8 Z. Z, y6 o, X; t              (command "_.undo" "_control" "_one")
& M& H! k/ T2 j            )
, g. w& d7 U0 _: N' J7 _8 l- O          )5 z! H! `' k. ^: J
          (if (equal 4 (logand 4 old_undoctl))9 A9 _0 R5 M+ t! t# {" N6 {6 n
              (command "_.undo" "_auto" "_on")
4 I: Y& z$ M* Z+ Q) {              (command "_.undo" "_auto" "_off")1 T7 A% }4 ?# H! |
          )& V; f3 D# A* s5 w  o( b$ H
        )
. x! X3 W" w% T$ ], e% I2 s# Z      )0 L; }3 F! v# B* X+ E! K7 b
      (setq old_undoctl nil)0 n1 j& q' h- X) P: u7 L' B
      (setvar "CMDECHO" cmdecho); m8 X  ?% e" C, v# R8 u
    )7 t/ {+ m7 [& g. ]; n/ g+ }
  ). j% ?0 a' L# Q3 D+ \
); defun undo_restore9 k, V( i$ B- A- r5 U, N
% G/ E) O" c! l5 h1 l, u, f! K
;----------------------------------------------------------------------------+ X; C3 b4 B, N5 B, N, M' r
; Save variables0 d% g8 J( s" c
;----------------------------------------------------------------------------
: w5 q# S& F( G1 K" E9 {' B(defun var_save (a)
7 g) W# G& @0 U0 x1 L  (setq m_lst '())
+ L% {2 b) h  l7 g  (repeat (length a)
5 j0 C/ W0 F6 K1 e' L    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
2 ?& p1 U% _$ W. g2 N6 B, v; ^3 |$ x! b    (setq a (cdr a))
6 B8 H1 j" i( J  )
: i" g1 S2 ~' V: |/ g. n) L- J- R4 E); defun var_save/ ~6 w, P6 k6 l0 I! v$ W, v
+ u2 t' j8 b" n
;----------------------------------------------------------------------------: A& H0 y4 N/ c2 w
; Set variables
( u& C5 N* a% W" j: S. ^;----------------------------------------------------------------------------, m( w( I4 V+ r; g* g
(defun var_set (m_lst)
  g  h4 I$ \5 |8 k  (repeat (length m_lst)
  S& B" f; D' p2 r& |( z6 k% Q* ]    (setvar (caar m_lst) (cadar m_lst))
: I, r+ B% L3 J$ l+ T    (setq m_lst (cdr m_lst))8 S; w+ q- q+ z% d( y" N$ H6 l
  )
* V8 o4 x3 j/ x); defun var_set2 O; Y1 h( R$ r6 R$ X4 s
0 \9 k- G1 d$ M7 T- v6 P8 @. h9 w
;----------------------------------------------------------------------------3 I5 J  b3 u! ^0 ^; }$ i
; Restore variables
* V' P  n" o7 q' z5 ?* L  u* b5 O;----------------------------------------------------------------------------9 P  {% U$ r. A5 o& n/ x' V
(defun var_restore ()& d8 l2 e& p$ M$ q
  (repeat (length m_lst)1 D1 Q( z9 v7 J" j0 v
    (setvar (caar m_lst) (cadar m_lst))5 y% h0 t; M+ G$ U3 `
    (setq m_lst (cdr m_lst))
) H; |" V8 ], f* E. W, p  )& N3 b5 M; z: A6 G; X
); defun var_restore1 }, w) [' G3 s6 t1 @% F% C' F
: x: q, {' y) o1 N( H6 k
;----------------------------------------------------------------------------
9 D- f" j' o) A$ h- B; Initialize routine 2 ^! G3 a) @% B
;----------------------------------------------------------------------------3 o7 ^$ m& v/ \. u0 B* P! I
(defun err_init(e_lst u_enable add_fun)( s' }5 H+ G( }! M! N7 B) a6 T: y
  (if err_alive (err_restore))          ; To avoid nested call
! y' G2 L# X0 j) ~( X7 R& R  (setq err_alive T); K& J% _* U7 l, `- Z
  (var_save e_lst)                      ; Save the modes
4 S0 `' D% R' H$ E  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status
* f& J# _; I7 @( B: M+ f/ [' G5 `) E  (setq err_old *error* *error* err_main) ; Save the handle of *error*# f. C( ^4 x& q% Q8 U& m+ B7 o& V9 t
  (if add_fun                           ; Add the user cleaner
: ]1 g: K7 o% S$ B& h% k9 w& }    (setq *error* (append (reverse (cdr (reverse *error*)))
1 _  V/ e7 q+ l                          (list add_fun (last *error*))
: m: U# V% B' ^4 F9 @4 Q                  ); append
3 H1 V3 I0 k, C( k. U5 X3 W    )
+ Y. d) j5 h% O, N6 j  ); q( n5 e& M; P3 o0 c3 s1 E
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------- V% }, n* H2 c' F. i
; Error routine body9 Q* n1 G8 X& d7 O  x0 w
;----------------------------------------------------------------------------4 E' j$ o, g2 B) J  F. M
(defun err_main( msg / )                ; Body of error routine) o0 Q9 P- e+ h) I5 |/ f- h% w
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs6 W' E( \% q4 y4 e
    (princ (strcat "\nError: " s))      ;while this command is active...
5 e) k2 P0 w# n  ); K$ z3 r+ F& b! o; _6 y
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command6 |& i9 C- X! q& I. @/ j2 ]9 i' z, V

- r8 l$ w0 Q0 ]1 P8 |* z9 c  (if old_undoctl/ t: \  z, x3 \' s+ W
    (progn
/ r2 ^* G  J' C2 _, j      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
' o- }9 D. X' w* B        (command "_.undo")              ; if it's in UNOD command3 }+ U5 n! g! R3 H
      )
" @3 |9 @; l  x0 ?; |6 O! A+ P      (command "_end")" x) o- u/ L. r! I& ^
      (command "_.undo" "1")
& a! v" h* t. R0 r4 m& V      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
  @5 W/ G5 m" w5 `' w) m7 X      (undo_restore)                    ; Restore the status of UNDO
) A) V- y# z, @+ s: g    )3 W2 K/ T) _- C1 g
  )
0 O3 ~* ^( d; h8 x3 Z; h; X4 h5 P: S2 i6 e' W
  (var_restore)                         ; Restore the variables
% a( T/ b& y  A  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
) R# s1 D2 L7 M5 S5 Z  (setq err_alive nil), c4 H6 b4 {6 z5 G2 a; g
  (princ)0 a2 E8 p6 j' l: m. C9 Z. R4 \! K
); defun err_main
$ J- Q: B- w" ~0 {8 {) A
  k# y" z6 D$ m! v+ w% t4 S;----------------------------------------------------------------------------) ?  q6 n/ |: n$ j, p- p
; Restore error status& i  d! B7 Q$ v3 p) h# w1 I$ t
;----------------------------------------------------------------------------
1 \2 h: d3 \: Q: d7 @# G; ^  k(defun err_restore()$ E! A( \/ O- J
  (undo_restore)                        ; Restore the status of UNDO. {0 A" w0 \' J* Z* v3 l
  (var_restore)                         ; Restore the variables1 \3 w% c  |0 [) l  R, k0 ^
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
( E. _0 @! e. a" C4 R; {  (setq err_alive nil)- D% e' q% X4 J4 a# N2 \: j& ~( R
  (princ), _: U6 l6 a. J: ^& L- F' T3 y
); 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, 2026-5-16 03:28

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

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

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