CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
# X+ J0 d' _: H: U7 B# P2 E2 I9 @ “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”! ~9 j" H& `% e
提示:加载成功
/ ]# `7 o  F( |# Q8 }% R  p然后使用CLOUD命令,
, P, A/ Q# L" j4 R( T2 w提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”( r4 Y6 n& r/ X. K' z! j9 g' J8 w3 U
请高手指点一下,这个是怎么回事?应该怎么改正?
) V' w# j! U+ o- C4 Q6 z0 T. k0 T这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx+ b$ M% I7 h/ t0 G# v
;;;5 Z: j) l& o$ O/ h* W  V
;;;  DESCRIPTION
! }$ [7 j: v7 p; q5 a4 v2 S" ^;;;     Draw cloud and you can specify the globals variables listed below
6 s' ^* C* }$ i1 @8 o( C+ O, h;;;     to decide the characters of cloud* D7 Q% k& i" K; s9 d% m: ~
;;;
+ K+ f0 h& _. L9 P7 Y) b8 P! m;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
% r9 X; G" J( S: d) x* @9 R;;;
; }$ J" T: J5 d, Y5 a9 `5 x;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed: B, [2 g0 r* Z* q: e. |6 y1 m+ E
;;;           Change CLOUD.001 to use CLAYER to perform the same function: y  r3 f. n# r+ g+ H% ^; p$ M
;;;           Use the common error routine UNDO.LSP to optimize this program4 w' S: ]1 b, p5 @6 X6 G8 m2 @3 m/ e
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE, a" C& w# X2 p( S8 O0 X
;----------------------------------------------------------------------------
% D# d( s% i( A. u4 i! ~4 {5 D3 P;  GLOBALS:) |$ C  w* Y9 X
;     cloud_layer -- layer of cloud* N7 q; }9 c3 z  P# S
;     cloud_scale -- scale of cloud. [8 z# z& q8 d) J1 D  V
;     number_rev  -- revision number3 _9 N# y, l- B  V
;----------------------------------------------------------------------------
/ i( v& T# D9 |) c: }(defun cloud (/ locked temp first_point next_point relative_point
; J7 n3 k  H1 M* z5 c: ?$ L! J/ C               last_point point_tri point_ref corner_1st corner_2nd length_tri5 E! u- E/ U. I0 m! Q+ T
               length_cloud angle_l_to_f dir_tri repeat_count
/ d, j, b" h2 l# P2 M# d- q               table_cloud )
5 }0 P7 h5 w3 K* g6 y        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))
% h" ]7 v7 m% z0 w6 F          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))+ Y" X5 |7 e2 Q9 h9 O7 ]
        );if$ V' j" U! D; y$ `
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE") E& f2 g# I2 J( }" h7 q7 l* h
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
. l! A: U$ J$ R+ W  h        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
8 [& E. i9 A  e, i                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))) O' Q- `" ^) {; U0 \6 y& M

" Q1 u: U3 s* r+ L& U+ G        (if (not (numberp cloud_scale))
6 Q! t! j( a3 b            (setq cloud_scale (getvar "LTSCALE"))
. T0 a: j* {( J5 y1 |        ); if9 [( n( e4 C( X
        (if (not cloud_layer)
. ~# p3 M) ?( D" L            (setq cloud_layer (getvar "CLAYER"))$ ^# e  Y, s; h4 V5 n: S' C
        ); if$ ?0 A1 f3 r! C, l) ^
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))! ]5 f& s# U( Y$ v, ?5 ?
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
+ |; q4 P' C8 J6 w) \        (if (= (cdar (laychk cloud_layer)) "No")
& B3 }! A1 @! e& q6 e$ q          (progn7 V; O: b4 w, T# S$ ^
            (laychk (setq cloud_layer (getvar "CLAYER")))
1 t3 t2 A% `& i$ h            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))6 d; _# C" n: X8 Y, i' x3 N/ n7 D( D
          ); progn* Q% j2 k3 {, \1 A. K9 b
        ); if6 `# L1 m' H0 p0 p4 H  `; w
- o7 |5 W- I4 A  h
        (while (/= (type first_point) 'LIST)  {& b/ }# @4 \. [& `* f
          (initget 1 "Layer Scale")# Y2 W' S  l' {/ j# y- \$ i0 H
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)$ ~# a8 _2 X- F0 o: j* \+ o
          (if (= "Scale" first_point)      
- E- f2 e8 K" _+ J( ]9 z( l2 j            (progn
* s# C6 i% D8 H2 u1 m( w              (setq temp cloud_scale)9 E, z! L% W( ?5 w3 Y+ H) V
              (initget 6); u. |  H+ @! b2 q/ u
              (cond9 b+ k  p% k8 _- W
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
; a. C* z* q: P2 Y6 P9 }. R                                                          (rtos cloud_scale 2 2)
/ _1 a, T7 H9 K. A' i                                                          "> "))))
4 q$ E! h4 g7 I* s2 e* C$ ?; x                  (setq cloud_scale temp) )4 q/ A- p* h1 L! b5 Q% G- l
              ); cond
1 O+ ^  ], X$ l+ e2 m; a( Z- J            ); progn. g2 I. |; N$ ^- z
          ); if$ b6 d" b3 x8 j" u
          (if (= "Layer" first_point), k4 N( N% m: Q- Y# r& K" `& Q. \
            (progn
; ^0 }6 S. c; u4 [7 e* q; x* Z8 _              (setq temp cloud_layer)1 Y7 T! I% Z( d6 D' n9 {/ r: P
              (cond6 X. h6 F$ _  O. z! m7 C) Y
                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
/ @4 H; ^) G  \/ x: ]: {                                                          cloud_layer "> ")))
$ D9 q6 P( c& T' Z6 D3 s7 c: C/ ~6 @                     "")
9 V+ r- I5 D" b+ D5 p  v                  (setq cloud_layer temp)9 {# {  ^$ D: l
                )
& a* t, h0 g5 a3 p8 x% i# I9 C              ); cond
4 n, S! g9 G0 t+ ~, [              (if (= (cdar (laychk cloud_layer )) "No")" m/ d, L; }, q$ w7 c5 ^: O
                (progn
' [( q* V$ S  e3 A  q+ t                  (setq cloud_layer temp)* y7 {3 E7 s! o1 y* r  j, A+ ?
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))5 z! ^0 v9 I" C' H
                ); progn
4 x* c0 \. M( d$ a              ); if+ }1 C2 H% E5 z. N' a+ m$ \% b1 i
            ); progn
3 v7 x8 U2 E+ V/ U+ B          ); if
7 p" v/ U4 b1 J8 Q" ^8 r; k        ); while7 G" S- ^5 T2 o: N& c& X3 e! b
        (setvar "CLAYER" cloud_layer)
% c' a& Z5 D+ D0 c; c2 N1 p# O3 ~2 @! o" C
        (if (>= ( getvar "LUNITS") 3)- U; a6 W" A; [" j2 [
          (setq length_cloud (* 0.25 cloud_scale)
# k" p" b6 ^$ A' G* y; S1 n                length_tri (* 0.3125 (getvar "LTSCALE")))
- ]2 C1 H& F7 Z# v/ H0 T          (setq length_cloud (* 0.3406890 cloud_scale)8 J6 P# i' z3 `# p
                length_tri (* 0.438366 (getvar "LTSCALE")))3 e% I/ e4 ?3 r3 D, N/ ]6 r
        )7 k: P: T& d  R' G5 o% C% \  L
        (command "_.PLINE" first_point "A")
0 [- }0 @; Q' _        (while (not (equal next_point first_point 0.000001)), Z% L& X% v' T2 T: n" @( d
          (initget  "Close")
/ R8 h& r5 b- }3 J4 J* v' N          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
3 N/ K- t' l' D        (while (and (not (listp next_point)) (/= next_point "Close")). k6 _2 l4 X0 ^- F. Z) `
          (initget  "Close")/ ]4 E) X; _* F3 \( Q) B
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))7 K/ w- \- E6 x  O  n3 V% k
        )
& z- `+ D4 h9 ~2 Z; ]% Y9 Y  T          (if (= "Close" next_point) (setq next_point first_point))6 P% c; B$ {5 z# t5 n
          (setq angle_l_to_f (angtos (angle last_point next_point))
6 u+ E2 l; N4 u3 T- \0 Y/ J6 F8 p% P                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))4 i) \% t2 v# w& N2 R" a* V
          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)0 u0 c  O. S% u8 c
             (setq repeat_count 0)2 L( b) }7 j9 j2 Z+ Q
             (if (>= (- repeat_count (fix repeat_count)) 0.5)7 k6 W! I% {/ M; s, B
               (setq repeat_count (fix repeat_count))
& C/ j7 r; A! Z: T( |- a+ w; B+ c               (setq repeat_count (1- (fix repeat_count)))5 g  t6 t! B# t+ h4 Z% a1 A
             ); if 0 W; {/ y; E! g, N3 _
          ); if
* b, v( s. q  t9 F: J          (repeat repeat_count (command "A" "-100" relative_point))* ?6 c" X" P3 m% G5 p
          (command "A" "-100" next_point): \6 z; U7 Q2 ]4 U) t
          (setq last_point next_point)# D) n  ^8 \+ B* G2 v& T# q
        ). s5 K- T$ l$ ^& ?) ?5 o
        (command "")9 ?' Q. y5 g+ P
        (if (= (type number_rev) 'INT)
! O, A& v+ T  \+ z1 p           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
% F8 ~# C' W; v- j+ A           (progn4 N4 W" v+ @3 r( \( s
             (initget 5)8 v! L7 L  `- h; `% g
             (setq number_rev (getint "\n请输入版本号:"))
5 c* M5 W4 M( e0 U- h# n& }* D           )4 Z) E2 Y- D" Q3 I& H6 \
        ); if
  N0 t4 q. o4 v2 m        (setvar "OSMODE" 512)+ i# }+ b* }  K7 g$ ?0 _. c% s
        (while (/= (type point_tri) 'LIST)8 Y& d" B5 h5 F6 {2 p9 O7 ]
          (initget "Number")( }& v: @  ?8 D% A* J
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
  r2 [7 a) w9 W          (if (= point_tri "Number")* d$ @% h( X0 Z8 j9 z. \' ~" v; X
              (progn2 W1 ?7 A1 ^9 L- h$ ~
                (initget 4)
5 a, K  W( \/ r( k                (cond/ Z/ M0 q1 ]( p# N" B
                  ( (not (setq temp number_rev
6 s3 B8 ^# B' t0 V                               number_rev
5 a* R7 r( v% i1 X3 D/ I: i. ?                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
6 L& C9 J$ p; r  x                    (setq number_rev temp)7 g0 `, [* T; \9 S% q
                  ). c/ a" ~6 s8 q; U
                ); cond9 e( x" m0 ]3 {
              ); progn
' E- O% z& g. r' y( x6 g+ M          ); if
  \, B' Y0 I& C+ s        ); while0 {" M; P, G# Z& w7 N1 N! x
        (setvar "OSMODE" 0)
" X( @/ p; x9 Q5 `* g% ]        (initget 1)6 E) N2 h) y5 L5 r5 K+ c  t
        (setq point_ref (getpoint point_tri "\n请选择方向:"))
5 n: `9 N+ l, S' E8 Y        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))
0 U7 e, Q3 y6 Y* }7 Q% p: c+ Y. O        (setq corner_1st (polar point_tri( m$ w2 j1 R" J! @! p; B
                                (+ 1.570796327 (* -1.570796327 dir_tri))
! Q; ^4 h' q" q5 Z6 V                                length_tri
* A: O3 Y7 x" q. e% d% S                         )* o! ]0 o+ ]( q
        )# g% V) ]0 A4 F
        (setq corner_2nd (polar point_tri9 l0 i4 ]: i; Q- _9 H* j4 ]& w
                                (+ 1.570796327 (* -0.523598775 dir_tri))
0 _( b) C1 \6 A4 K$ V' `0 `& A                                length_tri( W0 z0 g% d. N' N
                         )( H4 p0 E. A, o$ {9 h  |
        )* K5 w& a' c% f$ v+ E$ F7 Z
        (setvar "CECOLOR" "2")
' r! i" i' k% i: y* ?* G        (command "_.pline" point_tri corner_1st corner_2nd "c" )
0 m" J6 E  u: o+ r( T0 i6 E        (setq textstyle (getvar "TEXTSTYLE"))% u, H1 Y. V- I* x5 o
        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
5 A% ~1 X. ?/ d$ k8 ?; r) w" I        (setvar "CECOLOR" "7")
; O  _, i# o7 p5 R        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))2 ?, G% g3 c2 i- w6 d. Z
                  (* 0.4 length_tri) "0" (itoa number_rev))
6 q: a( H+ C$ `2 p( o        (layres)5 ]% V: ?$ d0 p7 T* w
        (err_restore)
: q4 y  M/ `( l/ k$ t+ F        (princ)/ p( P7 ?8 Y. t$ Q0 L
); defun cloud* L: M+ Q3 f" _8 F& Z

# ?& h; M# R5 i1 h! N; }(defun c:cloud () (cloud))
3 }, r& l7 M) p0 H9 [& Y* ](defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
0 m; u5 z+ A" m" };;;
9 C; n, h' H) j;;;  DESCRIPTION
+ Q9 @$ v8 X) R# K" [;;;     These are general error routines which can be called by
& q0 d  e6 G( z! e' H$ Y/ d( |;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference% x5 G6 u) M8 v( r0 J
;;;
- m, W, }7 S, t;;;  SUBROUTINE INCLUDED IN THIS FILE5 ^2 X' ]  n+ c3 d: P
;;;     UNDO_INIT+ t* u4 c1 J6 G( R8 L4 i7 ?0 R
;;;     UNDO_RESTORE
! R& E: ^# g0 i4 A9 E;;;     VAR_SAVE / g0 o$ J( Z! C( D5 d" I
;;;     VAR_SET  4 k5 B, B6 H; }& B& w
;;;     VAR_RESTORE1 [5 t: Z0 t% @
;;;     ERR_INIT
; X+ ?0 U5 W. x' t$ R/ _;;;     ERR_MAIN
  i& J" c) r' W/ b3 R( q;;;     ERR_RESTORE
. u4 i( V  \( P; v2 u: E- |# {;;;; E* ~% [4 h+ @4 a5 _  @) G
;;;  DATE: 10/17/98; 03/31/99; |8 H; l8 W0 Z+ a
;;;7 Q- u, S# M+ d' d5 k
;;;  HISTORY:
4 l; ^4 n* M  q$ M; V& V9 T;;;    Add routine of mod_att- q5 y$ X- t' y5 E# r
;;;
7 q: a2 z, H/ l6 ]& s;;;  USING METHOD* B- a/ ^$ k. |4 c! a2 Z1 B
;;;    ERR_INIT:. E/ a' H; X1 i
;;;      This routine initialzes the error handler. It should be called as:
/ A  e- T! f: a4 f3 @4 ];;;/ V+ N7 t1 O/ Z' ^: N+ J4 V
;;;      (if (and (not undo_init)
* n- `7 E1 J" L& I' n1 b;;;               (equal -1 (load "undo.lsp"  -1))
( s! L6 Z( U; p;;;          );and: F0 j' W6 S' I5 }
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
  r: h  `6 i1 H4 T;;;      ); if, E/ k/ c7 ^( y# _; O
;;;
2 I! w; V, {- O/ w& ~( z;;;     ARGUMENTS:
: I/ z- A4 d% W. ?9 J- n) S% C;;;       err_init Takes 3 arguments.
. I7 _; G! W+ u1 I, q;;;     1. - The first element of the argument:5 d: H2 p4 B+ c
;;;          This is a list of system variables paired with
9 e9 ?( H) g. _3 ]( S( B% i% H0 v;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
. q2 T3 K; N% O;;;     2. - The second element is a flag
  E! r2 J- s- l7 {) d7 w( c;;;          If it is true, then in the event of an error ; r! w  L0 J3 R- u, Q+ m6 l
;;;          the custom *error* routine will utilize UNDO
+ A$ v8 e3 z1 Z5 I/ n" h;;;          as a cleanup mechanism.- r# l7 @# Y# l- L0 l: r0 P3 E! |
;;;     3. - The third element is a quoted function call.
, u* r. }* j5 s9 b3 \;;;          You pass a quoted call to the function you1 x! S0 t% w/ b4 ^7 ]9 D' T/ k
;;;          wish to execute at the end of nomal routine if an error occurs.
; z+ x4 ], k+ r  q) a+ A2 U;;;          i.e. '(my_special_stuff arg1 arg2...)
/ V  W1 S+ k! |0 U;;;          Use this arg if you want to do some specialized clean up
3 A+ B6 Y9 d, H1 b( v/ p;;;          things that are not already done by the standard bonus_error
. ]0 T# N/ }* p) v; O& A;;;          function.
& u) R0 k7 Z7 e. ?;;;
2 R# u* ]4 D- I; U4 u;;;    ERR_MAIN: Body of error routine
7 R9 v! u  W, ?' L. ~  t;;;2 j5 v! ]! z6 e* Q2 |/ U4 u+ }
;;;    ERR_RESTORE: This routine should be called at the end of command to0 ]8 U7 \  t. p6 |+ E
;;;           restore the VARIABLES, UNDO & *error*." |6 ~" u4 k$ [3 d6 N
;;;8 c2 ?( c  X) `( x4 E) L+ O, g' u8 l
;;;    UNDO_INIT: Initialize the UNDO status, ~) V& X7 @! b1 w0 w; `
;;;0 x) I/ K6 s" _7 i8 c4 i3 s1 U
;;;    UNDO_RESTORE: Restore the UNDO status9 c9 {" C9 G" d% ?" J9 u9 b
;;;4 P, D  D# k0 v
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")% B& D0 |4 _( I# @9 E! t
;;;
( F  g  p+ N; T8 g' F3 k& F& K;;;    UNDO_set: Set the variables. the argument is like2 L. J" ^, [$ h7 a
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
. |8 _" J. G% c;;;
5 O  c$ P0 C) l6 T;;;    UNDO_RESTORE: Restore the variables
/ z2 ~4 ?# N! U;;;
5 A  j3 B8 M: g* b: ~) M4 C;----------------------------------------------------------------------------/ S3 Y3 N6 R0 [" I- C
;  GLOBALS:' z8 g7 g; p9 E" u- A- B0 @$ C
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
' e3 p  D' r* r$ t, A  \& _* `" F' O;     m_lst       -- list of variables (voided by VAR_RESTORE)
2 B4 p$ C+ r- S1 S$ N' z;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or
8 P! C9 h; [. t;                    ERR_OLD)
- [0 N" ]4 b$ r% q/ a;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)3 `5 G% H4 B2 i+ S& v. K+ T
;----------------------------------------------------------------------------' k# O: U, Y$ j8 S2 [9 i3 H" y

% l# p$ A1 A6 I& s" y;----------------------------------------------------------------------------
! Z* r# X4 k* T- |; Modify attributes according to entity name, attribute name, dxf_item
+ ?) O" O4 U, T& q$ F; k6 p;----------------------------------------------------------------------------
: S7 J& `7 `: \  F(defun mod_att(ent id dxf_item)        
: k0 Q; o  t: d8 R! f+ d" e  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))& W& P; `0 x2 N* O5 W( a
    (setq ent (entnext ent))
3 H* R' m7 y# l1 u+ n  ); while  7 M8 T) e; O8 d0 }" N
  ((lambda (x)
. {: ]' ?- y0 w- J4 x1 ?- v        (mapcar '(lambda (y)
" w$ a! P' J% @6 V! T; u                   (setq x (subst y (assoc (car y) x) x))
( E9 ?/ K" x9 I, X/ n8 f                 ); lambda  N/ Q1 A( J, t1 V7 i' p9 `# q% L
                 dxf_item, D: V% h: t0 N# \# D: t
        ); mapcar
4 r7 }& e" @& L0 z     (entmod x)
1 ?& f9 b! ^7 `& P* k5 @4 V     (entupd ent)
7 S( T- K6 F7 u( l% a   ); lambda
, N8 Q& r! }! g3 y" t( w1 d   (entget ent)8 r" q2 x# E' ~
)
6 d# W5 m3 @, m- g. t5 L% @); defun mod_att
" H9 b3 {, l4 R9 V3 R# T8 N6 D! @
;----------------------------------------------------------------------------# [; O1 V; ~5 J# D8 x
; Check layer status, return a association list which contains layer information
7 j  t, `& H3 ~/ \: `: r;----------------------------------------------------------------------------
1 ~. O+ c) U; y* i0 L. t(defun laychk(lay / l_sta)4 Y1 r/ s; W+ Q3 L: m$ i( f4 q
  ( (lambda (x)
# T5 D# {6 K5 [% e+ y' C/ [; m      (if (not l_s)) U8 u8 U. M& z1 Z% m9 l5 w% N9 M
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
" T% K( w1 E0 t. j1 [! g; T3 i      ); if8 b! Q5 W2 ]8 X: h
    ); lambda : t9 j: p+ p! a2 [- _
    (getvar "CLAYER")' t7 A7 b; o2 ]; f7 ?
  )0 u7 A9 K' K/ P& H
  (if (not (tblsearch "LAYER" lay))! G9 b5 O- ~% _$ [5 H; D  K+ `
    (progn  - x& E/ n9 S: H4 D& [
      (initget "Yes No")4 d1 l- S2 H. [( Z! D. O' C
      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")! V! p( Y- g% G( o8 P( i2 E4 T
        (progn
9 G3 n' [, y8 k2 F0 T          (command "_.layer" "n" lay "")7 M1 |1 {9 B$ a5 n" S" n
          (setq l_sta 0)
6 q0 M  {! r1 {9 }5 A        ); progn" v4 G& ]- i' V: S& I6 b
      ); if- n1 U# Y( n, `
    ); progn9 e, P' s" R: C+ u, p
    (progn
7 a7 K" e* @) D4 o; O" P      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay))))), g2 q& a1 y. i2 {; }# A5 L
      (if (= 1 (logand 1 l_sta))
, q) U1 ^, `2 N; b/ I          (progn
+ R7 H7 H3 f% h! ~" l& v4 I            (initget "Yes No")" A, m* d& m% S0 }# t
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes"); O: M  S  t7 B8 N9 {( f+ }4 S
              (command "_.layer" "t" lay "")3 \1 y/ R5 N; Q; s
              (setq l_sta "No")
/ L) G: Q" x6 {3 f1 ?             ); if
" j  \: h. V& @/ V          ); progn# d/ Z! `9 b# E. P  \
      ); if0 |* N; r- G# ~# k! i. M0 P8 I' @
      (if (numberp l_sta)
2 ^5 A. q+ X  N: p+ z0 g8 U, M        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
: t, ^' Q0 ]  e! v! [9 f, o# f      ); if
5 s1 f( [( C4 A1 L. t    ); progn8 |$ J0 a2 y8 Y1 I! z* l* f
  ); if
9 L$ B3 i* |% k' |$ C3 j$ o- I  ( (lambda (x)' {$ T4 W% I/ u" i8 \6 W1 C$ [
      (cond & P( L8 w& B- @- t9 ^& O
        ( (not x)+ ~, b- e  W% }' N# A; r8 ^
          (setq l_s (cons (cons lay l_sta) l_s))) n. `1 Q* Q% ?4 z2 r9 f& N8 w
        )
. N' Z% h& B% \7 r" b        ( (= "No" (cdr x))
4 }# l& v, W- v) H4 [" S          (setq l_s (subst (cons lay l_sta) x l_s))/ g  L6 e4 v% i) `# B& s
        )5 D! z  f4 W0 z/ z
        ( T l_s)" {: i  {0 ^( z2 O* \. u  C
      ); cond7 ^# W0 N3 I1 q  f
     ); lambda0 h2 {( D* S) h& U' E4 j; J3 H
     (assoc lay l_s)
" t+ c: K$ Q7 o! r% M  )
4 Y, U4 c9 b# Z) H# |# m. z: s4 \1 x$ D' N
); defun chklay
8 D9 `1 ^% }3 _. p  }6 P5 w' f- b
;----------------------------------------------------------------------------
. b+ N+ I/ H& |& h5 |; Restore layer status according to association list l_s
( ~! t2 U5 E. X+ f;----------------------------------------------------------------------------4 N  o9 ?% q% U" O' X  [% y
(defun layres()
( b# N9 {7 `- E! i: z0 S  (setvar "CLAYER" (car (last l_s)))5 \' Z7 `: o0 m/ R
  (repeat (length l_s)* o+ C3 L0 i; U! w4 z
    ( (lambda(x)  
1 x& q2 K; l- k- x  U        (if (numberp (cdr x)): o# P9 Q! g7 r- M; O& p- L! _4 L0 N
          (progn
- _2 d# J$ ?& T4 Z4 e  J            (if (= 4 (logand 4 (cdr x)))
8 Y4 a. H- ]+ k6 q  A4 H  P0 h              (command "_.layer" "lo" (car x) "")# o  \* t- D$ j) T
            ); if4 w3 ^3 J4 p& R0 n
            (if (= 1 (logand 1 (cdr x)))
+ @6 k5 R0 e9 a4 d              (command "_.layer" "f" (car x) "")# q0 m3 u; C* |5 S: w1 N' f
            ); if
. @- Y/ a! A6 r& A3 g1 o5 J          ); progn7 i( G/ C: e( `/ S3 ^
       ); if  
, I4 @( t/ P) s5 Q2 [& S+ D      ); lambda1 C& ]# M/ V$ c& ?2 h, \0 V$ y) F
      (car l_s)0 T7 @) ?+ Q$ ^6 y  l. N, M1 x2 Q
    )
- S5 J) V, M( ~, u    (setq l_s (cdr l_s))/ Q+ W8 O4 R" N" L7 o
  ); repeat/ `& B: a) I7 \
); layres. e5 I: k! o, D% k6 _# Z
2 i* F. r+ W  C. S
;----------------------------------------------------------------------------4 {- w4 n8 X0 R' I8 d
; Get DXF codes
9 h5 O8 C+ n" x8 C: w;----------------------------------------------------------------------------
2 H) r1 `! @: k; [(defun entgetf (index ent)
  v2 G* H! m, N+ H+ z# }2 V  |  ((lambda (e)$ c, N5 y2 x/ s+ a& G3 y
      (mapcar '(lambda (x)
; F+ f: z% }+ W% X0 g. v3 k                 (cdr (assoc x e))
9 i9 q; p. ~: [9 C2 F6 Y& S) f' {2 a               ); lambda
! f: H' I7 Z" S/ |# E" I               index) ; internal lambda function
- W' j- q6 I5 e: x    ); lambda" ?9 C( {6 {; G0 N7 |' F8 `
    (entget ent) ( G6 ]2 @$ m% z% v# T
  )+ E/ G8 M3 c& J8 T4 J: l' q
); defun entgetf
3 q- F4 ?- s. V' C$ E7 V9 }, O% n- Q* a( Z/ T$ T( E. X
;----------------------------------------------------------------------------
' c# O# y0 a! K' {1 {; Save UNDO status+ Y# x5 r( [! C5 ]& r9 H
;----------------------------------------------------------------------------9 A  ]  x8 {) {: v; ?$ g$ Z
(defun undo_init (/ cmdecho undo_ctl)   ! F, V3 Q0 C+ x3 O6 s& ^6 S7 |% y
  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value7 X# z7 Y& M( |  Q5 J
  (setvar "CMDECHO" 0)
; k) p1 \5 d# K. ~1 Z. f
- e! u! Y& `* O9 E  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
% R- W5 r% \7 x3 R' a  L3 c    (command "_.undo" "_all")5 G/ A& M5 y( |6 S% c
    (command "_.undo" "_control" "_all")' l  H3 f, ^# o6 c
  )3 R3 B5 E* u% q# p; O2 }

! U8 Z" H/ W( b7 k' |, L  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off
' F3 j/ J' W5 v8 O    (command "_.undo" "_auto" "_off")
' X* A0 I( l% \5 e& H# V; b* i  ). j+ k' `7 T+ @# Z2 o& R1 f, K
: E0 z6 u; {% Z: u
  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here6 H- z* O# ^( l: h6 m
    (command "_.undo" "_end")
$ P+ G4 K, c+ X  )
, J7 c( ^5 D  L! E0 S( l8 n/ D# D# t( x. D. \# ~
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
- y1 Y: o; w7 c" z; j* m9 _% H. l    (command "_.undo" "_group")
: d7 L) [. }$ Y9 r  )
* q9 a7 s6 C$ W& ~# o" k
6 f4 a" `7 q. `4 R' Q! ~  (setvar "CMDECHO" cmdecho)
% w" \/ {. Z8 B/ C& _  undo_ctl/ j% ^0 N% X7 F# ^; }
); defun undo_init
2 Y  v2 n  b- @" f2 v4 I( s5 o& k0 c* O5 n0 c$ p. [
;----------------------------------------------------------------------------$ i+ H3 q: Q; u% E
; Restore UNDO status- u* ?* ]  c; g- \2 n$ O- M1 t
;----------------------------------------------------------------------------* `4 |4 B$ Q3 o* Z' ?
(defun undo_restore (/ cmdecho)
8 v; P$ ?2 O% |& V2 y( E  (if old_undoctl# U6 G: x& M1 v! \  q
    (progn# w5 z: D9 `8 Z) i
      (setq cmdecho (getvar "CMDECHO"))
7 H" F) B' Y4 I( s% p      (setvar "CMDECHO" 0)
" Z+ q% z( u4 n* Z
2 M1 Q- u; u& H" m" {      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) 3 H5 d) n( W/ H& D& D8 g/ J
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))% |7 j& j+ C( S
        (command "_.undo" "_end"): z& s. ~$ @5 `
      ); while
3 x4 ?$ R1 T' q2 Y  K
2 M$ N- s. m: x6 v/ d$ q3 y& U, y; Q5 {5 l
      (if (not (equal old_undoctl (getvar "UNDOCTL")))' l2 E. c3 u, P7 d" ~% o
        (progn1 f- d4 Z' p! H
          (cond
7 N/ V# t8 S5 M8 r  `" G( O# o$ |1 S- l            ((equal 0 old_undoctl)% A  J/ V. f1 ~8 L
              (command "_.undo" "_control" "_none"). i  }+ j$ B8 p2 N( U. u
            )
# z) Z0 x( n  h9 D( q            ((equal 2 (logand 2 old_undoctl))) q- z' f7 W& X# W5 i8 j% C
              (command "_.undo" "_control" "_one"); }# Z& t# `7 e, x( \% R6 Q
            )
5 ?* ?2 s. @: k* L          )2 m0 m1 }) b$ ~/ R
          (if (equal 4 (logand 4 old_undoctl))/ l4 R* s' |$ K. d
              (command "_.undo" "_auto" "_on")2 d! N4 ~3 a, S) k; K# Q
              (command "_.undo" "_auto" "_off")2 h! _6 [$ Y# ]. Q  V
          )0 N1 V& I- B" u9 L
        )
1 w8 j: h# @- p! F* m& c7 H& X+ }      )) g" X% {2 d8 R: e5 w- u5 e$ _
      (setq old_undoctl nil)# P" o5 w0 z5 w! W, |) s' t' R
      (setvar "CMDECHO" cmdecho)7 g- W" h3 K. x( P& _" _
    )
& ^2 |& y* m2 R  F  )
2 |% D9 t  ]8 Z9 L- `8 C: ^); defun undo_restore
, H7 @- I6 T. D! B, u
6 x# _8 Z( J( w;----------------------------------------------------------------------------( }% B3 N# C6 S. r
; Save variables
$ r1 d5 {6 u( R9 F& k;----------------------------------------------------------------------------
8 ]8 Z. ?7 |& s- P$ g( K, B(defun var_save (a)8 r+ c4 R" H( t) m# @
  (setq m_lst '())
& O! I3 F. X$ C) ?  }( s  (repeat (length a)
4 @$ b/ y3 L) g5 y, v) e    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
4 x$ ]5 \0 n8 G6 u, }% M* B) {    (setq a (cdr a))) h8 j. b) d! A8 Z; b/ \. j
  )( Q$ t5 y4 D7 b7 J7 H: g
); defun var_save
0 g( V4 S: W: p- e4 I2 Z2 V# ?, ?5 N5 N: ~
;----------------------------------------------------------------------------
8 ]5 Y& E# ]% z# X* f# }; Set variables# I# `" k- l; n' I' R- W
;----------------------------------------------------------------------------
6 I. y5 F# m3 x$ B" `: q% O(defun var_set (m_lst)/ z$ T, H* i4 O+ p( u& t: T! \
  (repeat (length m_lst)- n/ M% ^2 f! Z7 w
    (setvar (caar m_lst) (cadar m_lst))& Y" s3 E! P0 J- D6 J9 G$ M& I
    (setq m_lst (cdr m_lst))
; F: r( e  M6 y+ f1 X( I1 y1 ]  ); @* p* w9 |5 _, }0 a5 {0 ?
); defun var_set/ p1 s; U5 R  i" l6 |
$ x8 [/ B: u+ s: J' z0 b
;----------------------------------------------------------------------------* ?# v% l: ]# v( F2 b
; Restore variables
! D3 h' ~' t5 D5 M5 ?4 |9 C;----------------------------------------------------------------------------! m8 Y9 }0 o5 z
(defun var_restore ()/ p' D3 G. N; L' c8 w
  (repeat (length m_lst)
" L5 l) l; G4 _' d% @    (setvar (caar m_lst) (cadar m_lst))/ c0 K4 O' d+ \9 E2 J6 Q& c+ n' U- t+ P5 h
    (setq m_lst (cdr m_lst))
# L& M% k0 T/ J) k' o! _  )7 ]5 X" F5 u* V4 s
); defun var_restore
/ F) R, C. f1 E$ M. Z0 V
; e$ a+ w+ y4 t4 p+ H;----------------------------------------------------------------------------0 O) b1 a$ g0 W9 N
; Initialize routine
, f' k: ~9 M: i" D) F5 E4 x8 t, T;----------------------------------------------------------------------------8 Q7 x8 P" H3 |3 Q( C) {& y  Y( w$ L
(defun err_init(e_lst u_enable add_fun)
$ x: y" z! }0 V  (if err_alive (err_restore))          ; To avoid nested call
/ g8 a1 t) y' X6 \5 j! ^' b. ^- Q  (setq err_alive T)% m% p2 F4 \/ v& T
  (var_save e_lst)                      ; Save the modes) J; w: a/ D9 k+ M, X
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status
/ N. k  _7 H4 V: A' k8 z* T  (setq err_old *error* *error* err_main) ; Save the handle of *error*
! W3 ~$ n: \0 x: k0 ^- O  (if add_fun                           ; Add the user cleaner
0 Y" v4 b9 `5 R  ~9 N$ i    (setq *error* (append (reverse (cdr (reverse *error*)))
+ y5 l9 N* ?$ Q( [& O- Z                          (list add_fun (last *error*))+ B# h# Y" H+ t  I) U+ X
                  ); append2 e  Z! d9 \1 O1 d/ L* I! f
    )% R, E) U2 Q4 ~$ Q6 @1 W
  )
; Y6 ]/ _9 R. q- X" J); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
  `2 R" q9 r6 x, i. X' h5 X; Error routine body" K. J; M6 ?' |! U: n) c  c
;----------------------------------------------------------------------------
- f. ~+ v' i3 h(defun err_main( msg / )                ; Body of error routine4 P# u+ a, W% S
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs* ?$ E) @0 T( ]7 [' Y$ T
    (princ (strcat "\nError: " s))      ;while this command is active...% q, [) g1 S+ {! M
  )6 |" i- M5 ?8 r+ Z
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
: O6 C) s$ ^0 ~  L0 U# o
4 Z& _( n+ m. Q& ?9 |- e' p  (if old_undoctl
% l! E7 r" O5 E/ [* j% Z  [" Q    (progn+ x. P0 h0 v9 Y. S$ o
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See# o  I/ Q5 Q- E4 d$ ^* t  O
        (command "_.undo")              ; if it's in UNOD command
' K3 y% F6 a; F0 A% P, G( T+ r& _9 f      )" ^- c9 t0 o  s+ H, k' ~7 \
      (command "_end")
7 }  [$ c& T7 W$ {( N; M      (command "_.undo" "1")2 f: d+ @# h1 y3 i
      (while (not (equal (getvar "CMDNAMES") "")) (command nil)). A  [5 _# p" V- X" c& H
      (undo_restore)                    ; Restore the status of UNDO
$ p: l3 z7 m8 ?( I6 \$ C    )6 l: C9 V- W: x& D2 \# f
  ), w  B$ x! `4 m& `+ P) p1 G
. W& }: Q% [  C% M% w$ j) B- h
  (var_restore)                         ; Restore the variables3 G3 j4 O' T- b  s& Y# c3 f
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
# D# ]9 R/ k6 f  (setq err_alive nil)
$ }5 z( a/ H7 O2 K6 z' a/ K1 p+ R% M  (princ)1 e, z2 j) q* \- F1 f/ j- o9 ^
); defun err_main
% s4 b6 L9 X7 E7 r% a* K. u( i5 e* w6 u; w. C8 @) x
;----------------------------------------------------------------------------- t, v: f) J2 P9 I" A
; Restore error status
0 }! |, r3 ]- ]0 f8 Y" w1 M/ X- m;----------------------------------------------------------------------------0 J- Z; y' d' [3 p
(defun err_restore()
7 P$ d  F8 O6 A2 X$ ^  b7 z. n  J  (undo_restore)                        ; Restore the status of UNDO( u/ C( V8 s* F* e$ x8 O/ I- s
  (var_restore)                         ; Restore the variables
8 Z8 A0 H! x7 z  `5 l5 B% e% S+ z  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
4 s$ p) }$ r* d7 d  (setq err_alive nil)
$ F; k3 F& ]$ ?% h6 e  (princ)
; q) T/ J& Q0 e- b" L); 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:50

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

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

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