CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:0 ~8 |' E" _! @5 s) s8 W, E
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
' v) E! e  A2 \! ]) i+ g0 h提示:加载成功' K- Y" C# `  S, p7 T( n% J' E  Z6 a
然后使用CLOUD命令,
8 B: A1 B! S) w$ d1 `提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
+ o! m& X7 Q+ S8 c8 l+ c请高手指点一下,这个是怎么回事?应该怎么改正?% K) u, {0 G. V- _9 g
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx% V0 U: T& P, w: g& ?
;;;) y$ X% V/ ]" ^+ w. Q) Z# V5 a
;;;  DESCRIPTION
2 P$ ^* j  g3 p;;;     Draw cloud and you can specify the globals variables listed below1 i/ v+ K! M' q1 {$ N; o0 F
;;;     to decide the characters of cloud* H* `* P% ^' e/ x
;;;
. t: }) D. J: m, d8 o1 z;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/984 w# b6 P0 ~2 p) z, h# v# @) N1 ^# P
;;;
8 ^) Z) p/ P' _; j! n;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
3 H2 K/ Z; a* n" [( d$ b;;;           Change CLOUD.001 to use CLAYER to perform the same function6 k! J8 y4 n  l/ A" x
;;;           Use the common error routine UNDO.LSP to optimize this program
, M% d1 S0 f* G5 ~1 \;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
* {' C# B3 F0 n- k1 y;----------------------------------------------------------------------------
% [" b5 U. j' E0 t7 K;  GLOBALS:3 v6 Z  Q$ q9 T' s
;     cloud_layer -- layer of cloud
6 O- A# g8 @! ?3 Q/ r. X+ O1 z;     cloud_scale -- scale of cloud# M; C, H8 _+ z3 }
;     number_rev  -- revision number& |. e$ r* S$ G% D; d) @  L' ]: T5 e
;----------------------------------------------------------------------------
5 C' c1 }8 ?3 H5 W( C5 t(defun cloud (/ locked temp first_point next_point relative_point3 q9 O, N% w+ Z: M) @
               last_point point_tri point_ref corner_1st corner_2nd length_tri
5 M) J. y) n4 j: o* W1 Y+ c" G# X               length_cloud angle_l_to_f dir_tri repeat_count 9 T: a5 Y9 w2 H* t
               table_cloud )" _( M0 B& ^8 x! g6 p4 A
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))# u. }1 i. n& @, }+ a
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))( k9 Z% ]( M; X! H2 c7 U
        );if
  n1 R. U+ T) S; m; {4 ]$ R        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"9 P& J8 Z8 u7 S* M' ]
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))) R/ x! m( a6 R! A: t
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
- Z& e$ P( Q8 N% w; t                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))5 x9 N& {7 m) l0 y

3 w* O$ D" h' T! P        (if (not (numberp cloud_scale))- X; Q# C5 F3 ^
            (setq cloud_scale (getvar "LTSCALE"))
2 M8 h8 P+ V+ E. `8 R        ); if
5 X* ~, K) u1 S9 C4 z# [        (if (not cloud_layer)
9 i1 n  E7 X" M  C+ B- d; m            (setq cloud_layer (getvar "CLAYER"))
4 {0 o- K: a- P3 O# O& M+ b; E        ); if( k9 [  P' r2 P* o8 L9 }0 s
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))7 w6 F: d/ U6 H; ~* {! T
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))8 ~6 {1 Z0 S9 n. \# ^, \
        (if (= (cdar (laychk cloud_layer)) "No")' k% b: {" z- n1 s/ l
          (progn
9 m  w' G0 |5 O; I8 v; i            (laychk (setq cloud_layer (getvar "CLAYER")))  Y7 U! b% S' W1 t3 d$ `
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
6 f. E$ @& F% b          ); progn; Y! l/ W7 _& o$ N
        ); if
% m4 T( n* o7 M& a' V1 N9 R9 T! E' Q
7 y5 N. N  U0 ^9 {" t' g/ N        (while (/= (type first_point) 'LIST)  F  g1 Z0 u" }( k/ V( P( ?
          (initget 1 "Layer Scale")1 g* v  s8 a; r6 C% O
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
7 D+ K( r: g/ Y5 l( l$ [/ c          (if (= "Scale" first_point)      
! K  c6 z9 U" w: X0 y8 g; m            (progn# O; `+ n; P" {. q/ {- U1 }7 I' R
              (setq temp cloud_scale)
+ O0 W( ]/ \5 }5 ]  Y2 o              (initget 6)" T, _% x1 F6 n- u. R, d$ Q: T
              (cond& g8 o  I1 G' z  ^
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"# r! _4 x. c7 g$ q* j2 ]+ v+ R
                                                          (rtos cloud_scale 2 2)
2 I% n! n$ @7 \1 b1 {# z                                                          "> ")))), H, U  j. s; f
                  (setq cloud_scale temp) )
& I4 D/ `8 H; }2 S2 O( ?              ); cond
2 U. Y  J1 m  z( l+ W8 j            ); progn
3 Q, g9 S7 M5 U          ); if
3 d5 C6 ]/ f* Y% E7 l/ D0 C7 s          (if (= "Layer" first_point)
6 f$ W4 y+ G8 u9 Q2 Z, q            (progn$ m# O+ f7 b$ O9 ^4 g
              (setq temp cloud_layer)& I; d, o9 V9 x8 w0 Y1 R
              (cond
0 o, `9 W" c: s. k$ h; p                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"; k3 S! T. }& ~4 j
                                                          cloud_layer "> ")))# T* s, N' k0 X- N9 j9 D" G1 c
                     "")
5 I- o; ?$ X0 K* `+ J# l( J8 c  v                  (setq cloud_layer temp)
" t0 I( I5 B; t2 J. Z. w1 Q0 B                )
$ u+ G0 y; R+ K/ S( C              ); cond; H  e& i+ M" d& m0 C% I/ M
              (if (= (cdar (laychk cloud_layer )) "No")
# C' m& X8 ]! c4 O; D+ @                (progn& f' q0 `: N3 m1 ^& S0 U4 v
                  (setq cloud_layer temp)
0 G! j5 y) j. b0 U! s- i                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
: ~; Q" L. k; l$ V, g9 _+ r                ); progn4 p  Q- ~; R- p( @! H) l2 d
              ); if2 f% ^, f4 V) O  v9 d$ K* G
            ); progn9 |- a8 p: D4 `8 I. U, r5 G# I7 y/ X
          ); if
  c  H" R6 Z2 K4 G& d0 j        ); while/ T  ~. m/ {3 i3 e! q
        (setvar "CLAYER" cloud_layer)
( F% M6 b/ t0 G3 b! U
8 \  ^; Z9 M6 b/ m; c! g; z# D        (if (>= ( getvar "LUNITS") 3)
' U! A, b$ b5 |  Q: y          (setq length_cloud (* 0.25 cloud_scale)
  k8 E# z5 X( f9 W/ ^                length_tri (* 0.3125 (getvar "LTSCALE")))$ I3 O) i5 I0 p2 E- `; c
          (setq length_cloud (* 0.3406890 cloud_scale)5 J) |) _$ T8 v3 y& r
                length_tri (* 0.438366 (getvar "LTSCALE")))
: S% t9 k( U& _/ X        )4 D2 E0 u8 E( Z* d/ z  ^  J; K
        (command "_.PLINE" first_point "A")8 W2 E" D" m  Q" g6 {
        (while (not (equal next_point first_point 0.000001))
" g, T3 d. i* c3 N! |, o8 A. f/ A          (initget  "Close")- j. W' P8 c+ \" d
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))4 N& R& @; e% }  ]# }/ b9 k7 t
        (while (and (not (listp next_point)) (/= next_point "Close")); b4 F7 ]+ E& `+ m; P8 V
          (initget  "Close"), G- H6 A# N- o- A0 ~0 M# h% z
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
) ~, ?0 o# K* i  U. D' h( ^        )
' s$ s; ~# G3 ]0 L2 [" l          (if (= "Close" next_point) (setq next_point first_point))
) M) {" A2 s1 T6 D1 w          (setq angle_l_to_f (angtos (angle last_point next_point))' P7 g' B; J7 W' L0 P" @
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
6 L1 x+ A; f$ m          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
8 D' l' J6 }0 Q( m9 V             (setq repeat_count 0)
# A" I# K+ i1 [3 o             (if (>= (- repeat_count (fix repeat_count)) 0.5)  X! a" L8 l* F* H' k9 X
               (setq repeat_count (fix repeat_count))$ B$ J/ B2 |7 o: x; u+ d
               (setq repeat_count (1- (fix repeat_count)))
8 F) a$ V8 e; D             ); if
$ R6 T3 t! G6 k: [$ i9 Y- P          ); if) Y* r& }0 N; M: z: o/ u, |
          (repeat repeat_count (command "A" "-100" relative_point))% N* k/ W6 C  j, `, m1 \
          (command "A" "-100" next_point)' M7 X$ l' i4 D  q# m; y
          (setq last_point next_point)! n" \; h5 ?$ H1 v& z( x9 D
        )( ^% s2 n5 F5 t- p( E/ ?! c
        (command "")
- L" O4 _" A. V! W        (if (= (type number_rev) 'INT)
1 u! p# ~2 _$ Q           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
! h8 e  {0 e# l+ G, {, j* m           (progn
* a; {6 t6 A; m. [; U             (initget 5)
% @/ s: F  J, ~! Q# ?             (setq number_rev (getint "\n请输入版本号:"))8 H$ p3 ^' e9 b4 X
           )
' E. `. e* ^2 L; L+ y        ); if
2 |: q) J; I8 i8 A5 z& Q        (setvar "OSMODE" 512)
6 X- i0 O! l4 J6 r        (while (/= (type point_tri) 'LIST)
% M. Y0 p( Y. z+ t          (initget "Number")% c+ A  M3 V& H2 \" ^* {
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))8 C1 n) I6 r  I
          (if (= point_tri "Number")+ C( B& X( i5 K* A# f% a
              (progn
( s9 r* d4 ^4 {! g, N& E: B                (initget 4)+ {% n# ?- U. C* r# D* X6 ]
                (cond
5 H$ {+ E* F9 L/ a+ d- X                  ( (not (setq temp number_rev . Y' C+ K; W" o6 f+ j
                               number_rev) H8 z# v8 L$ y" q1 r) e( ?+ u
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))8 {1 {3 l7 l" N8 g$ q/ }
                    (setq number_rev temp)
* ^4 t5 I7 H. [/ e5 D                  )$ H) |7 H( V# r+ h& S" n
                ); cond
' F$ G4 G# W8 b0 S" G$ e; e3 ]              ); progn) G4 m: |4 |0 Z8 q$ E( v  H; W. m7 a
          ); if9 g( o  @0 ]0 c! j1 a- j
        ); while
  i- f3 @: k+ Y7 ^7 @) b        (setvar "OSMODE" 0)8 R) d, Y! L$ W4 y" J$ x
        (initget 1)
' y3 [- n- B" i' ]( H+ U- T9 W& m2 I        (setq point_ref (getpoint point_tri "\n请选择方向:"))/ @4 X  g" `8 d0 E: a, w
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))  C1 k1 {+ D3 [5 K. F. Y
        (setq corner_1st (polar point_tri
: M. k; C2 l/ L                                (+ 1.570796327 (* -1.570796327 dir_tri))
& _7 u( l6 {: _( B, L0 d1 d                                length_tri/ _" F- J8 P8 N0 j
                         )- p$ h$ V2 B5 `0 i" W
        )+ ~1 v6 |0 X+ H2 ?& q; _
        (setq corner_2nd (polar point_tri" u% J" V) ?# I7 A/ \: P0 U
                                (+ 1.570796327 (* -0.523598775 dir_tri))7 L7 K3 }# }. {1 ]
                                length_tri
' c2 M- _' w% V/ c1 S6 w( {                         )% e: F% M9 s3 z3 j/ {, n
        )4 `) X5 H1 w& F$ l' t
        (setvar "CECOLOR" "2")
+ S* g4 m6 \) |& C3 X1 m        (command "_.pline" point_tri corner_1st corner_2nd "c" )& v% H* Z' G2 N" u& S' s7 u6 w0 _
        (setq textstyle (getvar "TEXTSTYLE"))
( t7 s% F# _' n1 f) N: \% T        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")$ i$ q# N+ W1 [4 H% F4 N) G6 W0 z& Q2 y
        (setvar "CECOLOR" "7")
5 V/ l' P- w) T+ t. W5 d  K- J, [' M        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
4 n: H8 g2 E! G% J- Q2 n! T' K& i( j" d' T; y                  (* 0.4 length_tri) "0" (itoa number_rev))
9 ]9 D7 _5 s- A: F8 S. v        (layres)) ]2 K0 c: }8 l+ D
        (err_restore)
# d6 j( {2 i. _. J% m1 J9 }        (princ)7 I' v9 Z4 N" n% c# L
); defun cloud+ B9 e4 B5 k( c5 d) T

6 p8 M! s  x' b; F: V(defun c:cloud () (cloud))
' I* S% ~2 L# F/ K; k, V(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
$ T4 Z2 t" w- ~0 j# M2 |' r5 P* s;;;. Z( p, u' x' z$ L
;;;  DESCRIPTION& b, |9 G. ^/ F6 g( D
;;;     These are general error routines which can be called by 5 y; X3 T, _9 p8 \2 m
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference7 l" w8 W& n! G5 b; b' f
;;;8 i% o6 l3 c9 g' }! S
;;;  SUBROUTINE INCLUDED IN THIS FILE+ _4 J' d5 ~! |+ e, D
;;;     UNDO_INIT' [2 m' x' y! U  ?( |4 }: r
;;;     UNDO_RESTORE
; W' z( }! [- p( k1 ];;;     VAR_SAVE 0 ~) {; F3 Y9 z* e: f. s
;;;     VAR_SET  , d8 X# R: b. O# j
;;;     VAR_RESTORE! z; k- N7 h* Z3 _
;;;     ERR_INIT - d! T! X8 a7 b( Y+ J
;;;     ERR_MAIN 7 R$ v7 V  `; q
;;;     ERR_RESTORE
, {' Z( }& @( ^: ~. w" [;;;
/ |8 O- `6 I1 T2 b;;;  DATE: 10/17/98; 03/31/99
( X& s  J0 v$ k1 k) b;;;$ q+ N5 {6 n7 n, M
;;;  HISTORY: 3 x5 O) q+ ?7 h4 Y
;;;    Add routine of mod_att
3 W$ t0 ?" ]* [0 M0 d: A;;;; |% f, Q8 B1 i9 `" _
;;;  USING METHOD
: W; Q" D5 P9 X; ?& M;;;    ERR_INIT:0 I3 B. ]- ]; D5 [- X/ z
;;;      This routine initialzes the error handler. It should be called as:1 e2 m- C, V$ C
;;;
2 n6 e9 J6 U& u, H;;;      (if (and (not undo_init)4 d! x0 Z5 n. p
;;;               (equal -1 (load "undo.lsp"  -1)) $ k8 K1 u! T! D3 U4 T, Q
;;;          );and
! f& ?# j$ K5 l# |( `8 E( E;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
- y) ]! b+ z  X( g0 @;;;      ); if8 U! T. H* s4 e5 A4 H/ P7 `3 e
;;;
3 y2 W1 M3 }. A% k: {( s9 W4 p  ]# N;;;     ARGUMENTS:
$ L4 y! X9 W/ `' U; u;;;       err_init Takes 3 arguments. $ b/ t& U* r# Q: Z7 W  x
;;;     1. - The first element of the argument:9 s$ i, Z! b/ c% j1 G5 k7 L) K2 ]
;;;          This is a list of system variables paired with
2 m" s( {/ G3 d5 ^" K) U& s;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
% o. `+ Y2 Q8 Z: m) t;;;     2. - The second element is a flag
$ o4 H7 V8 F7 e% G  [8 f2 I$ n;;;          If it is true, then in the event of an error
. ^. L6 r1 G/ ~;;;          the custom *error* routine will utilize UNDO
+ I6 V2 f2 a/ y! Z) P: H5 I& }' k;;;          as a cleanup mechanism.( v  P) F4 U. E# j. _6 C
;;;     3. - The third element is a quoted function call.3 P0 s9 a7 e% d4 d0 g
;;;          You pass a quoted call to the function you
3 j5 D( M; `( Y2 Z. N3 T;;;          wish to execute at the end of nomal routine if an error occurs.
6 O1 b9 ^- Z" I  f;;;          i.e. '(my_special_stuff arg1 arg2...)5 N5 @  g) U- W/ [/ g9 E" l( Y' Y
;;;          Use this arg if you want to do some specialized clean up + q" G0 ?6 o# }! M! N: g3 h- N
;;;          things that are not already done by the standard bonus_error 8 u/ V5 i) S2 H. o* ?
;;;          function.# j4 q* W* ~6 a, B# e! \. {
;;;
; C3 C, C2 y3 L4 h- M;;;    ERR_MAIN: Body of error routine
( t& x+ W/ f2 \$ \;;;6 g8 \  |/ F' @- I1 V2 }& m& O3 ^
;;;    ERR_RESTORE: This routine should be called at the end of command to
' b8 ~1 \) S: d& j6 x;;;           restore the VARIABLES, UNDO & *error*.9 w' Z8 l9 z$ H- i2 x; e7 t
;;;
+ u% M! u4 D: r3 a;;;    UNDO_INIT: Initialize the UNDO status
( Y' d7 W' ]+ ]! Q7 r3 N: y;;;
# E* P% G. g1 i9 |0 [;;;    UNDO_RESTORE: Restore the UNDO status0 z3 o  a' c8 ^, l2 t
;;;4 f. {3 |# p7 a+ f% u, {
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
- ~/ l: G: w9 F) O;;;; e$ n/ e; O! W% P6 `8 o
;;;    UNDO_set: Set the variables. the argument is like
2 ~1 l. ]# _2 A;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
6 n8 ^: c' w# Y: N( o;;;- G* u% G9 z1 U9 b# W4 L! q' Z
;;;    UNDO_RESTORE: Restore the variables
# E1 R$ K* C; N1 W" e;;;
0 l" [' x( `) n4 `% r;----------------------------------------------------------------------------
5 W4 w/ L/ z0 ~5 S/ s) q4 W;  GLOBALS:+ F* l' R: |& [2 U; \3 M6 P+ B
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)+ [2 A7 N9 T7 p. J0 c3 W/ [( _
;     m_lst       -- list of variables (voided by VAR_RESTORE)
& v# h% C: H+ ?) t4 X! G;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or
- t; C  [5 W% R/ z" j;                    ERR_OLD)
/ O, H1 V; I, S;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
9 ?4 `9 c. A, J" Z- `4 N: c( J2 W;----------------------------------------------------------------------------
8 H6 j  ~" s8 z3 h5 r* x5 V7 u9 b
; d$ ?" J% K) ?: D;----------------------------------------------------------------------------" ^& d( J" }: y+ \2 t- T* p8 z
; Modify attributes according to entity name, attribute name, dxf_item
1 t. B- s8 x' o  F$ Q. M;----------------------------------------------------------------------------, h* G4 ~' A( P( u* g
(defun mod_att(ent id dxf_item)        
$ S. h# `$ F4 O5 M' A0 t  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
  |; ?7 ^( b) s7 N    (setq ent (entnext ent))
3 i. m* o4 Y2 \9 G5 ^9 |/ h5 l0 h  ); while  , V& Y+ q: K- ~( f, w
  ((lambda (x)$ Z% }( K7 A1 H6 H0 z; V8 p+ i
        (mapcar '(lambda (y)& D: F3 W; `6 c, D
                   (setq x (subst y (assoc (car y) x) x)); a: b+ P3 V$ F1 C+ c0 J: f& ^
                 ); lambda
  g4 n1 v, Q2 z* S( O                 dxf_item
" d' b+ H) X# u/ s$ Z% Q% E        ); mapcar+ _" o2 h3 I- {: S$ N5 [+ |
     (entmod x)
" Y2 U$ v2 y" q, C9 D, L$ V     (entupd ent)
9 W% i1 _3 h* l% T: Z, q) E$ G4 i   ); lambda
: h3 `( `1 V- i( z  u   (entget ent)
% }# |) ]5 }7 m( V) R) M )+ l" a" x  r. J& n8 l
); defun mod_att3 K% E1 {5 E4 N; O# \
% R2 P- u9 |% i+ H! T) y. E
;----------------------------------------------------------------------------) q/ i$ w9 b4 Y  p3 \
; Check layer status, return a association list which contains layer information2 v6 \4 h/ u: I* M$ P& l2 }- Q6 f
;----------------------------------------------------------------------------, w. K+ P$ e- Y8 O% U' x
(defun laychk(lay / l_sta)7 y; l; Z3 v& u7 h
  ( (lambda (x)  N* Y+ O+ I  B9 `- v
      (if (not l_s)5 D1 S# ?) {/ J- F. g9 K4 j* |* m
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))1 ~5 y$ }$ Q& \% z+ ?
      ); if3 r. e6 G" h3 F7 m, \) q
    ); lambda : t! Z) ?& d; E- e
    (getvar "CLAYER")
0 A& P! ]' K7 `. h  )" V2 z+ E, T" q/ |
  (if (not (tblsearch "LAYER" lay))" l0 t  f& A0 A
    (progn  # T) w, z9 d7 E3 V2 b( r$ i, l: U/ c
      (initget "Yes No")
2 d0 e- j% P7 j) a" [0 T      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
/ c# U/ O- b( y, l5 L        (progn& o! j5 k: O) U' w. F/ C4 ]
          (command "_.layer" "n" lay "")
  p6 B7 h0 T# _7 q! a+ U          (setq l_sta 0)
7 r) w+ p1 p4 Y# m0 n6 d        ); progn7 ]. a+ L$ G& v! S; j* Y: d# h
      ); if8 g* w, t5 a" F) b0 Y5 d
    ); progn( v4 S* s9 M6 I( u" p  {7 U4 i
    (progn% W8 ]; o- e; E5 u8 d
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))5 \$ j: [( T2 n2 l5 x
      (if (= 1 (logand 1 l_sta))
7 R# L& S: P& B          (progn' n: X) i( x# \) Z- V' u
            (initget "Yes No")0 ~) H# P  d- A- j3 y% H
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")- e" g( \( T8 t- ^) r" }
              (command "_.layer" "t" lay "")
, d& P. y! y) E, J2 t7 u- x              (setq l_sta "No")5 x4 t( \3 w; j5 ^4 z2 R
             ); if8 S2 n$ X" V" ^
          ); progn
7 i, p  \9 U+ m" y# S9 l( B      ); if3 X5 X/ W$ G+ U5 D( H
      (if (numberp l_sta)
( P1 d1 [5 P9 h. P! M& `2 h5 ~        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if6 t. \9 A% M: y* G2 O# f
      ); if
: V) f  N( A. v- X2 }+ ~8 c    ); progn9 T, n3 Y1 }; ~: f
  ); if  z% N# I7 F  G; s
  ( (lambda (x)* l) T4 e, M: x: E' V
      (cond / N; }1 }0 r! p( |
        ( (not x)
: H& E# j+ W, Z' C7 [2 T" }0 U          (setq l_s (cons (cons lay l_sta) l_s))
6 R; }, C  I3 n- s8 Q1 ^        )
# k1 J8 Q4 X, }        ( (= "No" (cdr x))
' a1 |. K( I) J4 q1 O  @, H          (setq l_s (subst (cons lay l_sta) x l_s))
' [( u! U. p8 ^" J        ); u6 p) X# ]6 V2 T( H
        ( T l_s)
: B, P8 {( X* a" S      ); cond. O3 w2 c& _1 ?- O- M) L
     ); lambda! Y8 b2 b0 [  F; K0 @
     (assoc lay l_s)
. }' \" w+ f" p6 [  )' L2 B4 @) U+ G
5 ~. Q8 e+ U& }7 R/ Q( `
); defun chklay7 K. i3 a; b4 f" x$ J& g3 [) t
- `# o7 m  I: {+ C% k1 V1 e& r
;----------------------------------------------------------------------------: x9 j2 K) l/ n
; Restore layer status according to association list l_s
: G# h& k8 I3 {* W3 y" W/ b;----------------------------------------------------------------------------* {/ Y# Q4 h9 _, r4 w. u; Y
(defun layres()+ c2 d6 T% F2 U
  (setvar "CLAYER" (car (last l_s)))% B9 o. N) t4 k1 `8 ]- H
  (repeat (length l_s)
/ Y% [) r) f) o1 ~, y    ( (lambda(x)  
- ]8 `/ C# \' e- w5 v9 Y7 h7 I9 L9 u        (if (numberp (cdr x))6 ^0 ~: B, v( f0 r6 w% t
          (progn
# v( \7 m* H4 M! n. Y. [            (if (= 4 (logand 4 (cdr x)))
. A' W+ j! w/ ?2 M. a              (command "_.layer" "lo" (car x) "")
; r4 J* b7 \, b; u% x. `  w            ); if: Q4 x+ A5 Y9 p5 O0 M
            (if (= 1 (logand 1 (cdr x)))4 ^8 o( L. `; Q# P8 o( w
              (command "_.layer" "f" (car x) ""); B( u1 u+ w9 L- Z5 Y3 W: w+ |
            ); if
+ ~1 |+ q4 B! S" ^* R( N          ); progn
8 c) S, b/ p6 N& F4 h# K       ); if  
2 F8 L7 j" g( ^7 N9 d# {4 E      ); lambda
$ s* a2 g' u4 i' Y! }) B5 l      (car l_s)7 z. d" {- w* X- Q4 q/ S0 M/ }3 }
    )  _& ?% z4 c5 b& t( E
    (setq l_s (cdr l_s)), t% J: F4 m3 u; J) e
  ); repeat
0 w/ S) {! E2 \); layres
8 `# L' m0 f6 d" ~+ N$ z/ b
- O! p, L( O! Z" V;----------------------------------------------------------------------------
: x" T2 Y5 n3 r+ K9 t" B3 ~; Get DXF codes
  T9 W) m  g+ I/ B;----------------------------------------------------------------------------# [) A! P  x+ }2 L, L
(defun entgetf (index ent)
6 t3 F! ]7 J/ k7 y& u& h2 e1 l" i  ((lambda (e): ?0 Q/ D6 s: |! w8 [
      (mapcar '(lambda (x), s4 m# {8 O2 t+ D9 p, s
                 (cdr (assoc x e))
. G- ]# C4 q& T% m. @% f$ y               ); lambda1 u% V# P2 |8 y; a! E
               index) ; internal lambda function
" t7 ^  I$ e3 R    ); lambda
/ I/ e  f  k# c; B' t0 h- r( ^    (entget ent)
- z; V0 z- Y  l2 s4 O  )
  h* S/ u( u5 e/ F2 m); defun entgetf
; m& r& t, G( f$ h( t
0 G) h% f$ y+ F) i;----------------------------------------------------------------------------. O4 ?4 w% L. b: N4 u. J1 @2 ^1 Q
; Save UNDO status
( R* P8 d$ g" O2 R* c" W0 q/ e;----------------------------------------------------------------------------) ^+ @6 i" ^2 t5 O0 ^; Q
(defun undo_init (/ cmdecho undo_ctl)   # K. B9 V; i" C0 L7 {9 g6 T# K/ r
  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value9 I) |3 ?; ?2 K2 z
  (setvar "CMDECHO" 0)  K! h  h( a* Z. V

, Y$ B- [) E. R* R- a  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable! v& {( E% p/ H/ n, N
    (command "_.undo" "_all")
+ t2 V7 q  N5 v) {4 }3 t% H    (command "_.undo" "_control" "_all"); j5 S- c: l1 N
  )5 C9 q7 u2 u' {; G. q. r0 b2 b4 t0 q
8 n& ?( L" ?! ]: Y! J# s6 Y' }
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off: K4 _7 B6 q0 F& ?* W$ O* p" _) o
    (command "_.undo" "_auto" "_off")3 C" a: `# {4 E! l
  )8 e1 [+ z, b$ [( j5 f5 {

% ]: @3 z' X( F5 X4 `. Q( F  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
0 m# S% Z2 n' q) q7 Y6 O    (command "_.undo" "_end")
& O- O! P) o8 v' x7 r% }  )9 h6 R, R+ K4 G# f6 d" }
7 m  t1 P# y& d3 I: O+ g
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
7 X' X" C; O2 n- F: u3 m    (command "_.undo" "_group")% j" I) v9 Z; ?( F/ w' |
  )
! j- ?& T: H: y/ K. B; ~, T, m  |
* K5 f) @0 ?& x6 y) e  (setvar "CMDECHO" cmdecho)
/ z! A. c6 j7 Z4 r% }  undo_ctl# V, L0 o/ V7 s+ H1 U* H# ^
); defun undo_init
4 z4 e. [. i8 G/ ]9 n+ r5 u3 Y
;----------------------------------------------------------------------------4 W$ e$ f9 |2 A% f: B* y3 N
; Restore UNDO status6 V7 d0 W0 E" T2 t) q" r
;----------------------------------------------------------------------------0 w5 m8 z& F- o# F7 v/ [
(defun undo_restore (/ cmdecho); j+ M/ g; i2 t! J" c8 Y9 `# E1 ^
  (if old_undoctl7 H6 q2 V. V1 s2 o+ d- F
    (progn
: F& q. {2 I" b, z/ M  L      (setq cmdecho (getvar "CMDECHO"))' O+ _( d( S1 K) F9 D- G7 ?+ c
      (setvar "CMDECHO" 0)
* A+ s# T$ y1 ?: t
  i/ L3 m& N6 }* N; k6 Z      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
! Q1 `3 u0 @) s      (while (equal 8 (logand 8 (getvar "UNDOCTL")))+ B6 }8 r: Q$ E" k$ {
        (command "_.undo" "_end")3 Z# ~. ]7 d: A9 _9 @. D& J
      ); while: A! B) I& `" k7 H0 E3 A: `, i
. H5 R3 Q  c5 R9 U, _
% r4 R+ l+ ~: i. Q
      (if (not (equal old_undoctl (getvar "UNDOCTL")))
# I8 Z& ^3 M; L' l! G0 B        (progn& z4 ]( `( M: o. {. n6 R
          (cond- g8 g2 q0 g- P; Z5 i
            ((equal 0 old_undoctl)0 i! H8 n; F/ u0 N
              (command "_.undo" "_control" "_none")) ^4 _2 _$ M4 Z! r7 i. P
            )
$ [" j* L. d. J- o+ b            ((equal 2 (logand 2 old_undoctl))
/ j% L9 b+ n, `/ K- `1 |              (command "_.undo" "_control" "_one")
1 ^( e; {# e  O/ N1 J9 x% ]" h% n            )0 \- Q  H; T$ C. S
          )
& C0 Z/ Y8 Y; I% |0 y- o3 E. z          (if (equal 4 (logand 4 old_undoctl))
$ G: i; c6 f3 u# _              (command "_.undo" "_auto" "_on"): ^! C* d0 F! ^. Q  B
              (command "_.undo" "_auto" "_off")
5 G. {0 O; ~1 i% a  |          )7 V8 s1 i% B7 o
        )$ F- W  W  [2 D% T; ]; I) q. `1 g
      )
' l4 t2 c* y# a0 D: G      (setq old_undoctl nil)
/ `# f4 H9 N: x      (setvar "CMDECHO" cmdecho)
4 h9 X" B$ ~1 d6 g/ P2 m% g    )
9 r9 Z# U! x, S8 m: _, \4 y4 ~7 y  )' b$ L8 Q0 }( z8 ^; K, b8 D
); defun undo_restore
. L, i. T1 h& `( N, t; ~) \# `. W3 U: ]- g
;----------------------------------------------------------------------------' W, S2 M2 a7 H& u& |, z
; Save variables' y3 X/ ]! Z7 Z  m2 ]7 y* Y0 \
;----------------------------------------------------------------------------3 _$ m6 J3 e0 S( I: P- V, v' a; Q
(defun var_save (a)
; R  x* [" ~. h9 ?  (setq m_lst '())
/ x9 J" @( J7 j, o* z( c/ r  (repeat (length a)8 D0 Z3 v; N& w: s0 F' I
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))9 u$ }* E+ h3 u( t! M# [
    (setq a (cdr a))
9 J! I$ o. v( J$ X3 y  )' B" g" r3 u0 E0 K# C
); defun var_save! Y2 G8 c; _, L
. P) v" m% b4 c: Y1 Q4 a3 d+ O* B
;----------------------------------------------------------------------------
& l0 P: w" R3 \; Set variables
4 t) Z/ e( M% U;----------------------------------------------------------------------------' H  ]8 ~9 B0 }% L2 x" `# t" A
(defun var_set (m_lst)) ~- w$ s  U- W5 F1 o
  (repeat (length m_lst)
: p! i: l$ w) l3 @( i    (setvar (caar m_lst) (cadar m_lst))3 I8 p, o$ o9 v" d. T
    (setq m_lst (cdr m_lst))
. W2 X. S; Z) D& k/ K$ ]  ), y0 @& ~6 ?+ O* \" {/ C
); defun var_set$ ~: }) _9 @) X) ~+ J
2 H1 }$ A6 _- h; k& S
;----------------------------------------------------------------------------
+ `& u, E! V0 B- t; N& u4 D; Restore variables; Q' a! y- R5 ?9 n2 o( q
;----------------------------------------------------------------------------
- o: |0 r2 h# z2 U/ I4 O/ `. u(defun var_restore ()
3 K) Y; W. ^, ?$ D  (repeat (length m_lst)5 w) d, c9 t2 N: P* ^6 w
    (setvar (caar m_lst) (cadar m_lst))
8 M# w5 z( y1 Z0 G0 `/ y    (setq m_lst (cdr m_lst))
% `5 Y0 x. z; I( c  )4 S& X8 h1 n5 l
); defun var_restore
) u' |6 h( t1 [2 r, q4 a& \
$ x4 l* c) Y" o3 O9 p- \;----------------------------------------------------------------------------
: H% I8 C# T  X; Initialize routine
, |- V) ^! h$ ^9 O4 J1 H" H) C" s5 M;----------------------------------------------------------------------------
1 F$ G& h1 q, ]& _0 \; d2 M(defun err_init(e_lst u_enable add_fun)
: }% ~* S% K& O! o  (if err_alive (err_restore))          ; To avoid nested call
% R* k& }- u4 p5 J  (setq err_alive T)
: \" \9 Q1 }" Q/ [. i# _  (var_save e_lst)                      ; Save the modes
/ E, B: u2 t( ]. e; L, B0 w  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status; m% E" J. z$ o  R' T. x' ?
  (setq err_old *error* *error* err_main) ; Save the handle of *error*
6 \7 o; b0 e5 y0 E5 w+ ~* U. L7 s  (if add_fun                           ; Add the user cleaner4 U" X0 m: `' r0 ^5 P
    (setq *error* (append (reverse (cdr (reverse *error*)))
7 H  y0 z& |7 R4 h/ S+ h                          (list add_fun (last *error*))
; x3 e4 b; Y" B( G                  ); append
% g5 S# \$ ~; i5 G/ O( Y9 W+ L    )
# s. J+ A3 M& P3 m! o3 R9 l  )4 Q) b0 R% W) I/ _; o% D! w
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------: @3 W/ N- V* S% y
; Error routine body; m+ Q$ ]$ W& M" ?) O
;----------------------------------------------------------------------------
) v5 J& Z. `( m- t; [(defun err_main( msg / )                ; Body of error routine3 l7 X9 O9 ~( n7 ~
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs
! u& M4 Q, C" u* e6 x9 x" b    (princ (strcat "\nError: " s))      ;while this command is active...
3 j( z8 y5 p' y* r: b! a% A  )" S7 I+ a% B" s
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
, y; X* S! T9 J; @) \4 X
! N) q% F  f7 w# |4 W) b6 {: s  (if old_undoctl! J2 l" x$ i. l- y) E6 z
    (progn. A9 _0 h+ C5 e# q% g3 z/ r2 F* f
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
+ T( x4 n2 Z! y7 ~: V0 d        (command "_.undo")              ; if it's in UNOD command
' x) r* [1 y0 `9 Y, X3 U      )
' ~6 x, P5 H: P1 u3 `      (command "_end")& a% b0 j2 r0 u' M9 C
      (command "_.undo" "1")
+ C6 x2 V. ]7 |% r- w% g5 y4 U3 m7 x      (while (not (equal (getvar "CMDNAMES") "")) (command nil))* D: O! h0 a+ I( z) S$ U5 N* n
      (undo_restore)                    ; Restore the status of UNDO# i) H: j; \1 f' X
    )+ |) [2 T+ s1 O
  )& i4 [5 x3 ~0 A- F  ?

) N/ z! I) [& |# [  a" v" z  (var_restore)                         ; Restore the variables
( u7 _, A8 `1 A1 |. {+ `  I2 j  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error6 ^3 y5 v  }' W% d! x
  (setq err_alive nil)
5 j$ D( c7 \9 o9 o( f" [7 ~  (princ)
* J$ D3 ~7 Z  K/ `); defun err_main
) S/ y6 U" N# z3 q. x) Y* F$ [4 e
+ x0 B. N6 y* P  d5 ?5 U;----------------------------------------------------------------------------
- t: }5 ]# |7 i; R: L# I4 m; Restore error status  ^" Y7 F$ Y4 r8 a
;----------------------------------------------------------------------------
1 y+ L. E5 |# d6 N2 C+ f(defun err_restore()
4 T" s$ R4 m% e0 u  (undo_restore)                        ; Restore the status of UNDO9 x& Z( {+ A1 y  x; z4 O3 N
  (var_restore)                         ; Restore the variables
' o+ ]: S% p) F  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error& W, D. Q5 D/ r1 O0 ]% I; y
  (setq err_alive nil)
- i. I/ l- G  I9 G( N4 `  (princ)1 f0 a, i. j2 U7 D& N
); 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 06:23

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

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

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