CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:& B' [5 C) W0 [5 E) p/ R
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
; p: d/ b; b& }0 i提示:加载成功
8 s. g5 l5 N4 B0 D8 O4 m然后使用CLOUD命令,
! D: c( G( ?# @6 e; ^( ]提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
7 @1 C! ^* ^$ p; m7 L4 `0 U- Q; {请高手指点一下,这个是怎么回事?应该怎么改正?
# {1 M! O5 F4 J7 g4 R& ?2 l. o# f这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx3 y' {2 n/ r; N+ o
;;;
5 z( Z) e, }/ v;;;  DESCRIPTION
" t, F4 L1 r5 h, ^6 z;;;     Draw cloud and you can specify the globals variables listed below2 U( s! p9 W5 k2 |4 R
;;;     to decide the characters of cloud2 {# V, Q2 `. O  }7 N
;;;6 U4 d( H4 X% J" Z( I+ R: \, q# n! a
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
1 Q* f7 p% `8 J3 \7 R* t;;;8 z+ Z  t( c9 a) j
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
2 V3 @' Z; R5 G: y6 ]& ?9 l( ^& c;;;           Change CLOUD.001 to use CLAYER to perform the same function: O/ X8 `- T! \: f# s
;;;           Use the common error routine UNDO.LSP to optimize this program
0 f0 Z  q# C, C$ i; t3 E3 n;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
1 e9 b* h$ A  `2 A/ [;----------------------------------------------------------------------------
5 v: N% [4 ?/ o" K3 d$ P;  GLOBALS:
" ]' P" ]& I# s; @+ l/ g2 \1 s;     cloud_layer -- layer of cloud/ {/ p9 \% Z7 T# E% s
;     cloud_scale -- scale of cloud4 [8 u6 v5 b2 K. J* I2 F8 ?+ @
;     number_rev  -- revision number# p0 L6 ^% E+ l) }! a& X2 F( V
;----------------------------------------------------------------------------9 O2 g9 k2 n( ~: K! g
(defun cloud (/ locked temp first_point next_point relative_point
, @  W9 B) l7 @               last_point point_tri point_ref corner_1st corner_2nd length_tri
# k4 G5 b, [5 Y$ \1 y               length_cloud angle_l_to_f dir_tri repeat_count & I6 p7 a( N1 Q4 b2 W# I
               table_cloud )
0 x$ }3 r/ a/ J' E5 A        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))
6 g* M: M' d) M2 F! J          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
: Z# ]* Y5 G) ?        );if$ G* \0 x# Q: ^0 t$ K: L3 I
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"3 \! s6 M' [; T8 F: L
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
% F; U0 ?; G* d, f' v6 j1 {# h        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
: E- V- h* Q: M( i& s  d$ o$ o                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))9 |7 H' I1 r+ w- s& y

9 z3 b' a8 g% \' X) R: r        (if (not (numberp cloud_scale))2 n) T& D0 B. L7 f
            (setq cloud_scale (getvar "LTSCALE"))3 N( s& u  M0 \" e  s2 q
        ); if/ ^2 H6 S: G: i4 Y5 P6 `5 o
        (if (not cloud_layer)( H) W2 H4 h0 |  {4 ^; v
            (setq cloud_layer (getvar "CLAYER"))/ Y! o- I0 y( T* E
        ); if
" w# A! K5 Y0 b8 T# t: V& |$ y: u        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
% T: q1 p, J  L        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
# S; ~2 H: @" z! Z' \* q  t0 j        (if (= (cdar (laychk cloud_layer)) "No")
% @# S# ]  M1 g/ I4 S1 f3 J1 O          (progn% U/ C; l! u: s' V
            (laychk (setq cloud_layer (getvar "CLAYER")))4 f* |" m# q, P/ Y3 Z! e- U' |& m
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
0 C/ _; V* O# F6 N* I* B: j* X          ); progn$ M7 e( ~& c& T2 ^# }/ l1 q
        ); if
) k' I( r# P  y. s$ k- e
* C3 T$ h1 p( u! x8 w% l3 ?        (while (/= (type first_point) 'LIST)
! a% `; Y/ m, p7 z! P/ G' e          (initget 1 "Layer Scale")
6 ?" {$ c, z. w0 f# c% o          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point). j2 E  Z  D9 l" K6 }
          (if (= "Scale" first_point)      ) x; H$ y' u. F
            (progn; d4 P/ i/ n! }/ a3 J* i) B" j
              (setq temp cloud_scale)" g5 L) G& p& p0 f& T) ?
              (initget 6)
" l7 T6 C" \: \, b              (cond- d# P" ?% t, d2 ]4 f  a
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"9 h& C- w, I9 f6 O# i0 C$ q
                                                          (rtos cloud_scale 2 2)
3 h' B# Y$ f5 d                                                          "> "))))
. O  [8 ?5 j2 ~* j& u                  (setq cloud_scale temp) ). ?: _$ \  v6 q' \( v: F
              ); cond. ^! @# Y& p' e# m& |
            ); progn
% u& x* ?) {# h          ); if
: G$ m: c+ z" D9 U; k6 V, n          (if (= "Layer" first_point)( j! F7 H+ b' r2 h
            (progn
. W7 W) l: l4 _* g. Z              (setq temp cloud_layer)  j' ^+ H8 `  S, C, J
              (cond
2 }+ }: `6 q  G, ^5 A                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
/ ]  C! ^. e8 G+ e( G/ _                                                          cloud_layer "> ")))1 K- ?2 I6 i* s2 `- U" z! x4 I8 w
                     "")1 G5 p4 n* o1 G: U3 O
                  (setq cloud_layer temp)& a1 [$ R( |& Y2 B4 W
                )
4 v  |% F9 |" ?% ~5 x/ x              ); cond
- M7 L$ M/ ]# a/ [; a              (if (= (cdar (laychk cloud_layer )) "No")
2 T# \6 R) r" e9 [) U' I# S                (progn9 p7 H/ B. I: l1 {3 J; [
                  (setq cloud_layer temp)9 u3 ^3 [% Z/ q( ?2 t
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
( n, c$ `+ T& l- S% ~; r                ); progn3 `& X( Z: L7 c( `3 F
              ); if
' u; n6 ^! F0 r+ G            ); progn! o& B9 p( }! C2 \$ g9 t
          ); if1 a* j) W! x+ C& A" R
        ); while4 i! t( [7 p7 Q6 e3 {, s: B
        (setvar "CLAYER" cloud_layer)
0 B# i, C0 u2 J
2 L* K' A1 u# d5 r! J/ [+ }        (if (>= ( getvar "LUNITS") 3)" g4 \8 H: {* `' W+ d$ y
          (setq length_cloud (* 0.25 cloud_scale)$ f0 C: A* Q: }& K% B% |! \
                length_tri (* 0.3125 (getvar "LTSCALE")))6 p7 A8 h# W: t
          (setq length_cloud (* 0.3406890 cloud_scale)5 B, u% s6 J' m5 o' ]8 v; ]
                length_tri (* 0.438366 (getvar "LTSCALE")))& B) K; |5 n5 A1 k. G
        )" x. D1 M  Z2 q, f4 K" r
        (command "_.PLINE" first_point "A")
7 R) V/ S& L: `- e0 t, v( o        (while (not (equal next_point first_point 0.000001))4 h2 r( }/ \) j) m! |* o
          (initget  "Close")
1 Y9 D5 O$ T  L* L0 F          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))- |/ A5 ~1 O8 z: A" v
        (while (and (not (listp next_point)) (/= next_point "Close"))
; t1 Y% @4 N5 Z. b( i. Y7 j          (initget  "Close")
5 a% p8 f5 `- Q3 h% W          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
) R: v9 W. u! }4 A' }/ `        )
/ O2 \% e0 o3 U8 i: a; N9 A          (if (= "Close" next_point) (setq next_point first_point))( H) g* \  B+ v/ U$ a8 n  H
          (setq angle_l_to_f (angtos (angle last_point next_point))$ M+ D) c8 r) x- h
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
3 |% g( A" U6 n6 l* h          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)% R' {- n; a4 g
             (setq repeat_count 0)
+ B0 ~, V  y$ [0 \5 z5 j0 w             (if (>= (- repeat_count (fix repeat_count)) 0.5)
( L7 B' h4 j$ U8 W( M               (setq repeat_count (fix repeat_count))
4 H6 d" g6 ~: [+ f               (setq repeat_count (1- (fix repeat_count)))1 v. G/ C1 e4 A2 ~7 ^  V) R
             ); if ! C6 @, _5 h( T) g7 S
          ); if+ @8 w0 m% U. m2 `) h* t7 l3 Y2 e& W
          (repeat repeat_count (command "A" "-100" relative_point))5 y  D& j$ d3 _! L; J' }- u
          (command "A" "-100" next_point)
: G8 R6 g2 H5 Z' o/ p4 U$ j          (setq last_point next_point)% l& C& X# t8 S- y2 Y# l( O
        )
' `; h4 {/ M* V+ w% n6 v8 U        (command "")6 j6 g/ E$ R. ?
        (if (= (type number_rev) 'INT)4 H0 |# t# b- ]1 n1 O" R9 C
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。")): z+ J8 R/ a6 P! Y- y" h8 a
           (progn
2 ~, e0 n+ E) e; O. Q             (initget 5)
. ~5 y) B6 ?, x4 Z) [             (setq number_rev (getint "\n请输入版本号:"))
. w: O& |4 [& d$ [" P6 K6 @           )
9 c& Q; o* R9 e# {  `4 p6 G1 J) j) r        ); if
9 i5 q% s' U  ]& q/ a! n+ s        (setvar "OSMODE" 512)) k3 G! l6 s' C: z8 G% d
        (while (/= (type point_tri) 'LIST)
) U+ z+ i. J4 `          (initget "Number"): v4 g! y: L6 o# D0 ?2 P
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))( z; t2 y4 ]! B' W1 }, f
          (if (= point_tri "Number")3 i3 U% g/ @6 ]
              (progn
1 o1 N2 g1 W, o2 L( p* o                (initget 4)
+ n, a5 v' c& R+ F; H                (cond0 j8 P8 I0 L7 \
                  ( (not (setq temp number_rev 2 Z1 m* N5 t7 n
                               number_rev4 y; o: M$ Q: v0 f  g0 k6 D- I
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
$ P2 m. h3 d4 ^* g7 v# V* _                    (setq number_rev temp), ^: K$ m  e" ]# h5 `% _
                  )
! d  a' h" I5 _4 E0 h. M                ); cond$ r  ], Q+ W$ z5 U' C# S# R
              ); progn
) Z( {# z7 f- r. ]3 i          ); if# c* Q4 p$ F3 s/ C8 Q
        ); while' Q8 X3 ]. P* ]
        (setvar "OSMODE" 0)
- Q7 [" P9 S- V3 v& ?7 R, G5 _        (initget 1)
% o& I" L- L+ E! o        (setq point_ref (getpoint point_tri "\n请选择方向:"))
/ L# @) G. U5 q6 A) s6 [' |; o$ w, V        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1)): n* u2 @" W' O
        (setq corner_1st (polar point_tri
* |8 _. y% x+ Q  A* p: A                                (+ 1.570796327 (* -1.570796327 dir_tri))- f: f* o, B; s
                                length_tri' K. C& ~: {% b
                         )% n, d0 V- c0 v7 X
        )$ f2 J# c6 ]9 c
        (setq corner_2nd (polar point_tri
  k3 M2 C* j4 E+ \2 |7 b* l! f& q0 h) L                                (+ 1.570796327 (* -0.523598775 dir_tri))7 `5 ]4 l( W2 `; v' R' `5 r+ R/ C
                                length_tri1 O: }7 }% R6 P) r7 J
                         )
- `/ m" u6 X# H5 I- m0 o! x        )
2 G; h! x' d7 q2 N* O        (setvar "CECOLOR" "2")
2 Z0 ~) p6 e& L& T' O2 D3 s        (command "_.pline" point_tri corner_1st corner_2nd "c" ), {. a* R6 W/ L; Z5 o( F
        (setq textstyle (getvar "TEXTSTYLE"))/ J8 z0 c( k) r/ b. C  b  S
        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
( Q  K, u+ b& }$ \5 \        (setvar "CECOLOR" "7")8 Q2 _% z  v& Z5 s
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
: i. A% ?! z8 r, _  s                  (* 0.4 length_tri) "0" (itoa number_rev))  y+ k6 d+ o! h- V0 \& I' t
        (layres)
- R- H  D& A3 j, P; |" ]" t4 N        (err_restore)* u$ g- c& A* o8 g
        (princ)
7 y: k- c9 R$ J# D); defun cloud, \, v$ T6 W) e$ p" `) f/ }  H" C

3 g8 W% Q0 c( Z. L  q(defun c:cloud () (cloud))
3 B$ C! ]( P1 o, h" ~( X- [(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy+ s4 T. ^/ W1 K/ L
;;;
* O" d* H1 \4 W3 K2 w: D;;;  DESCRIPTION2 ^, S4 g$ ~/ ]' @. E$ V1 n, q
;;;     These are general error routines which can be called by
9 [0 w0 Y  O+ r. U6 Q7 l; c8 R% L, L# ?;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference8 [/ f  c' g; Y+ b& y5 _+ ^
;;;8 j8 c' h+ k& t( y; o3 l
;;;  SUBROUTINE INCLUDED IN THIS FILE
0 p- X$ n6 `; p) ?4 F5 D: |/ Z# _5 y;;;     UNDO_INIT/ U' {- k( g: P8 C+ H3 ~4 u
;;;     UNDO_RESTORE- v  I* I) _1 Y4 Z3 m
;;;     VAR_SAVE 4 a8 J6 R6 b' ~0 ~, g
;;;     VAR_SET  6 I3 b5 R. r/ }9 L$ p/ v9 \7 l
;;;     VAR_RESTORE# N  Q7 ~! Z* x
;;;     ERR_INIT ; k( r8 I* [7 a* O( x6 [. m* n. y5 e
;;;     ERR_MAIN ; Y) e: O+ L. O  J# R( U5 \
;;;     ERR_RESTORE% D: f/ X/ s3 l; A% e2 G0 R7 F
;;;
# `/ `& e; D, E6 q9 {;;;  DATE: 10/17/98; 03/31/99
  o" J- Z# S* o6 m( h) D3 q;;;9 u/ b1 r6 F# Q9 L. @% h
;;;  HISTORY:
2 F9 S. W. i( N0 h1 B;;;    Add routine of mod_att! h2 F8 [- w) P; a6 F" k5 Z
;;;9 m- R9 u- n. [4 c  @) u! {4 O
;;;  USING METHOD6 E. n  t& J/ ]* {6 {$ x
;;;    ERR_INIT:
4 v7 T. S; a: x/ q6 w;;;      This routine initialzes the error handler. It should be called as:# Y/ ?; c/ b0 a5 }
;;;# \- U9 M: @  I
;;;      (if (and (not undo_init)+ B3 ]! a# N! g
;;;               (equal -1 (load "undo.lsp"  -1)) - q7 {8 n% y1 h  f+ m  I" z
;;;          );and
2 k) y* l) o4 Y5 }0 H;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))6 J* k: W3 ^+ a" b: u6 W
;;;      ); if
8 r! k4 s) e. G& l7 C;;;
5 p( c7 V9 O2 R8 X;;;     ARGUMENTS:" r! c3 F# J2 t) Z2 y! n: ^2 D% t
;;;       err_init Takes 3 arguments.
' @9 A% t& w- u  m8 Z9 B. @! E+ Y;;;     1. - The first element of the argument:
  T5 Y3 `& h0 s$ J;;;          This is a list of system variables paired with$ ?4 }; z& R* f/ N4 R
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
4 m' o8 b/ {- b8 f" k* O+ G, z;;;     2. - The second element is a flag% S, ~8 y6 t$ H. u0 [8 m: F
;;;          If it is true, then in the event of an error ( g9 p2 a3 P7 ^) C2 q2 V
;;;          the custom *error* routine will utilize UNDO & A4 c; O9 R# z+ p# t4 R# C
;;;          as a cleanup mechanism.4 D; u( l* |  r6 h' i; E
;;;     3. - The third element is a quoted function call.* o/ n( o/ i8 y  M" s% ?6 {
;;;          You pass a quoted call to the function you
- D7 `" P. }2 g- r) D;;;          wish to execute at the end of nomal routine if an error occurs.
1 r0 W8 W  k& P1 M4 K( }( Z;;;          i.e. '(my_special_stuff arg1 arg2...)
! O& Q( \4 K, X( n, K;;;          Use this arg if you want to do some specialized clean up ; P1 e* L" g! ?5 F/ [7 n* g
;;;          things that are not already done by the standard bonus_error
1 Z# d3 d; y0 s, ?/ [# k;;;          function.- f6 {6 ^& ?* R( [8 w3 `1 z
;;;$ [8 N1 o) ]  P6 ^. {9 g' _  u1 M
;;;    ERR_MAIN: Body of error routine) z4 Z- T2 C$ d8 u) Y, U
;;;
5 I/ x" c# F% W6 A1 Y+ p;;;    ERR_RESTORE: This routine should be called at the end of command to
+ s7 d! R. s1 u8 Q4 x. R;;;           restore the VARIABLES, UNDO & *error*.1 l/ {! q* F% M7 E3 }( C
;;;7 x2 u6 S8 ^" x8 D2 S- z0 w- u
;;;    UNDO_INIT: Initialize the UNDO status
' w- k% R. }; i5 s; G;;;
4 j2 ]! r) U$ Y& Y. O( G;;;    UNDO_RESTORE: Restore the UNDO status
$ n4 `0 h7 o; E# T+ R3 a4 ?;;;7 r% T' E  d+ B: ?# k$ b( t* M: @
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")) N; W% ?2 T9 p( o% |
;;;
2 C# E, v8 V$ G;;;    UNDO_set: Set the variables. the argument is like
; V7 `; e! K& R9 h: {- K. I;;;              '(("CMDECHO" 0) ( "ATTMODE" 0)), _. n9 |8 l0 q! [) ^4 W' _) Z" z% t
;;;$ L: ]9 ~+ j3 X" w  h5 K
;;;    UNDO_RESTORE: Restore the variables9 N$ O5 `4 D! g4 n; k1 E7 Y  T
;;;
3 Z, K+ e$ u  p) C7 R/ d6 d* {;----------------------------------------------------------------------------( b% o# c  z+ L$ j9 W" w$ c7 q
;  GLOBALS:1 e% b/ A/ e4 s5 ~) R+ X, ^
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
7 d6 @  b9 Q* K/ @* G;     m_lst       -- list of variables (voided by VAR_RESTORE)- s% G# h$ q9 W$ ~: Y
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or2 }7 i- }, ?8 `: ]$ a3 k
;                    ERR_OLD), {( B9 F+ b& f9 F9 P- V
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
0 j! ?6 ~$ n. q;----------------------------------------------------------------------------1 H& _% P* F# H  I( V/ K8 L
6 B+ h2 Q7 D1 d
;----------------------------------------------------------------------------
3 G6 k9 e/ Y& O. c; Modify attributes according to entity name, attribute name, dxf_item
+ X7 R, s9 e* `# A+ ];----------------------------------------------------------------------------
; t7 n# u/ O# R; F% Y/ E! J(defun mod_att(ent id dxf_item)        5 ^4 y# }) c. F
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
5 z4 S. C3 E' E8 P  K. f2 X    (setq ent (entnext ent))
4 V8 Y0 }2 I2 ~8 Z  ); while  
; H$ S9 e* c! p! a  ((lambda (x)1 |: z4 H; `7 }& C+ Z' r) W8 J" S6 o
        (mapcar '(lambda (y)
0 B; }  ]- x1 q/ u. ^4 N                   (setq x (subst y (assoc (car y) x) x))
& b1 v  g) o. `  ~) [. h- R3 N9 P                 ); lambda
: P. i2 C4 D4 g8 J; `0 F2 x                 dxf_item/ E1 B# r  F6 H: U# x) s3 o
        ); mapcar
  ]8 c) V: i* D; P1 @5 j     (entmod x)- ]1 S! Q7 q/ P
     (entupd ent)
& `) L& V9 F) D" Q# \   ); lambda
% c+ g! U, P+ j4 M5 }! L   (entget ent)
( `, n2 J6 p9 C )/ q; y) D1 R( N6 G
); defun mod_att+ @* `( c) }& _# ^
- X# `) _2 I3 b9 C
;----------------------------------------------------------------------------# z- }8 x% Q, ?# p$ X4 x
; Check layer status, return a association list which contains layer information2 Y: U5 j/ v( @9 ~  O$ k: e
;----------------------------------------------------------------------------! N; i5 Q5 G3 x% B$ l9 i( X% U& j: [
(defun laychk(lay / l_sta)
7 q: z7 w% q+ P  ( (lambda (x)
3 q; ^) S1 D8 a* B1 g6 p6 ]$ L      (if (not l_s)% x1 }7 b- w+ [& j. K
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
5 F: w5 F% L" b$ `1 y      ); if
2 ]  R( C* B" `, a    ); lambda
& G4 [. ]; D. H    (getvar "CLAYER")
; c( R% p6 Y5 b: m  )! r' z0 F3 r: Y! a+ n1 s
  (if (not (tblsearch "LAYER" lay))
- r! C- R$ b/ y2 [+ ^( o6 G    (progn  
; j7 y" ?5 ]. A2 O      (initget "Yes No")
2 O  R, r# `! Y2 T' H' W      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
% @+ _: I' F1 B        (progn3 `5 K6 w* \% l% v( u
          (command "_.layer" "n" lay "")# E# K+ `' T: Y, g' G% D
          (setq l_sta 0)4 [) p( Z5 W8 ^9 I! i* D2 x& g
        ); progn7 W' \( e, ]( \) s. B1 {7 N9 B
      ); if
; y9 u" y$ m) ~& O    ); progn3 |9 U* r# h3 X' P, c
    (progn; m; f7 h' l6 ~' e
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
* X8 p# V! @% q( S8 ?      (if (= 1 (logand 1 l_sta))# C1 u* u% U2 u
          (progn
& ]1 B& i$ O3 S            (initget "Yes No")( E/ U( c) l  V* ]6 k% d
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")" c% a1 i5 r0 F  o( h; E% O' @
              (command "_.layer" "t" lay "")
) S$ C( m9 Z. |- v              (setq l_sta "No")
2 \: z& q7 v/ s. `0 }! D0 O) E             ); if# g7 t6 \! E9 Q6 w3 l1 t
          ); progn
( a) M- p; O. ^$ Z      ); if
, _( }: \. Y7 t: Z) T9 q) ~      (if (numberp l_sta)
) H' [  j) |2 M        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
" t! z* {' m% m0 }      ); if
! A1 M& d- B! ], d9 b4 A3 I8 |: W    ); progn* d. J$ d7 d2 V/ B) j! v4 g
  ); if
% T5 r$ @) m8 U- a  ( (lambda (x): Q1 H) k1 V" Z% r8 w  [2 {
      (cond 7 a& S' i6 o3 ^" m- \3 K+ S6 j4 Y
        ( (not x)9 M% {. F8 p9 }/ W
          (setq l_s (cons (cons lay l_sta) l_s))- \( \3 n7 G: `% L1 O% M
        )
% p, `+ z; U  H& m        ( (= "No" (cdr x))
- y1 x$ a) |9 ^, d          (setq l_s (subst (cons lay l_sta) x l_s))  D2 S' H" Q0 r6 E4 g- p6 }3 f
        )$ M5 }% Y# }$ [7 P, j7 \7 F
        ( T l_s)( U% Q  ^) U, M2 w$ A4 y2 q
      ); cond
2 R2 r8 G5 M7 y5 r/ \/ v6 b1 r     ); lambda& l4 P( j6 w* S. t# _" M
     (assoc lay l_s)9 @% g' e- p% |" `/ ~
  )
6 n6 A4 }. @8 ~, f8 n0 H
2 ^. K9 \7 g/ E& i, X2 V+ ]  I); defun chklay$ D; \! w: K, P
1 z7 L& m: H* V' Q# Q/ j. M, E
;----------------------------------------------------------------------------% I( w$ j! ?0 m5 \$ v( f% _; k* T
; Restore layer status according to association list l_s
' R7 S: @* }% X% N. ^4 n1 [* b& v;----------------------------------------------------------------------------
/ g' l- R2 v2 g: q- }(defun layres()& I/ @7 I, U& b; _' F- q8 p
  (setvar "CLAYER" (car (last l_s)))- }+ U- H9 m9 e+ E$ t9 ]
  (repeat (length l_s)
) J4 q8 ?, s, }: A4 [" X* j5 m    ( (lambda(x)  / L) A/ Q( {8 \
        (if (numberp (cdr x))% E* g; p, A0 b" l8 o
          (progn
% |* M. g. A! T8 r, g9 D0 |            (if (= 4 (logand 4 (cdr x)))
. X3 d3 l8 ?2 q( M6 H3 s" H              (command "_.layer" "lo" (car x) "")
- s6 ?0 ?  s' s; i2 w8 T# Q( A            ); if% w. v5 \% V8 {3 r, z
            (if (= 1 (logand 1 (cdr x)))
# U3 M6 h7 Q8 @$ _9 \              (command "_.layer" "f" (car x) "")
! z9 Z6 I% ]2 x8 v: D            ); if
/ |( K0 A1 U8 `' a, h          ); progn0 c; K5 F' n0 s( k. k
       ); if  
) D) y+ F9 d$ K( K- t. ?      ); lambda6 p5 v( J9 i4 Q' y, y& S( O  X
      (car l_s)! V( N2 d- F8 U, Y7 B+ w3 n
    )0 C3 ^; }, x! @, z
    (setq l_s (cdr l_s))/ c. Z/ C# M$ [8 i1 `: L2 D5 {
  ); repeat
  ^" i( t$ \. F2 o- X); layres& g3 h* }. e  F+ e8 k* i& ]: Y8 P/ u
) a9 g6 M  c1 w8 J" l- R/ n8 h
;----------------------------------------------------------------------------
: e! N7 b7 m7 s8 N' _- X9 S$ g; Get DXF codes, g! y% b% i( A! R+ l( D: ^. f
;----------------------------------------------------------------------------
: S6 Z( J  ^5 W# d( Y(defun entgetf (index ent)
% X8 I5 M, b3 c7 ]& v8 }* X9 n  ((lambda (e)
7 y* r4 l" H1 s" F      (mapcar '(lambda (x)
% b  l; p6 `5 K3 n, j- v" m                 (cdr (assoc x e))
! v9 B/ W% K3 p9 }0 ~1 Q               ); lambda9 W2 R, p/ i& x+ f. `& v6 ^
               index) ; internal lambda function
" H% J+ w6 @$ Z" {/ y9 H3 s5 N6 \, E    ); lambda
4 Z' j# T: {1 a% |1 v    (entget ent)
. q& y, x7 r  C0 _  )% {5 T! R( Z4 d+ h) ], c
); defun entgetf
0 ^# }2 ?" F$ x. Y3 h' D( U2 x" r
$ O5 x0 g8 k. i% H2 {$ W;----------------------------------------------------------------------------5 a9 A  U  B' }# [" L
; Save UNDO status
) G& f& p+ w+ U, O: i2 b' @;----------------------------------------------------------------------------
3 }; w; W$ f4 n(defun undo_init (/ cmdecho undo_ctl)   $ @7 ~1 C" ^7 m+ M" `/ P+ E  }# n3 z
  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
& M& X- M& X4 e6 q! Y, ^* U  (setvar "CMDECHO" 0)
6 z7 G. F! i- r; A- t
) r2 }8 L- ]& z) E! s8 A8 |0 }  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
: m2 m/ }' |- p+ C2 y  i; t+ j    (command "_.undo" "_all")- ^8 @  Q! I$ H! m6 Z3 T3 m# l9 }& M
    (command "_.undo" "_control" "_all")
2 y& f5 m" S7 l% o# |2 P  )$ K- J* `, G/ I1 w3 z
( \6 D; T" C; x7 Q5 A6 j
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off  J- t" p3 t; ?3 g9 L8 m6 z
    (command "_.undo" "_auto" "_off")& i* }0 B7 m+ v( L* v- z
  )- X9 F! _9 R) D
3 L6 ~+ M9 g- j3 G3 [* F8 \
  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
. u- C4 e  U- B$ M* V    (command "_.undo" "_end")
4 D3 ~. {2 |2 z  )
; {, r8 }7 C5 ]8 e1 Q% p
" K, R; ^' _- r0 _  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
0 R  H5 V  N7 ~) P    (command "_.undo" "_group"), d3 H8 o2 v; ^" p* B
  )' N5 c' i  C/ g: y- t# q  X

0 ]9 e: M2 a# K- `- T  (setvar "CMDECHO" cmdecho)# a" Z  u1 s) t; u) Z. U1 [) P
  undo_ctl
+ X' r8 B- Z7 i); defun undo_init; ^* [4 O7 n1 j% e* f1 \( c7 Q
5 A' S: q. `7 F. t- a9 a2 Q
;----------------------------------------------------------------------------
& R# B- w' Q/ B/ t; Restore UNDO status
( L8 j! l7 z: ^. E2 U) c& S;----------------------------------------------------------------------------
" z% J9 O$ V# w(defun undo_restore (/ cmdecho)
) u$ F$ e. z+ S5 ^- d0 p/ J  (if old_undoctl6 D- N" F# Q2 y1 r
    (progn
2 f& G8 B! W# l      (setq cmdecho (getvar "CMDECHO"))
7 A8 N& G1 S) g$ e' s& C: c2 P2 z* }      (setvar "CMDECHO" 0)0 W& U( K! a* h- @" |9 v  y$ H

3 u% N: ^, r0 Q0 K; L+ k3 P3 ]! d1 c      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) 9 X: L) I9 \, ]4 m( E2 x+ Y
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
, x: h! t9 ^& t# F1 @2 j0 ?        (command "_.undo" "_end")! i# U9 ]! J4 m( p8 k
      ); while# Y; T6 F- k2 H9 |2 F

, X' J' p- Y* ?1 j
' w) [# x/ }: R! J+ Z& @      (if (not (equal old_undoctl (getvar "UNDOCTL")))
) K0 }1 P, B  H) ?4 y# g5 Q        (progn
. |' {, `% U; h. \  y, |* O4 f          (cond
& C9 u1 Y- [2 Q9 n* b, F' I            ((equal 0 old_undoctl)
6 N3 ]: f/ w$ U" M) G8 |              (command "_.undo" "_control" "_none")6 ?, n6 H* X% v7 I9 w5 O) Z
            )
) i& G. q7 R% D4 b            ((equal 2 (logand 2 old_undoctl))
' u0 c) l- B6 ?/ v              (command "_.undo" "_control" "_one")  q) `3 U4 {) h* x! ?& G  y
            )  y  L. ?0 e& h- y( v0 e) r
          ), v, E$ x- \$ m' O; j4 p
          (if (equal 4 (logand 4 old_undoctl))& j. `  J9 I3 R# ]+ {
              (command "_.undo" "_auto" "_on"), b/ y5 x! X, i! P7 f( Z
              (command "_.undo" "_auto" "_off")- u5 k) W- \+ o7 Z4 L9 J
          )2 }- T' b  |# f* {: M
        )
9 W( Q4 _! u! s$ m! d* a' a- p4 x      )
4 C1 R; w* T/ F* a4 I' b' }      (setq old_undoctl nil)- b* c) c; @: c" d/ ?& W( Y
      (setvar "CMDECHO" cmdecho)' A: O; N/ P$ l4 t2 B
    )( U% d1 h4 b5 ~
  )
& F, Y) D5 Y0 v; x; H); defun undo_restore5 I% }! o1 M& H6 [/ w: A4 T: s

8 d& V! Z+ ]6 E7 O% g  M+ J+ J;----------------------------------------------------------------------------
. A  N" M) I4 Z+ l# x3 W; Save variables* r) M% H# z4 C% F' O) I' W
;----------------------------------------------------------------------------
! @4 T: o0 p+ U9 C(defun var_save (a)
" e' U5 |& n' B+ f9 V6 K  (setq m_lst '())5 W! M& K- q+ r3 E* l
  (repeat (length a)( s5 ~5 D1 I) }3 Q) m' D7 a
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
+ [8 K* N( J% [) e2 {4 G    (setq a (cdr a))
7 Y* d6 b; R6 ?$ V! O  )0 [* V1 |# p& b$ s; _3 ^
); defun var_save
- I' i& Y- A0 w* o
* O' A2 F! L! S9 H;----------------------------------------------------------------------------
( r* K  }" [8 w2 t; Set variables) p1 ~9 c7 ]- X; @/ w9 f. K6 t) x' m
;----------------------------------------------------------------------------
; A4 c! v5 e7 S4 z- ~5 u(defun var_set (m_lst)2 J* x* G# i8 K8 B0 N7 j0 A
  (repeat (length m_lst)( g- `- M4 l( ?( i1 ~
    (setvar (caar m_lst) (cadar m_lst))
3 q! S( q' g) o' Q! n! Z; n    (setq m_lst (cdr m_lst))
6 Z/ ?, T  f& j1 q; }3 ]9 x  L' ^1 }  )* e8 [0 A) H5 o* Z
); defun var_set
' `8 X6 V: A( {/ l) u; |- Q/ `) N' g( ~
;----------------------------------------------------------------------------# g, S: ^$ y* d" F3 H
; Restore variables1 S# B' a4 Q* B) G1 }
;----------------------------------------------------------------------------
7 n! y$ C4 B2 i* P4 p2 L(defun var_restore ()
+ P6 f( ~7 W0 d$ k% W4 x  (repeat (length m_lst)
% u. n. W  d% I# J: y    (setvar (caar m_lst) (cadar m_lst))
. D) b* s6 M; @- P; T    (setq m_lst (cdr m_lst))
; n0 q, n  k+ }1 m( C+ _3 ^  )3 v% l. C# B+ [1 X8 R% G0 K
); defun var_restore
8 A+ @0 s; P/ }7 f+ o) q4 M3 j8 f" G4 N
;----------------------------------------------------------------------------1 `! N' v3 I7 o( h( C
; Initialize routine
1 t7 F) a1 @, k# ^" T( v& G;----------------------------------------------------------------------------/ ?: _3 d2 c, n5 r2 x; w
(defun err_init(e_lst u_enable add_fun)" p# f; @9 ]. B5 [9 f
  (if err_alive (err_restore))          ; To avoid nested call) S; o  J6 {' U- A$ `5 [/ }& o
  (setq err_alive T)7 r+ [# K1 H& e! j
  (var_save e_lst)                      ; Save the modes- q. d# v0 N1 h3 i3 K
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status
+ _% P% |" ?7 ^  (setq err_old *error* *error* err_main) ; Save the handle of *error*! v8 V: s7 ?0 k  f8 X: M  j/ J* [; G
  (if add_fun                           ; Add the user cleaner  L+ r+ b' F0 K1 `
    (setq *error* (append (reverse (cdr (reverse *error*)))
" [' ?5 x  s2 m  T5 r9 X. p                          (list add_fun (last *error*))
6 w- X. D6 E6 s                  ); append
$ ]& ]# g- T5 G$ l, s+ a$ S7 T: L* a    )
! j, X4 Y2 W. z2 j7 J# {1 r( ~  )
3 J* z, t7 b. O3 l2 p* j( V9 m9 _); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------# e4 Y+ a# h& Q8 {1 K6 a
; Error routine body
6 A0 P( |5 u  o* X3 M;----------------------------------------------------------------------------
6 J6 V% K) H( k6 q5 a9 D(defun err_main( msg / )                ; Body of error routine
% M# K% Z! y% T8 U; N: E  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs' `- O/ t4 r# N, C! ]: k
    (princ (strcat "\nError: " s))      ;while this command is active...
+ x( K# a, A* ?7 U  )
9 x9 w& ~7 A2 |/ g$ z" S  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
1 M' m' W, a. Z1 X( ?' {* f  P4 ?% x& f- i) f  j3 [
  (if old_undoctl- L- l# U  Y2 [% h
    (progn
; L0 W' U: f: o1 v  O9 W* J      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See0 n* T) }0 F: t0 v' ]* j
        (command "_.undo")              ; if it's in UNOD command
+ c/ Y1 k0 f0 J      ): R3 f) m, j* w4 p' j/ d1 y7 Q: o
      (command "_end")* N# Y' q8 J: V
      (command "_.undo" "1")
& t& M* v" o$ l      (while (not (equal (getvar "CMDNAMES") "")) (command nil))$ g# Y8 t9 C" M; Z5 X, z, h
      (undo_restore)                    ; Restore the status of UNDO
+ K  g# F4 C3 c8 S; K) }' p    )
, e0 N  x$ F( {) s; f1 k( b& m3 F  )
$ {5 V. O# s% e1 R  ~# \8 d4 l5 x# b+ w; Z
  (var_restore)                         ; Restore the variables# I1 d7 t1 l# W; f. {
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error, D( Z9 Y$ n- D
  (setq err_alive nil)/ R+ U+ D1 h- d: H9 K( J2 T
  (princ)
: M# B- @3 T( w; q); defun err_main0 S% a1 j3 a$ s; K3 F% g
9 G4 ~' h8 u! Q9 V0 g4 Y
;----------------------------------------------------------------------------4 ]8 U: Q/ k4 n2 A0 q* C0 ?# U
; Restore error status
, p. r, `# F* L- R( k;----------------------------------------------------------------------------
2 \$ ]" u3 [# o+ u8 F5 A(defun err_restore()+ ]2 }; K$ U+ X( N9 B# F
  (undo_restore)                        ; Restore the status of UNDO# S, Z0 g; G, ~# `2 b; z* l
  (var_restore)                         ; Restore the variables* [7 C0 I" R( ^8 T+ C2 L
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error/ I+ p+ ]% |" k4 {
  (setq err_alive nil)3 _4 G' ^# b! a
  (princ)& v: Y. C2 [- T& ^
); 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-10-3 13:23

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

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

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