CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
# |8 m: A0 A2 \" T- X8 O0 D9 ^ “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
! X  a% e6 Z! ?* z% s; i提示:加载成功# n2 E/ d7 [9 X( x5 O
然后使用CLOUD命令,
! x  d/ {3 [. T+ Q提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”5 b, @6 j& r% t. m3 ^: R3 K) w: x" j
请高手指点一下,这个是怎么回事?应该怎么改正?
+ E. Z* ?$ w" x) p这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx3 a* E3 _( |" Z9 R2 I. k) q3 S4 j/ K
;;;2 h) t+ v3 W' |" B2 \
;;;  DESCRIPTION
/ }* f6 m/ b! l1 }$ t' y; M* s;;;     Draw cloud and you can specify the globals variables listed below8 n3 B4 ^. E- S7 v: J
;;;     to decide the characters of cloud
" f. u6 C& Z  t" [7 P8 d- @3 J;;;
: Y: Z( b0 t. A# B;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
5 h/ x8 j" [* R) a;;;
" H; p- D- [& r- A, @# u# T) b. D1 P;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed: P/ u/ g* f" p) Y) K! |
;;;           Change CLOUD.001 to use CLAYER to perform the same function7 }" b% g1 N4 i5 L' ]
;;;           Use the common error routine UNDO.LSP to optimize this program
5 c1 G# _" W7 B: l; \; A;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE, u& z" n/ q7 a( l7 t
;----------------------------------------------------------------------------. c5 m0 a1 M3 ]
;  GLOBALS:
* ]! V) h9 k( P;     cloud_layer -- layer of cloud& x) V9 [" w3 K' _, _0 ]
;     cloud_scale -- scale of cloud/ i3 }2 X/ w6 j& v4 D4 F
;     number_rev  -- revision number
  u1 S/ p  I: A0 D;----------------------------------------------------------------------------
7 R) E: G+ v5 m8 C" d(defun cloud (/ locked temp first_point next_point relative_point  c7 h) b. y: S  G2 h7 b' h
               last_point point_tri point_ref corner_1st corner_2nd length_tri
( d1 G! W. s( K& ]8 _) {8 B               length_cloud angle_l_to_f dir_tri repeat_count
* m4 @5 {, ]/ ]1 T9 Q               table_cloud )) I' U4 J& V+ V! i% `: B
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))) M8 l! L- B8 t/ |, X, L6 Z7 X
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
! |& j; z* p/ E- f        );if% `& m( S+ [! ~/ I# t
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
9 c3 X. g0 X. b. ?: ^# ?$ B" n                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))# {1 @- V. h, C/ ^' B4 |$ |
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
2 |! A- T& m# p& Z3 |" ?                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
- U5 f2 W) Y+ D7 P6 `% `$ Z$ K
; R' ~' l, @$ b        (if (not (numberp cloud_scale))
+ S1 |5 F9 ^0 P" _+ H- V! B            (setq cloud_scale (getvar "LTSCALE"))
1 P  R- R, j% g3 W        ); if
, h6 O1 b0 w9 W7 w) y9 b        (if (not cloud_layer): T. R" w, W! `5 a/ `' g! n
            (setq cloud_layer (getvar "CLAYER"))+ [) t2 J- O8 S, N' K
        ); if
6 b! o* }9 S6 r6 @* d7 I        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))* n# Y$ f5 c( A+ G  C9 ~$ l
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
- Y3 w$ ^& y- }" ]7 {: O, x        (if (= (cdar (laychk cloud_layer)) "No")6 P/ H  B* k0 g( l9 I
          (progn
7 d& |1 f0 m( F% ^# A5 `" D6 o            (laychk (setq cloud_layer (getvar "CLAYER")))
5 h, _1 M: ^- {% _            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))) N/ ^& p& L7 u+ `7 G8 N; e/ K( X
          ); progn
  ~. n' Q  a* {3 z% |        ); if, v2 t; k2 f  C/ I% |# K0 t

, n% M5 x. [; p# G        (while (/= (type first_point) 'LIST)* U7 p" F* J- }( G
          (initget 1 "Layer Scale")
3 o8 k% @2 z3 i. r, l8 h& b; n          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
( j: K- k9 }% K: @          (if (= "Scale" first_point)      
, ^) |# T6 L1 |            (progn" m8 a% a3 s( z& j" P
              (setq temp cloud_scale)2 J  f7 l) q' M& z/ ?
              (initget 6)0 H& J5 k+ C- L5 N* U# t- D8 n! y
              (cond
0 x0 r% y/ D2 `9 }$ J+ [. A9 |! U                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
7 H. S* Y5 X1 V( c  V                                                          (rtos cloud_scale 2 2)6 n  N/ k( S  G3 C8 R
                                                          "> "))))
1 e6 x  M; y8 y4 e, z                  (setq cloud_scale temp) )
( p, l5 E: D: K, U1 V$ T              ); cond- _; k1 o$ N4 t) r. o
            ); progn
9 \2 d; K% f. S. E& ~5 C! n4 w          ); if
+ K: z1 Y1 s& P+ x- f% R          (if (= "Layer" first_point). S' B, }7 _9 s% h2 t1 r6 ]
            (progn
" f5 Y# S; n0 p, Z4 L              (setq temp cloud_layer), t1 t3 z. u+ G9 W! B9 ?. w, [) O
              (cond# t" f) K) \7 A, x' X% q
                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"# a; d, B2 F* G. u
                                                          cloud_layer "> ")))
# J' o  J9 T8 D+ y. t                     "")
% e0 x0 L( `" z                  (setq cloud_layer temp)
# g0 m6 L9 k9 u* M& k( T) L- [                )& P5 w2 O- i& Q" B
              ); cond& C+ ?# J2 F- m
              (if (= (cdar (laychk cloud_layer )) "No")
# n0 }5 G: [+ V                (progn
9 M5 G0 ?: y. H, g# \                  (setq cloud_layer temp)
6 }& J" q5 o! l) s/ n                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
6 G. R0 y" y3 V  C. G6 \/ O                ); progn
6 O: e7 P' D$ @7 j5 S/ I/ U( O              ); if
+ F# \8 j8 ]6 Z4 x7 V# r6 T: u            ); progn
4 D- U2 k" }2 g$ g! c  Q2 ^          ); if
) v6 ?0 Z$ L% p2 p1 D% o6 W3 n& j; m        ); while
# m' ]* |  N# {. U( X        (setvar "CLAYER" cloud_layer)" f9 z$ ?# O8 w9 [( J! N' }$ B* `
( d2 Y) [5 L+ a2 j2 L; z
        (if (>= ( getvar "LUNITS") 3)2 D, @$ y* ^. i2 v, @$ b  Q
          (setq length_cloud (* 0.25 cloud_scale): B$ {1 p8 I1 v
                length_tri (* 0.3125 (getvar "LTSCALE")))  }3 b( O, W  f/ U# a$ g
          (setq length_cloud (* 0.3406890 cloud_scale)
4 Y" e5 f# J' V                length_tri (* 0.438366 (getvar "LTSCALE")))  ^7 F) x; D$ v9 d- a* o- b% N3 F, U
        ): a9 A$ G( r  q, j
        (command "_.PLINE" first_point "A")9 g9 a' e  e7 P; M8 o" n: R3 E
        (while (not (equal next_point first_point 0.000001))0 i3 ^5 e% W1 Q
          (initget  "Close")
5 w3 E- t2 v. v( O% n          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:")); y5 o& ]  {/ ^, V" i( W- [( S3 J
        (while (and (not (listp next_point)) (/= next_point "Close"))
/ |9 p" \& N7 P* N, ]% N. M          (initget  "Close")
* ?9 H  h( A+ P! e+ k          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
6 K3 n! s, M* e) @5 P0 U% J        )
/ W& ], N* ?3 X8 P2 v' x; r0 P          (if (= "Close" next_point) (setq next_point first_point))
: I* E, c+ d- a3 e9 ^8 }9 a          (setq angle_l_to_f (angtos (angle last_point next_point))
1 Z  o; v: ]; L2 w2 H                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
. |+ D2 e) L' Q6 H. ?          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
5 N% _8 i0 r& T" h, p             (setq repeat_count 0)
9 h) m* _2 u, v4 n$ R! d" F             (if (>= (- repeat_count (fix repeat_count)) 0.5)
1 q; \% Z/ I" r$ m' d               (setq repeat_count (fix repeat_count))  v* w6 o9 Y* t, M. M, R0 B
               (setq repeat_count (1- (fix repeat_count)))
# e3 ^. e; X3 h; |/ Q0 c$ h; I             ); if 8 c% f5 j# ?1 Z3 }
          ); if8 M/ Q; J; L/ F/ I
          (repeat repeat_count (command "A" "-100" relative_point)). x% C4 s2 |# J5 H' l
          (command "A" "-100" next_point)( O- f  e; }" i; G, @- E6 w
          (setq last_point next_point)
5 I( N- _  a: t* J$ {3 [8 _. m7 a        )4 t% p8 {/ V; D" o9 _
        (command "")
! E! i1 S# \  L4 z, Z4 A        (if (= (type number_rev) 'INT)$ d9 X, x5 k+ N; [2 p  l9 ^
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
9 `9 i6 w2 N' _$ n2 ]           (progn& i" `4 M, p: }" l5 |% m
             (initget 5)$ j5 g1 A$ r( G* t3 ~
             (setq number_rev (getint "\n请输入版本号:"))! t6 F- F" e3 e0 j1 T  d4 y$ K
           )
1 |. g# b9 P: m, w4 z1 y) s        ); if
  V5 X" ~+ k7 N        (setvar "OSMODE" 512)
; o$ Q8 s3 C; }* M( a) d  P        (while (/= (type point_tri) 'LIST)% S! ?" X) D4 a2 p, E6 X7 {
          (initget "Number")
* Y2 r4 h% `$ l4 N          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))6 Z0 D3 u' @- r7 R
          (if (= point_tri "Number")
# E: t$ I3 Y" ?, P              (progn% ~7 F" u" G# T6 w# x
                (initget 4)
* a6 b' A; a" F                (cond
8 @) d3 }- i+ n$ V                  ( (not (setq temp number_rev
# }( a) Y! `0 z* S1 @$ w. O5 z                               number_rev- R1 E7 ?) K7 X$ V; l
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))( p; \7 E  P& s. S0 b; h9 A
                    (setq number_rev temp)
  G2 _5 ?8 Y$ E2 b' {, @2 C* v& f; |8 E                  )  E2 W1 X9 d, ~+ t/ s2 d+ D
                ); cond; }, i) K" \0 F0 q5 c
              ); progn* w" }5 G: A( H- }# V* Q! z
          ); if
1 }2 k: ^) f0 s% X* D, I        ); while' E/ y7 ^/ G: Q. J0 `
        (setvar "OSMODE" 0)
8 R, q9 m3 }" |" `( L        (initget 1)
; c% t& T2 ^' m! L7 k- ~        (setq point_ref (getpoint point_tri "\n请选择方向:"))
( s5 [& P4 P, j% F' L- ?        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))
* Q& m2 R; j& U, c        (setq corner_1st (polar point_tri; C6 k$ P3 h# H+ Y0 J
                                (+ 1.570796327 (* -1.570796327 dir_tri))1 m. k; ]5 M- |/ ]$ R, z
                                length_tri
3 M7 }! Y0 R' L7 V+ g                         )
# I5 k5 @! X, U3 c/ ~9 v        )
5 g$ ^% r, D" `: r- A4 W+ ^        (setq corner_2nd (polar point_tri
% h* a& Z0 v+ T$ [                                (+ 1.570796327 (* -0.523598775 dir_tri))' Y9 c/ K  a/ Z8 }( x9 S/ p  @: k
                                length_tri
. j$ q5 j% J2 z, ]8 K$ V( c" Z                         )
9 w" e$ _' m* d        )* ?7 S. \  |2 C( P! r; X' {0 m
        (setvar "CECOLOR" "2")
% c% a1 m4 E  |5 t: a        (command "_.pline" point_tri corner_1st corner_2nd "c" )
) G* ?) Z6 v" |( D        (setq textstyle (getvar "TEXTSTYLE"))
! ^: {( Q1 Q6 ^; @. I% Y        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")( G7 v3 N0 I  H& D7 ^( Q
        (setvar "CECOLOR" "7")1 l9 ~" S# v5 Y  A( `! x" Q" P7 q  d
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
( ]. D! A: H3 x) N( r: S/ Y2 a                  (* 0.4 length_tri) "0" (itoa number_rev))
' {9 Y7 w6 {! K( U        (layres)( s/ Y8 C& n3 P" M2 [
        (err_restore)7 Y* \7 B' V9 D2 n9 u1 Q! M
        (princ)+ m/ F$ n7 T  [4 X& V
); defun cloud5 {' p# A( C: G& [
$ Y6 ]5 z3 N4 n( S; p& o9 o
(defun c:cloud () (cloud))5 d1 g1 y1 _2 d3 G5 o4 b- j! n: g9 B
(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
$ F" E7 p" K5 j6 j;;;- E# b' u7 J6 E# O" c; y
;;;  DESCRIPTION
. `3 ]8 @2 G$ u6 Y: W;;;     These are general error routines which can be called by
, X) g' H5 ^3 \2 D  \;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference
% R: e- G, M, d' ?;;;* Q! \+ A4 ^' l% B6 T5 z& g
;;;  SUBROUTINE INCLUDED IN THIS FILE* v+ N: z) s# M4 f7 G; Y
;;;     UNDO_INIT3 S& j3 I/ y7 S5 a" b; }" V& ~
;;;     UNDO_RESTORE
- K# y4 s* L* v3 u) c! a# b3 T' U;;;     VAR_SAVE ) {, l+ p& B! h4 Y5 }/ [8 N7 W
;;;     VAR_SET  6 H$ f$ k! k  W; c' l! q) R, s
;;;     VAR_RESTORE6 N1 k1 p8 g9 S8 Q9 g  Z
;;;     ERR_INIT 2 K# _$ u, Q$ e( @- M- ?- l
;;;     ERR_MAIN
; S3 Y' A  X/ _3 ]9 Z;;;     ERR_RESTORE( f. s) n+ m  q
;;;, \6 X% K  u+ W4 h
;;;  DATE: 10/17/98; 03/31/99
( U* ]4 x. {* |, w3 ~;;;
1 g: k  v% R. _  m" u; c;;;  HISTORY:
6 o2 G8 j5 Z  W/ p" p;;;    Add routine of mod_att
3 @. G7 X6 F  A5 W, X$ Z! Z;;;
+ s$ ?5 m3 |7 e, K* p5 r7 H7 A;;;  USING METHOD
0 p5 l- |0 l: e+ ]# G* _5 d;;;    ERR_INIT:" w. k& \3 f& \2 k' Q8 T. q
;;;      This routine initialzes the error handler. It should be called as:
1 D; b! k( Z* ]' `* E;;;
$ r( A5 i- r1 [6 u" r;;;      (if (and (not undo_init)' \8 G$ T7 e8 }! q& T( u7 a
;;;               (equal -1 (load "undo.lsp"  -1))
( j# k" @# W! m3 S;;;          );and
# }7 s: Y) Z" a! Y& W8 f  J;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
6 b5 Q( U5 c: D' h  \& l* X;;;      ); if
9 t5 \9 S7 A- N" V" Q;;;
: S& n+ i0 X% O;;;     ARGUMENTS:2 d( T; j4 N7 s# I$ E/ O$ z
;;;       err_init Takes 3 arguments. : C7 r3 Y- E& @) y: }' E$ s5 D5 G3 A
;;;     1. - The first element of the argument:
3 h4 {% N0 ~; D. h- _# I; E) Y5 [;;;          This is a list of system variables paired with; q9 v* i8 ~9 Y
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
5 a% j9 W7 [* f$ @) {# b# d;;;     2. - The second element is a flag! g; e4 c" S4 S" S+ v$ Q! ?
;;;          If it is true, then in the event of an error % n! d7 j' y% X4 C1 G
;;;          the custom *error* routine will utilize UNDO . |, l7 c0 C6 b/ Q9 X  m: x/ T
;;;          as a cleanup mechanism.: N2 A+ H8 Q) ?3 H/ U
;;;     3. - The third element is a quoted function call.
  h" }; {7 p$ R- n, O) `4 n( b) B% A;;;          You pass a quoted call to the function you
; x; A  i- [  _) r& a3 E, @;;;          wish to execute at the end of nomal routine if an error occurs.
5 |0 p3 W) m5 L& Q/ |/ y;;;          i.e. '(my_special_stuff arg1 arg2...)% r/ A1 l' k& F, C) v- `
;;;          Use this arg if you want to do some specialized clean up 7 P& E  b8 X) j# @# O
;;;          things that are not already done by the standard bonus_error
& o  e# z3 O. y! A+ Y;;;          function.
0 A+ {9 D# T/ c;;;
* a% `: s+ y. o- w/ R$ e;;;    ERR_MAIN: Body of error routine& L: _% F0 ]' U9 Q5 l- D& S
;;;8 {8 H7 N* ^7 I$ `" j; S4 t) }" a
;;;    ERR_RESTORE: This routine should be called at the end of command to
5 O; M* A* T! n# ?* _5 ?;;;           restore the VARIABLES, UNDO & *error*.
4 ]# I- N% l6 z: ~  `5 Z;;;
  W5 d7 b6 r+ C+ T) g3 };;;    UNDO_INIT: Initialize the UNDO status3 s! {; J# a# I0 A! w: s+ a3 [7 O
;;;. s1 e! J& U& r4 E& l/ {) \( k
;;;    UNDO_RESTORE: Restore the UNDO status' ]$ M; _  R, f4 M7 W, G% a
;;;$ k6 ^% `9 C. l) a7 Q
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
  l0 t6 a% F. ?;;;7 A9 p' K& r2 M% [) P9 ~4 q$ O8 G' Q
;;;    UNDO_set: Set the variables. the argument is like
6 x0 `8 P; K3 ~* Q4 T8 E' d;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))3 t1 x- a: P7 ^4 e" a5 ^
;;;/ Q+ t8 @' v9 H$ ]% T
;;;    UNDO_RESTORE: Restore the variables
2 Z' i! z/ u( I8 h6 {9 |+ b, L: K% s;;;, O% s. V. E- m7 {8 Y: k$ C! `
;----------------------------------------------------------------------------! B0 y( Q/ p. X% q
;  GLOBALS:/ a. \% h2 d2 Y
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)1 e; j0 _( q# Y* p, Z6 ]
;     m_lst       -- list of variables (voided by VAR_RESTORE)% ]3 H8 h  J/ S. X$ z. G: v
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or) r  A0 K& k; ?) g4 g3 {
;                    ERR_OLD)
6 z) L2 s! E% @% K;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)7 k5 J9 c( ^  t9 l# ?/ Y" S& L
;----------------------------------------------------------------------------
: |" ?  e' u4 o6 b* @8 l/ w8 @- r4 l
# d+ ?: f8 i4 X;----------------------------------------------------------------------------0 J7 ]2 Y' H/ d, R
; Modify attributes according to entity name, attribute name, dxf_item; v9 H3 l7 P$ k1 J' a
;----------------------------------------------------------------------------
8 }7 v9 z  z2 U: t1 J+ k2 Z(defun mod_att(ent id dxf_item)        
; y8 O( i* Z5 `0 B9 p  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))( m* {7 v* j3 i8 z+ G
    (setq ent (entnext ent))
) X! ?+ L% c: C$ D& {& P. x  ); while  ) k& a7 O. m7 Z% L
  ((lambda (x)
3 l$ [8 p! m+ j        (mapcar '(lambda (y)
# P9 X; X3 r2 \! f+ {2 @/ M8 v                   (setq x (subst y (assoc (car y) x) x))5 [* m; s3 w3 X5 J. R
                 ); lambda! l2 Y" ^7 U/ ^- X) g
                 dxf_item/ m% l* {6 t& M; s4 \
        ); mapcar
, a: J4 J/ \) D# A  t, w     (entmod x)  k( t0 R+ t+ x  |. r  e
     (entupd ent)
$ @1 e% @2 a  A3 u   ); lambda
* v* j$ l& A  n# r% R) |   (entget ent)' f7 _; [5 R8 ]' N
)# m6 L& }; L% t9 A
); defun mod_att
: g  `* [. c2 G# T: w  q8 Z+ @' |. c+ r
;----------------------------------------------------------------------------
- z; {) Y9 f) H* t9 e( i* u; Check layer status, return a association list which contains layer information6 v+ e4 r" z5 p% V
;----------------------------------------------------------------------------
: |) C5 a2 H) E(defun laychk(lay / l_sta)! G! P- m( v  O3 g. i) y. t
  ( (lambda (x)# L4 e. O" d& X! ?6 a- ?' N
      (if (not l_s)* `: [: `1 |7 Z4 b' r' M
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))) y6 ^, d: H$ b% v% L& [
      ); if* J7 [9 m" Q# n. c1 r6 X1 F
    ); lambda & m3 q1 h1 s0 r  Z% Q, k& r2 e3 A, i4 r
    (getvar "CLAYER")
% V/ E/ ?% [3 E! l  )
, J) e) l& B5 l9 ~# T! }. V: j  (if (not (tblsearch "LAYER" lay))
0 l! Z* ?0 w# ?4 R) ~" ^7 s    (progn  
5 W1 `6 v' }- t; L      (initget "Yes No")
, I1 ?8 ?! A& z# v      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
2 X9 K  S; B' I) D/ C        (progn
' b0 p. e; f% M4 N          (command "_.layer" "n" lay ""), }, S3 l: u( k# z
          (setq l_sta 0): C- a9 L% v* j9 O+ p, l2 @
        ); progn
) o1 P# v( c& q% W3 G0 j- }      ); if5 o/ r) ?% d* s% h# d( \. d
    ); progn
! ~4 V6 [% O  i# }, o- |    (progn' P# y' z- G+ }# @# ]
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
3 q& w* [/ s; [' [# |* [2 c0 O      (if (= 1 (logand 1 l_sta))
# r/ G5 M' a5 V+ B  a          (progn* ?+ l( U7 [5 F  \
            (initget "Yes No")
5 Z/ ?6 M( b- ~& J7 N            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")+ [1 W( ?7 A8 Q- E8 \# N: H
              (command "_.layer" "t" lay ""). g  }& m) u& C3 g5 p9 u
              (setq l_sta "No")
5 {. X- }+ j+ Y$ h: H) E             ); if4 ]! D6 C1 o; v1 a8 U2 _4 b& @
          ); progn# m# G! P6 T9 p4 h
      ); if, }' e9 e: v* H, `
      (if (numberp l_sta)
7 ^9 s# b* I8 L        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
* w4 C1 f" }$ i$ I      ); if
5 D5 Z$ I6 j8 k    ); progn
$ U( g* A$ }, J  ); if* p! k5 a% v8 n# s' |
  ( (lambda (x)
! L9 @( o' i6 K# L  o      (cond & ~8 E' X1 B6 Q6 K3 `
        ( (not x)
; _7 y2 ?' B/ |7 Z: ?# K2 k% J          (setq l_s (cons (cons lay l_sta) l_s))8 ^9 F5 C- t" R$ w
        )+ y1 I9 l7 F. y' Z! D, G' R
        ( (= "No" (cdr x))- ^) m  f' a. ~4 Q
          (setq l_s (subst (cons lay l_sta) x l_s))1 j" h* h  Z+ u& x; U
        )7 D8 g' B5 T& S1 W) z
        ( T l_s)3 ?( R! g5 q: G
      ); cond
. g. v+ c* A( g8 `- S     ); lambda0 U* d& [4 x0 j: J5 x
     (assoc lay l_s)  ~6 ?9 z( i; r1 z  ]( Q6 v* B
  )+ S" L2 F5 N+ v! I' N1 C( n: ~
; H% r( A' W5 O: y
); defun chklay
  M$ x% ^# x1 f8 a9 t
5 f  a. ^! t* j7 R5 z8 |- c9 A;----------------------------------------------------------------------------! a2 j! W1 J. L: I" [! U& U
; Restore layer status according to association list l_s6 I5 @# ?" u! z0 b% W
;----------------------------------------------------------------------------
! S% f$ ^3 Q! v(defun layres()0 ?( u) @9 q9 N4 A3 L3 H% p: @. s
  (setvar "CLAYER" (car (last l_s))), v& I- d5 w: l
  (repeat (length l_s)" z- @8 @8 z1 U
    ( (lambda(x)  3 e' ^; K, B* V% F# Z. t& v4 ]
        (if (numberp (cdr x))
9 z& p' D( {2 V; c, F" y* i, G          (progn 2 `, D5 O% F& B
            (if (= 4 (logand 4 (cdr x)))
+ [5 R- I) L/ h% N- B: M8 [              (command "_.layer" "lo" (car x) "")" \' r4 G% R" F+ \, u4 {
            ); if
; W4 A$ ]) E' i0 l            (if (= 1 (logand 1 (cdr x))): r4 C4 X$ v' H" c" m% W
              (command "_.layer" "f" (car x) "")
8 \7 u/ S5 Q' [7 \            ); if8 W' O  A( W+ i6 ]' j
          ); progn- M2 u6 d* S4 A5 d2 D' A
       ); if  ) w9 X& E2 q' D  f: N
      ); lambda
4 {3 Q# j3 g7 \$ O# Z6 X      (car l_s)
: s" Z* @4 i# x! S+ G. A    )  }) P9 }( f0 U
    (setq l_s (cdr l_s))
3 z+ {$ r7 w! I  ); repeat. F- r* q  ?  t* m9 ~
); layres9 q$ F1 V' b4 b5 X: M: h
6 ~) R2 |# z- J, W& X
;----------------------------------------------------------------------------8 _& l9 _* ~* |
; Get DXF codes
& x, Z5 W6 B! ]( M; D- R;----------------------------------------------------------------------------* T1 y' l& q! F3 R2 J
(defun entgetf (index ent)
5 _# g9 n8 f, q* v  ((lambda (e)& `% ]* k! J. i# c
      (mapcar '(lambda (x)
6 W6 Z9 E4 [3 }4 T                 (cdr (assoc x e))
$ N6 }2 v3 r3 u: D$ [! ?               ); lambda& H: u0 @4 x1 E6 u. n
               index) ; internal lambda function
- ~; s  F8 o; O5 o6 `5 |6 ]* F    ); lambda7 K5 q) F0 h3 p& [- V$ }8 a
    (entget ent) 5 p" G8 l5 u2 }$ O4 y
  )4 W" @, V' S3 T
); defun entgetf! K2 ?: P: }& S- l
5 A) g7 B3 ~" n* z. C0 \) `8 L
;----------------------------------------------------------------------------( h0 S$ R- K" [4 J7 v9 v4 A
; Save UNDO status
$ Y, ?+ d- G. v: P" ~4 _;----------------------------------------------------------------------------
, t5 w, V4 j1 {' O(defun undo_init (/ cmdecho undo_ctl)   
0 \* f; k0 }( l9 m  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value* L3 d; C! P% A0 [0 {0 C( \
  (setvar "CMDECHO" 0)
3 e) t' R, Q; e& H" L/ O" {: P) ]) a' \
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
+ d4 d& t0 a0 D4 b+ P1 ]    (command "_.undo" "_all")& N- b6 d0 j/ `  m" R0 h
    (command "_.undo" "_control" "_all"): i- S2 [! m9 w9 d2 m6 Y1 N9 z
  )  u6 S* ~* K9 Z8 r0 a! \5 f

" v: n# k+ j" w0 A+ T- t( s" X  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off# C) y' Z# S4 O  p3 ]# K! A
    (command "_.undo" "_auto" "_off"), C, e3 I3 m$ y* ^9 ^5 ~
  )" F% j" i# Z3 W% ?+ b, R

) A( ]5 [8 r0 P, J7 h$ v& I  M" L  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
+ X0 l1 Y! D4 h/ ]* l* K" q    (command "_.undo" "_end")  s3 O3 s" H  @3 y/ `% ~
  )
% r' w  R0 k0 o* H1 w8 U8 u* E: B  _" h. I- o: \% A
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
2 |  w" c. l# S6 C0 m3 Z    (command "_.undo" "_group")9 n7 n$ D/ x, Q! O" n7 O1 O
  )& d" F: `* d. ^# ~! q/ ^% k
4 L' j- L" V/ p3 O- [7 ~
  (setvar "CMDECHO" cmdecho)+ a7 a, w+ U  ?7 Y
  undo_ctl
) u4 R: A0 }8 I" g& n/ f- ]1 y); defun undo_init
1 U5 W: ^; ~+ F
* Y+ _* ?- A+ M( Y0 i! S2 C;----------------------------------------------------------------------------; B3 K; p% U' F; h" f$ O
; Restore UNDO status  F; u7 a3 K' C  Y) o3 B; G
;----------------------------------------------------------------------------7 {* ~! a# U( X2 ]8 v; Q& @
(defun undo_restore (/ cmdecho)
# @# T3 Z6 p, |$ B+ ^. s  (if old_undoctl
, b5 D% ?+ J8 J; A    (progn
. _" x) L; C4 Z9 m      (setq cmdecho (getvar "CMDECHO"))
2 @; t! I$ U" {) f  r) M6 _      (setvar "CMDECHO" 0)
' q' c; |; r" g$ D  Q! k& m9 a# e3 s2 G/ o5 f" O4 M# w7 G
      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) # n6 H$ B/ h' Y
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
0 e& K* X8 O9 }) X1 z        (command "_.undo" "_end")# T2 a; N! w$ P# ~% }0 T) e
      ); while
9 b5 m5 W) {+ n/ ^* c7 _2 A% X0 Y  r) L
' r2 v7 c& H" H  r: U
      (if (not (equal old_undoctl (getvar "UNDOCTL")))4 N2 f& o+ N* m- F! ~' k
        (progn9 l/ V- `5 u0 @& w% o1 _
          (cond7 e. m% t0 z% U5 Z6 r: q
            ((equal 0 old_undoctl)
  o& ]; X# P" S) \              (command "_.undo" "_control" "_none"), k6 X7 v: P1 G# b: e2 E8 ]
            )# b/ w2 i* |/ }+ C: l- M( s; Y" m+ t
            ((equal 2 (logand 2 old_undoctl))4 @) E6 j; f2 i' B4 F! \' t9 }, Z
              (command "_.undo" "_control" "_one"): {' y: U' b  W7 A' ]; h3 D
            )
* O9 b! \: i" }6 _5 U          )
, T: U" b4 X2 c, ~0 a          (if (equal 4 (logand 4 old_undoctl))
0 s* M1 D1 Q7 l2 }' A              (command "_.undo" "_auto" "_on"), o7 ^, w4 E+ M
              (command "_.undo" "_auto" "_off")6 X) ^1 m' G% \; s  ]3 J9 k3 Z
          )  O1 N% c7 ^& {% y
        )
+ `$ X3 H, P: s3 Q, e+ q8 _      )
% [# O2 h7 U8 f0 w4 v      (setq old_undoctl nil)% t1 O" o1 x+ _/ K
      (setvar "CMDECHO" cmdecho)
% D8 R( q8 A: G! N, n    )9 V3 y4 T# p7 g& ~7 c$ l
  )# ]& H& ?: J& E1 D) ]
); defun undo_restore
4 \# \) L( t1 N% T. }
* {% ?5 I( \% T/ S* X# e;----------------------------------------------------------------------------' P3 Q* }" A7 b- |0 o- k% l
; Save variables9 w% v" g- d  {5 l/ x  n
;----------------------------------------------------------------------------
- c: n# t3 k8 Y9 w- j7 f(defun var_save (a)
0 g. S% T4 C9 n9 H1 k  (setq m_lst '())6 G1 n) ]1 D  u: n
  (repeat (length a)
( Y+ L& K$ ]( \    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))# |3 C2 _1 e* u4 `: q
    (setq a (cdr a))4 n$ O0 e+ r: T' ?* j) P4 j
  )
" y" C% i7 U. d1 b. i); defun var_save
3 M5 F$ @" g3 g6 ?& O4 i
- j9 Q6 b$ }" V- i+ i( _2 u;----------------------------------------------------------------------------' g4 f0 y, t, d# ^# ]. G% o* O
; Set variables- s$ [; d* Y  s6 Z$ ~- ?) O/ b9 ^
;----------------------------------------------------------------------------
: j- D, q+ D' `1 L( ](defun var_set (m_lst)
* x4 U* g$ E) I) h: q+ j1 q  (repeat (length m_lst)
+ E/ ^2 ]; F; ?    (setvar (caar m_lst) (cadar m_lst))6 G8 z0 I) ?5 J+ S9 Q( x
    (setq m_lst (cdr m_lst))
. ~$ [4 Y( v1 L  )
. I- K. u5 Y9 z4 \, z2 ]# s( z); defun var_set
7 t: {( F/ n2 j  m
0 p2 N6 @( O8 T) a3 i. r) g  @( n;----------------------------------------------------------------------------" C6 }7 E0 H3 r) D3 S3 c
; Restore variables, I+ ]8 u- w2 }  w" [( Z
;----------------------------------------------------------------------------4 C0 j4 \/ I$ N$ s3 S# x
(defun var_restore ()
( e) ]9 s4 j1 b* V$ c  (repeat (length m_lst)# a6 ?2 \% l! i* d
    (setvar (caar m_lst) (cadar m_lst))" z6 N4 S! s% \  N
    (setq m_lst (cdr m_lst))
# E) D* q- @  g& f* J1 Y2 I$ }1 q  ), ^3 e, o" ?: Y* _9 R+ @& N0 K. v
); defun var_restore
! b  C1 s) I  j8 t" Y' H( l5 u8 d1 a1 l  J- N
;----------------------------------------------------------------------------+ T( L  \' T/ e+ {9 S
; Initialize routine 8 [% ?8 h3 y! N- Q
;----------------------------------------------------------------------------
+ J$ _. s2 ~3 F8 D* w* \(defun err_init(e_lst u_enable add_fun)
) D2 R8 i% ~1 r  U. k/ C3 J0 P  (if err_alive (err_restore))          ; To avoid nested call
! e$ m9 }! V; Z( D9 w  (setq err_alive T)
( F4 n4 x  p/ |  F! g6 H/ ]  (var_save e_lst)                      ; Save the modes0 b0 Z; C7 M( [- U' l: c, }0 d
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status1 G% v" }  v- y- {/ M0 O
  (setq err_old *error* *error* err_main) ; Save the handle of *error*
% z8 O$ b  o6 X, X! i+ R, l  (if add_fun                           ; Add the user cleaner- r$ {, ]+ X4 n) O  n! d
    (setq *error* (append (reverse (cdr (reverse *error*)))
" r; c" |4 ^& `! `7 {                          (list add_fun (last *error*))
5 e; ~, ?* |5 i0 f$ `5 O. }, E                  ); append
3 Z- E5 G0 ?8 f" V. @! w. S    )
& {5 \, g4 U0 y# ?  )
2 W0 {8 _, w3 {5 }# Y  p( x7 ^+ W4 A); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------6 J9 W$ y2 S% ]6 h# E$ p
; Error routine body
9 U$ Z9 F: Q) b9 p! R;----------------------------------------------------------------------------
7 U1 ~: D( i, W+ P0 f% K, h% @(defun err_main( msg / )                ; Body of error routine
# F. B3 B4 ^, a' c; I! M: ]4 ~  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs
: m0 U/ f& |) c# s    (princ (strcat "\nError: " s))      ;while this command is active...2 l+ a. s) u) `* B
  )
' I' R( k$ p% K$ u  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command. N; |# c4 V8 k$ @
& }; `" F- m: N! n
  (if old_undoctl
8 @% c. e7 f8 x' N7 W+ \    (progn
* g) |$ P% Z0 N5 q+ C  B3 A      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
; Y, L' x  Q  \        (command "_.undo")              ; if it's in UNOD command
/ ]; k1 Y1 M3 m! k: L2 O      )' b0 U' W5 Q' _
      (command "_end")6 m% \% o* T) Y+ ~2 T3 {; q6 ?
      (command "_.undo" "1")4 D6 f( ^. F" r* F( x) l; t
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
& c1 S4 B* e  I' K0 o      (undo_restore)                    ; Restore the status of UNDO  S8 _7 D5 M6 |- p3 w! }7 x, N
    )4 }. D- {9 t7 U4 r2 ^7 i% Z
  )
0 g0 `. D6 a& ?) K% @6 S" z& ?' E7 e! `$ t1 y! o' Y' w2 ?; D, h5 r! W) ]
  (var_restore)                         ; Restore the variables* i1 o; h  B8 n8 }# f% k
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
2 a  o! V- I" u* D  (setq err_alive nil)
6 E+ e0 w1 p" a5 D0 V( |  (princ)# W. P; l( z7 ^' Y" }! a
); defun err_main
/ R7 E% k2 i* {9 x2 b6 I7 c% V0 Q' A/ F$ t! z8 ?& E; A
;----------------------------------------------------------------------------8 T. E& D" P% g( P# Z# u* a
; Restore error status
6 ^3 h  O  m, ~1 I  C9 x6 p! W;----------------------------------------------------------------------------, B. D/ R: g6 G1 z/ m
(defun err_restore()! A$ r" V8 T8 E' h
  (undo_restore)                        ; Restore the status of UNDO; x' w; y1 \  {' l
  (var_restore)                         ; Restore the variables& D( I- D' r) D$ j9 _6 ]
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
6 M: O, w$ V0 R3 S; G! S5 G2 ^2 d  (setq err_alive nil)
+ x" ?/ h# c" a& A5 ?) G0 C9 F  (princ)
8 J* I8 P2 _0 u: c" U* 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, 2026-11-28 17:17

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

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

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