CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:+ L: ?, B4 A; k) [/ f
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
! M7 T6 S. S/ ^6 B提示:加载成功
* A0 F; d' W7 }- u2 G" _然后使用CLOUD命令,
" _/ U! j/ i3 O  X6 M* m! `提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
* D; b) ?3 P$ o8 ]- _1 u2 x请高手指点一下,这个是怎么回事?应该怎么改正?
, {7 p& c5 w' J$ _# O0 ~这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx4 J  [/ I3 m% H
;;;6 M$ A" t: Q, T
;;;  DESCRIPTION3 H: v8 ]9 ]& C$ T" s& i
;;;     Draw cloud and you can specify the globals variables listed below" T+ H; s7 c: W/ B
;;;     to decide the characters of cloud
: q6 q8 o7 k2 z  g( [3 _) C6 k. P. k4 S;;;
. D4 v: P! L3 s, A3 R# `6 w;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
% V5 g6 J% U0 g& t' {1 g4 X# p;;;
  ~3 k- Q5 q: K. r5 D;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
  k$ A( @& ?( b;;;           Change CLOUD.001 to use CLAYER to perform the same function( Y4 g8 f/ v0 x# j  z/ w) D
;;;           Use the common error routine UNDO.LSP to optimize this program
8 f: B0 x! s0 n$ @; s* ?;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE" ^' i( h( s) n8 ?! p
;----------------------------------------------------------------------------
3 L; H" X1 C3 S2 A;  GLOBALS:$ l( _! L; R+ Z" F* D- a
;     cloud_layer -- layer of cloud! J- `! j5 U1 j- E
;     cloud_scale -- scale of cloud% c' ]) X! Z: ~1 N
;     number_rev  -- revision number- g# S5 F7 O" r
;----------------------------------------------------------------------------
( I0 R9 h  ]. j8 \3 O(defun cloud (/ locked temp first_point next_point relative_point
4 ^/ ]) E' E" [' d% J3 C# O  v4 k5 U               last_point point_tri point_ref corner_1st corner_2nd length_tri5 w! r+ P. v8 Y8 v
               length_cloud angle_l_to_f dir_tri repeat_count 3 |$ J: @* m' J$ d$ w% E& H. y
               table_cloud )
; M  W6 t- N0 g/ S        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))! G, _! [  q( w( p
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))8 x$ d# `2 Y: Z& p1 p0 b
        );if$ L, z: o2 u- q: H  v. _6 Q
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"! i% r- s3 c( V, F2 \- q6 v$ _
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
# b6 i: i6 p4 W* [- Z3 _5 A        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
% L) d5 R( S/ D$ [, e( h                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
3 w2 B; J* p/ }* Q8 I5 ~
6 j; `6 a, g# a, o        (if (not (numberp cloud_scale))% }$ m" d  C9 Y+ Z
            (setq cloud_scale (getvar "LTSCALE"))  _% K; v1 c" s% U. O: D
        ); if7 F; s3 A, A% G( w
        (if (not cloud_layer)
7 V8 Q2 g( o8 K            (setq cloud_layer (getvar "CLAYER"))
+ D; ], o7 J! d" G: K$ i6 D9 ?" X2 Y        ); if
+ r) C7 v  _( u2 a        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" )): R7 U- n, t' s8 n9 j
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
/ c4 z% c! H, t% u! r        (if (= (cdar (laychk cloud_layer)) "No")2 e7 ?& H/ x1 z3 L+ w1 g2 I
          (progn
$ Q& M% X! r; U: Z9 o            (laychk (setq cloud_layer (getvar "CLAYER")))
! J+ E! j8 r; ^8 v            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
+ Z2 C3 X, W: g9 o6 ^% Z          ); progn
' b; p% O$ p* T' l" l+ s% S        ); if
' y6 L& G) s5 i& n. a/ e- `( s3 }  |0 Y$ F) V
        (while (/= (type first_point) 'LIST)
8 p9 o& b: ]& g' q          (initget 1 "Layer Scale")$ l8 D. s- ]3 W* n7 ^+ W
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
7 {+ }- t. y: z5 b  o3 f          (if (= "Scale" first_point)      # b+ {4 Z( H9 j
            (progn
7 G6 }& b0 c( r" s3 G+ J( [              (setq temp cloud_scale), ?. M" A: w; z" J  a
              (initget 6)! t" {1 w* o1 M1 ~3 V( u0 _- [& f
              (cond4 P* ~5 q( S' [
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"7 R0 N# c" x$ o. g: c
                                                          (rtos cloud_scale 2 2)7 k3 x% P# y  q5 }
                                                          "> "))))% _6 P) F' R8 [8 X1 y
                  (setq cloud_scale temp) )
. k6 q3 s! ]6 j              ); cond
7 z# C% P9 f9 ^8 M1 C" E) V            ); progn; b% ^( z! i! A! Z
          ); if2 z5 h5 N- H6 X6 Z5 F) V
          (if (= "Layer" first_point)
$ |% n% ^5 s2 P- `) }8 v  j: I6 d, Q            (progn8 v6 w8 k$ |% y, o" f
              (setq temp cloud_layer)- R" ]! A  A0 D+ _
              (cond
& q& V& `( z/ O2 X, H! g                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"* [* s8 J" A9 E" U5 [0 V' P
                                                          cloud_layer "> ")))
: Z3 j- H( C" Y3 D+ }                     "")
1 ~+ s. t9 E3 a. A% S- p. @                  (setq cloud_layer temp)$ s- B/ o5 V( F* e/ ~
                )
, b$ W$ {( y+ j0 i$ u              ); cond& M9 T: A6 u0 \5 C: o
              (if (= (cdar (laychk cloud_layer )) "No")
* N  l- L1 B  u& u- S                (progn- P. P5 h1 |$ [! K5 ~" I' _; P
                  (setq cloud_layer temp)- V  q+ w! p; I
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
9 C" D2 L. @7 K5 S                ); progn1 K3 X, [6 s( _3 J4 Q/ D, E
              ); if. P! i2 D; f7 C+ `
            ); progn
! |5 D& j9 k. [" ?          ); if% C% F# O; j6 G- O7 d# m4 y4 n$ z
        ); while
5 k5 }4 U8 s6 V3 U0 I3 j9 R        (setvar "CLAYER" cloud_layer)
8 B4 C7 [" F6 ?, B+ K* f. b
" K! k0 _+ O; q! T1 z* \; Z; E        (if (>= ( getvar "LUNITS") 3)
, T7 M$ v# I  p0 h0 V          (setq length_cloud (* 0.25 cloud_scale)  V+ B. A+ U: M  m2 y
                length_tri (* 0.3125 (getvar "LTSCALE"))); C! f' m2 j( P9 P) k+ v
          (setq length_cloud (* 0.3406890 cloud_scale)& \: i) s8 D0 P8 r, w
                length_tri (* 0.438366 (getvar "LTSCALE")))7 q: _* {2 ~! s; j1 Q
        )
* I( X9 L* ~& Z( s5 {. t3 H        (command "_.PLINE" first_point "A")
( L" @$ _2 H1 g, w( s$ i        (while (not (equal next_point first_point 0.000001))
3 y4 Y4 I+ {3 C1 A# D( U          (initget  "Close")! p7 d; @8 o$ X% q8 Q# U
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
& Z8 v2 Z# z5 \        (while (and (not (listp next_point)) (/= next_point "Close"))
6 m, n. M  D6 q" @; t) y0 |          (initget  "Close")) V8 }  q! F, p0 }! n
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))$ J4 a8 }4 J, m+ d
        )
' r: d% [. E! @6 e8 i; c          (if (= "Close" next_point) (setq next_point first_point))
& U" N9 |! H  F/ v0 @5 A          (setq angle_l_to_f (angtos (angle last_point next_point))* G  }- J( f$ b0 t: o
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))9 t- S- b0 u* N: i, g4 u# }
          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
( n) B, J0 ^. r             (setq repeat_count 0)" C% _' V+ L  O" {9 S
             (if (>= (- repeat_count (fix repeat_count)) 0.5)' G7 ^; |0 A) d' I1 W: {2 c' h' j
               (setq repeat_count (fix repeat_count))
* T) g/ z' }% v/ ]4 A+ O               (setq repeat_count (1- (fix repeat_count)))( p' B+ X6 k" [
             ); if
# F5 V5 X) \7 B9 D  c7 z4 d          ); if
) w# `2 F) u- d. a% p1 D% [: ?          (repeat repeat_count (command "A" "-100" relative_point))
8 B4 X/ b' U( K. P" D          (command "A" "-100" next_point)+ y% Y- q6 t6 G( n9 Q
          (setq last_point next_point)# @) C: T2 j* }# w/ l4 H
        )$ t5 r9 ~1 T% K
        (command "")) m! J. U: k. R5 s; y* c% w
        (if (= (type number_rev) 'INT)- g( u1 S  D' o& x$ N4 V1 {
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))% ?4 J" d* C/ x  J# i
           (progn' R. Y) g: e* K6 t. X$ \
             (initget 5)+ y8 \) j6 g6 y6 a
             (setq number_rev (getint "\n请输入版本号:"))
6 F! A8 U4 Z! y           )
: G3 Y6 J1 _2 \        ); if9 T) ~, L( J1 D) S" d; ?! s) c
        (setvar "OSMODE" 512)
! t% t1 p" A) R/ ?* I' N4 t  o        (while (/= (type point_tri) 'LIST), o& I9 X/ B* A( u  o- ]
          (initget "Number")# S4 Y7 j) Y( [+ u
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
/ x: N9 [, f9 n          (if (= point_tri "Number")! x9 z! }/ e4 F& H& i3 a9 A
              (progn
9 }' I4 f" ]' g$ W0 k- A                (initget 4)$ G7 {8 {( y' [+ B$ a0 o
                (cond. K: W1 z4 a3 A! L, O% K; Z0 c
                  ( (not (setq temp number_rev $ H! C& r9 @9 E" a$ I9 E, }. V
                               number_rev# ?0 @! R+ s4 t- r8 o6 B. D& ]3 b
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
3 k8 ~% A6 G" ^/ d2 N/ E  r( ?                    (setq number_rev temp)
& ^3 S; E, s) h" X9 k- Q- D' G) o/ X                  )& A: ^) c, }6 }4 ]
                ); cond, u. F  s& ]3 y, K
              ); progn+ [) w' A- l$ ^- G! E  F  j, i
          ); if( f4 ?* V9 h; }3 {5 q* b
        ); while% d& X! f5 @! C0 a5 J
        (setvar "OSMODE" 0)  f# O2 s/ t+ M4 j8 d
        (initget 1)
0 ?" W4 @% K( t1 H' x; c( e# ~        (setq point_ref (getpoint point_tri "\n请选择方向:"))8 a; I; V: }" V
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))3 S1 ]+ }/ W* e1 f6 N
        (setq corner_1st (polar point_tri
4 ]. E, e% X2 q1 f+ T- n                                (+ 1.570796327 (* -1.570796327 dir_tri))8 G3 Z6 h) ~2 _0 m. @0 H4 Y
                                length_tri
; F3 S- Z" g/ i                         )$ `' L& J! S! }
        )
' E7 z( p' i4 n' B: t( @) j        (setq corner_2nd (polar point_tri
3 `! ^# @+ v$ t- f4 d) x                                (+ 1.570796327 (* -0.523598775 dir_tri))4 U1 }* M  }8 ~
                                length_tri. c6 i% W+ k& `+ e
                         ), {( V, r/ ^- ^4 _1 c
        )$ k$ U. q. V6 d2 i
        (setvar "CECOLOR" "2")0 m7 u2 u# M# H: |# Q( f
        (command "_.pline" point_tri corner_1st corner_2nd "c" )
- u2 s# q  o/ Z' f$ L) {" C- L" `        (setq textstyle (getvar "TEXTSTYLE"))
+ {+ ~  T7 }+ s# ~# O4 Q        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")& u% G7 W, D. J( P, X$ [, \2 \
        (setvar "CECOLOR" "7")
5 R, v' a, e/ M/ D; E6 a        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri)). B1 b) m/ a1 f
                  (* 0.4 length_tri) "0" (itoa number_rev))
; n' M0 s/ \; }3 H! r% D, g* S1 z        (layres)- x. c3 Z& `9 \) I
        (err_restore)$ `. k/ D3 k+ [* G! K/ E+ O
        (princ)( y! a8 @/ \" d! D. _' x% J/ b
); defun cloud
! a: @7 u, p" E5 S, N9 g
  i- Q8 C' B1 b- G8 U(defun c:cloud () (cloud))# ^4 U; P9 B9 d& `
(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
5 h- \4 c, T5 I  I) ?" b( \* H/ M;;;
- R' [. f. i  t;;;  DESCRIPTION
; B; G: ?9 D8 z" [- S7 H$ i) j;;;     These are general error routines which can be called by
' k8 u& e' x5 x' \  C6 b4 {;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference
5 D/ Q$ d: K  X1 d! t* u;;;
" w( d0 W8 [' p  f( c;;;  SUBROUTINE INCLUDED IN THIS FILE8 i0 p8 |* v* C9 J+ P
;;;     UNDO_INIT7 I4 }9 R/ w- o$ }, Q
;;;     UNDO_RESTORE
) Y  z" i, ~1 ~0 A2 |;;;     VAR_SAVE . N- D$ H9 o$ H% J. i9 s5 \
;;;     VAR_SET  7 P! H3 ^& [9 S4 {9 m, P
;;;     VAR_RESTORE
! r6 c+ E- R/ \( H3 [) U;;;     ERR_INIT 9 ~" ~* z) p3 c4 C9 b& V
;;;     ERR_MAIN 1 D9 U3 o& o' d
;;;     ERR_RESTORE/ ~+ \  h6 {6 X; i
;;;5 r- d! t$ C8 j0 E* K" w* F/ g+ |
;;;  DATE: 10/17/98; 03/31/99
4 B! \3 ~7 S5 H3 p. J+ C;;;
8 t' ?- C0 d/ O;;;  HISTORY:
5 g- C0 e; X& e3 `;;;    Add routine of mod_att6 t  J, @  a( r( h
;;;
4 q6 u2 L+ o& s4 F' };;;  USING METHOD# y1 X( f5 j5 P
;;;    ERR_INIT:
2 q3 B. p4 W; v7 k3 \;;;      This routine initialzes the error handler. It should be called as:
$ ]9 O+ J# t; @( S9 Z2 J, d9 V# B6 D: I;;;$ a6 V9 R1 c3 g8 E. a! h) |0 X! o- O
;;;      (if (and (not undo_init)
, Q  u$ Y; X3 r2 ?* N;;;               (equal -1 (load "undo.lsp"  -1)) 5 k7 y! o+ Y7 ]2 V. U! Z
;;;          );and8 A! f$ h4 k( W& y! W3 X
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))' w0 B# ]2 F' s3 {
;;;      ); if
/ Q' [! Z# A& f: O" V  [$ d7 A;;;
2 {+ j$ S: g' k7 N2 Z2 b6 Z4 m;;;     ARGUMENTS:3 F8 u5 ~5 _' v3 S
;;;       err_init Takes 3 arguments.
! V. J5 W9 A0 J& l+ c1 r0 o;;;     1. - The first element of the argument:
4 K0 F  m, z& l! w' l;;;          This is a list of system variables paired with
- U0 J) N* g& y' T, ^;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
5 F3 C0 a# a) T( p! C/ i5 B. M: d;;;     2. - The second element is a flag' ^: ^& f2 B' G
;;;          If it is true, then in the event of an error 5 M! m' W- X+ D' L: m! p4 T
;;;          the custom *error* routine will utilize UNDO
4 T0 L% q8 Y0 v* d( E' v;;;          as a cleanup mechanism.
/ q5 ~  U( B" i# Z( T8 a;;;     3. - The third element is a quoted function call.
( r) z9 o5 v; m% O: \/ U;;;          You pass a quoted call to the function you
3 U) X2 d4 R$ Y) M;;;          wish to execute at the end of nomal routine if an error occurs. 9 q) q! c3 x4 B  S- y9 a
;;;          i.e. '(my_special_stuff arg1 arg2...)
: h/ z9 `+ [" u- G1 M  b- o, ^;;;          Use this arg if you want to do some specialized clean up
1 R2 G0 V3 P) y4 n;;;          things that are not already done by the standard bonus_error
& P  U& M8 [0 v# C9 };;;          function.
/ }# B- g& v- h;;;& ?5 P, s" C6 Y3 H1 e
;;;    ERR_MAIN: Body of error routine
) y" p( T& z6 A' p+ ~6 g; ?4 i;;;
: ?; R2 M0 C0 p;;;    ERR_RESTORE: This routine should be called at the end of command to
7 L/ r5 x- Q% a4 y3 e;;;           restore the VARIABLES, UNDO & *error*.
3 ~- h) Z# a) v;;;
0 y2 S" }- w" _" X( y' S( _;;;    UNDO_INIT: Initialize the UNDO status8 V5 {" P, ^. r; e  \4 U& P
;;;
, K; {; X0 j0 d7 U;;;    UNDO_RESTORE: Restore the UNDO status
' u7 I% |2 o2 _9 E" ~;;;5 G, A+ L0 p# e- W  v; d
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
; ~/ Q+ j9 j7 F1 t' B;;;1 [8 ]& m: H. s
;;;    UNDO_set: Set the variables. the argument is like" |3 X9 U' K  v* Q8 Y6 [
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))6 Z5 }) H5 [( w' O2 M- {
;;;
+ J" B4 W1 Q6 k! ]+ ];;;    UNDO_RESTORE: Restore the variables6 d3 p2 r: W& V# T
;;;0 R( s5 {6 t) F. g6 u: J( {- u. \
;----------------------------------------------------------------------------
! E2 T" q  g0 I; U9 y1 z1 i  e; @;  GLOBALS:
, B2 u  X2 L' i: F: w;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
- Q( Q6 v5 [4 b( m* I7 Z- q;     m_lst       -- list of variables (voided by VAR_RESTORE)) M6 _% n4 {5 p  V4 e$ b( S: z
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or
  |7 q3 `* Q6 I6 _; w7 q;                    ERR_OLD)8 w4 w. T6 _: h4 ~2 K$ j( w
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
. I  O; h- }4 z0 y;----------------------------------------------------------------------------
% @. M- |2 `! S9 t4 b  Y& t3 ^
;----------------------------------------------------------------------------9 C% l$ |: J# p8 F6 {" Q# k
; Modify attributes according to entity name, attribute name, dxf_item: d2 d6 }; s& @# B- ]+ Z: r2 C
;----------------------------------------------------------------------------
- K! l: W+ N" j7 |(defun mod_att(ent id dxf_item)        * I& c2 T1 n9 X( G% N
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))- D' c+ I  n7 m9 J
    (setq ent (entnext ent))
! k' K( ^5 @1 z  ); while  2 @. v. N  ~1 @2 s5 f) Z. G3 A$ _
  ((lambda (x)# ]* D+ v- [1 j$ U* E& T
        (mapcar '(lambda (y)
3 |) n8 N- b# S# C                   (setq x (subst y (assoc (car y) x) x))5 e7 o0 f! ]5 U( G0 J  C
                 ); lambda2 o3 V- Y1 n" m) c* w5 {+ u
                 dxf_item2 n: Q3 A# {$ j: `
        ); mapcar: J/ Z; @0 i# R5 H% ?: e
     (entmod x)
) [. @9 V. B0 b     (entupd ent)
* X3 |! Z& w& g* d# j* X6 L! A. B   ); lambda+ l1 M* x. J' F, H( \2 @
   (entget ent)! R( u" o$ S3 m  {7 ?
)7 N# \+ U. C0 B( Q/ `# P5 k6 w
); defun mod_att
% q5 v  }4 V  k1 A! T8 t" U: @6 ]6 s& g/ K5 D- R
;----------------------------------------------------------------------------# Y  {  B# K" f9 N% J) O+ A& w
; Check layer status, return a association list which contains layer information6 m7 p! f' X- M# z- L# ^, U* B
;----------------------------------------------------------------------------
: h7 g4 ?: h: r(defun laychk(lay / l_sta)
+ l6 N: j, F, L5 K  ( (lambda (x)4 I- u. x! L$ v4 S6 c: T1 U" p& e0 }
      (if (not l_s)+ {' S% G# M8 X, E) `2 k
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x))))))), K! p; _( {" ]5 o. ?
      ); if
' O$ P/ {2 `! X0 c3 @+ L* D* ?    ); lambda
1 ^6 R' `; R$ c2 ~4 F* Q. Y. ]    (getvar "CLAYER")
; A3 o/ w6 p$ V& [( M  )
, {9 F0 W+ A1 H- \+ `  (if (not (tblsearch "LAYER" lay))9 m  M6 o. P5 `8 k
    (progn  
/ @8 A6 r6 W5 e( f" Y" [9 Y      (initget "Yes No")! g- q! c. M8 ^/ L$ ]1 v8 L
      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")( o& l9 i3 B% U- K2 X8 Z
        (progn9 C% ?% K* \  p7 F! F1 e; v
          (command "_.layer" "n" lay ""), o/ S9 J9 b0 B! R8 S/ Y9 S8 m
          (setq l_sta 0)
) [# C/ F+ b7 G0 ?% ?        ); progn8 g5 c. E( x  `6 G/ s2 G  J$ E+ P# X
      ); if
& `  Y; J: Z: \9 g; s! N    ); progn5 M6 N7 U# r: q9 c: c8 q4 W+ P. ^
    (progn
7 f/ }7 y& E! j/ x      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))1 }, L3 `, v, \/ m
      (if (= 1 (logand 1 l_sta))" O2 u2 V$ e, t1 P+ {6 R
          (progn
- H1 [- ^+ p- m  y5 \            (initget "Yes No")! w) p8 B; f( Z; h7 a6 G& y
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")& M6 h# v1 R; }( y- i
              (command "_.layer" "t" lay "")5 ?( z% s: [+ b! R
              (setq l_sta "No")
$ d# e: {  V4 q: W, }             ); if  k5 z: `7 y- v, S- f* E) ?5 _8 e
          ); progn
: M7 D" B9 y5 a* W! e. M- h      ); if/ @! L; ~/ M$ \4 g) P6 N# I$ C9 W
      (if (numberp l_sta)
- l' H) n8 U, C        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if6 \, k. I/ Z/ h/ n: U
      ); if
4 w7 s5 L0 {4 U3 j- A5 M) x    ); progn! E3 u) g( v% j, z. S* d
  ); if# h% N8 ~# o# t4 j2 L; N% K' H' @
  ( (lambda (x)
: C' ^7 w7 \, ^! H7 f      (cond $ G+ c/ O4 @/ i" D& ]: Q
        ( (not x)* l" Q8 P! k9 R5 E7 P+ C$ }( U
          (setq l_s (cons (cons lay l_sta) l_s))
: _7 p+ e3 c! _. C4 C% v. v        )
4 s1 R3 g1 n) p( A) A9 e        ( (= "No" (cdr x)), ]4 M) M1 ^1 C+ W  r. H+ D0 K3 X
          (setq l_s (subst (cons lay l_sta) x l_s))% w9 R9 m7 y- k+ u# k; t
        )7 X3 S/ C/ u( r. o7 n: B
        ( T l_s)) j( C* f) S  \' U4 g, d
      ); cond
) r3 I" x0 B+ Q$ h     ); lambda" g9 ]5 X7 g! v3 f4 D7 z: E4 Z% y& c
     (assoc lay l_s)$ |; ^& r3 f# a5 A* h
  )
9 @  ?+ N$ g0 I: l9 `; f2 L* u1 t  q  ~5 X6 Z0 r8 R
); defun chklay
1 l- `5 A1 O; j, j! o- k3 A
- f# c5 T7 k3 _, J7 R/ Y- C( k3 L1 h;----------------------------------------------------------------------------' N8 ]0 `2 Z6 M; F
; Restore layer status according to association list l_s: k1 X3 }* D$ }3 \; e3 s" }
;----------------------------------------------------------------------------
+ Q3 v% a& x  u) n(defun layres()2 h7 S* f7 b# r; w
  (setvar "CLAYER" (car (last l_s)))
+ R  H8 O5 W6 ?: N. p; S  (repeat (length l_s)) t6 @( v. |. {, h- L. w
    ( (lambda(x)  
" O/ K5 ?# w$ Q% \+ E( R        (if (numberp (cdr x))- ^- ~5 H% x% n* A& d6 n: ]
          (progn
3 }6 E; ]( i- X            (if (= 4 (logand 4 (cdr x))). N: L5 j2 R3 ^6 L+ F) }; m
              (command "_.layer" "lo" (car x) "")) k& a$ p8 v1 {& T, K2 t2 x$ N
            ); if
. z- F1 e1 {2 r/ \% L- b+ R            (if (= 1 (logand 1 (cdr x)))6 o( j6 t2 a) V1 R, P/ p" D1 j
              (command "_.layer" "f" (car x) "")
, E9 g& c" ~7 {: P& }            ); if
5 N5 t! o$ y0 x5 S; X/ Q          ); progn
4 m' v7 r, W8 A( c* m       ); if  ' {  G0 f4 s2 S1 L
      ); lambda
& u  e1 F1 d6 m5 m! K' r      (car l_s)1 E/ E: L, G8 d1 Y9 ]
    )1 S* [- F0 ?  W8 s1 `
    (setq l_s (cdr l_s))% t- }6 `7 j4 M% ]- \
  ); repeat4 @* N% J; v! ^
); layres8 I, Q8 A7 |9 k7 |$ \0 Q  E% ~* N
& v6 H) p& j2 o" {
;----------------------------------------------------------------------------
( h8 i+ o7 k7 F9 ]- i; Get DXF codes! \4 X3 U; {4 }% ^$ m' r2 H. G
;----------------------------------------------------------------------------. V' W+ G( T" y# J1 y
(defun entgetf (index ent); i! e9 Y& I: {  y
  ((lambda (e)
7 N1 r. O/ V4 l% H) }      (mapcar '(lambda (x). s! J+ R' G$ R1 N
                 (cdr (assoc x e))
3 w# L" h& ~1 X! w               ); lambda
( z3 Q% o  h/ e- V3 ^( W               index) ; internal lambda function, U" t6 V: P: `" r1 ?  g' o
    ); lambda" G7 Q  P, s" j/ m% _/ {  s1 L
    (entget ent) ) ?7 F8 C' B' A. ]$ H3 ^0 t
  )
3 l: H3 L; D! U8 @5 N9 V); defun entgetf
' H+ a: t0 G6 Q/ H: G% @' \
' _' H& |- x4 `& |' z1 @. J;----------------------------------------------------------------------------
! k. X; l2 j( f5 W: ?1 [! d+ r; Save UNDO status
  S& V' b/ E7 q  ]4 v' ~;----------------------------------------------------------------------------3 C- Y1 x+ o4 j# e9 f
(defun undo_init (/ cmdecho undo_ctl)   
$ A4 ^; a7 D0 N/ [( S% S. c  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value' s7 m: j) a# n  w% x2 l
  (setvar "CMDECHO" 0)
5 m# a; F7 M, E, n' R+ b. K0 D: a
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable( T8 g8 I8 |  Y% m5 \2 \; A0 m
    (command "_.undo" "_all")8 s  {* j6 f3 ]* `4 j- J0 \
    (command "_.undo" "_control" "_all")
9 ]2 J% W" \- @1 }# R8 q  )& L- @& C2 t2 l

4 W! B# b; u8 m6 E# m. ^6 M' m9 n  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off
3 q6 W; Z# ?: o6 H    (command "_.undo" "_auto" "_off")
- a& z1 w8 g0 V: ~5 q  )6 ?& B7 Y# A: p$ C

1 V& `! z$ O# v" F9 i3 ]$ q' f  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
( L1 {7 S5 e' Y- q    (command "_.undo" "_end")
6 \; U+ z' O( Q( H& t6 g* `$ T' N  )& M) l5 [% X( @3 y, l6 s1 d& p+ S

, o$ j- a2 b1 u3 ]  g+ b  {+ n1 F1 @  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
" h' r4 Z! T; v0 r) W9 v5 H4 X# M    (command "_.undo" "_group")/ M% d' y$ D( x1 [, K. ]
  )0 Z# z, Y5 U- [

2 |9 v& O9 J& n- `* P  (setvar "CMDECHO" cmdecho)
3 H: i! N, Y$ P7 H% a* F  undo_ctl& |1 h1 N- H( M. p6 J/ Z  p2 P; a) s' i
); defun undo_init
! ~7 T' h( x1 N
% [& P# d7 X( a, c+ N;----------------------------------------------------------------------------% N) k& ?2 ]" H( U+ X% u
; Restore UNDO status
, E( g: p8 [9 ~, E;----------------------------------------------------------------------------4 T- X; s* t+ w: x
(defun undo_restore (/ cmdecho): K4 k$ o, X3 H" d) i1 Y0 J2 _* P
  (if old_undoctl
; l$ ?2 p9 \$ b; D2 q+ N) X# P    (progn
% X0 R" z- P8 v  y      (setq cmdecho (getvar "CMDECHO"))
& o) E6 L- y* ]+ B      (setvar "CMDECHO" 0)1 {! u' k$ K6 J' `/ o( x- u& b1 b4 O4 k( ]

; g. s& @. s. M4 d5 ~      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
6 X5 h( R4 T- {8 _& _      (while (equal 8 (logand 8 (getvar "UNDOCTL")))3 G) {( S" G1 U" x- \7 `
        (command "_.undo" "_end")8 ?/ z; e6 K+ R- D6 h
      ); while
0 {% ]! z. W, K/ ]2 L1 L3 u* _5 ~. t' x/ i$ n& a0 [

* C. Y8 r7 Z1 a4 {      (if (not (equal old_undoctl (getvar "UNDOCTL")))3 v; E! |5 ^* `' B" e4 D
        (progn
+ |4 H+ \7 C3 V7 ^          (cond" P$ b7 S. S+ o  u/ E
            ((equal 0 old_undoctl)
! X* c# N8 `4 j+ V! I, k              (command "_.undo" "_control" "_none")
2 x$ Z* T" P% @3 y5 \0 L% U            ); Z6 V. d& [/ h* G
            ((equal 2 (logand 2 old_undoctl))
4 S8 f- Y+ G7 p$ W, ~$ m0 `              (command "_.undo" "_control" "_one")* C2 q6 n" G' `7 A- d7 Q
            )
" s( J& ~, {! L3 c& u& Z: {          )9 p- {, k; A. A9 y$ d
          (if (equal 4 (logand 4 old_undoctl))9 G: f1 V8 V  I/ m; D5 x
              (command "_.undo" "_auto" "_on")( L4 B3 v& k1 B: ^' |1 O
              (command "_.undo" "_auto" "_off")* a8 @  X. i6 l3 k$ G3 W  r
          )! z0 J* f% [, }0 u7 F$ I
        ). ?8 n- ?5 |) M
      )
; X# v4 a4 |+ _) Y. D' R8 M% w      (setq old_undoctl nil)' X9 m' N  F, }6 X, r
      (setvar "CMDECHO" cmdecho)
1 Y2 j4 A9 b' Z; v    )
  W% x" X4 {# t4 w$ \- P( {  )8 b- @; U) \; z" \1 S7 z: e8 w6 \
); defun undo_restore
' y2 u8 |) r9 S  T1 W+ f9 ]) O# [1 n# q( }
;----------------------------------------------------------------------------' ~  b  W* B" H7 s
; Save variables
6 I# I0 S, K& [2 _$ ~2 I- V* C;----------------------------------------------------------------------------
* J% C; T" N2 x(defun var_save (a)
9 g) w5 f5 Z/ D% [) H3 j  o  (setq m_lst '()): A" j3 O- M7 J$ F7 X! f, T
  (repeat (length a)6 P3 c' i* }! x9 ?' J* [
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
1 K! e  j5 o& y) t% N2 K    (setq a (cdr a))) M) Y' f; h( e7 w* z8 ^
  ); H1 _, I, N; z8 Y  r
); defun var_save
1 a4 G) y0 z! V  A7 @  p9 _# g
* d0 g$ @# g6 t9 ?2 j' [# J' C;----------------------------------------------------------------------------
- \* e. _( `8 B* n. i0 {" V8 H9 l8 R; Set variables1 i7 Q8 C# T( |. i
;----------------------------------------------------------------------------
: k' T% o# c) z& P(defun var_set (m_lst)
' X) b! K: y9 o- |5 D# p  (repeat (length m_lst)
4 b3 X5 B6 `/ e% i8 D$ {    (setvar (caar m_lst) (cadar m_lst))
0 z$ J2 A1 h+ C; Y: W7 `/ _' U: w    (setq m_lst (cdr m_lst))
" V( J' O  O( N9 ~& N. F* s, z  )$ L3 t1 Q2 _8 i- R7 s
); defun var_set* c4 u4 B% g  b' s% Q% K
* P8 _, M: G4 r+ R% P
;----------------------------------------------------------------------------
4 F! ?! d: C& t) W4 _6 [; Restore variables
: o0 e0 a; D( v9 e0 ^;----------------------------------------------------------------------------
$ }! E* S* `# p5 \: @(defun var_restore ()
1 m/ k9 M8 r* w4 [  (repeat (length m_lst)1 }5 ]$ n: g0 q; R
    (setvar (caar m_lst) (cadar m_lst))( B$ Q: N5 A/ g: G+ o: q6 F2 d
    (setq m_lst (cdr m_lst))3 @" u6 l8 e4 l: A
  )8 V8 E* F0 A4 t3 o; B
); defun var_restore
0 G* L3 m1 f  \2 Y- e9 T5 v+ A4 P
. c' a2 V2 m) }5 w;----------------------------------------------------------------------------- O' C/ ~9 W1 W' b
; Initialize routine
8 b3 C* D. X& [6 R1 j" I;----------------------------------------------------------------------------0 X- y% w8 B, U9 ?6 A" k' t
(defun err_init(e_lst u_enable add_fun)5 E; o: {1 ^. Q7 [6 }" f
  (if err_alive (err_restore))          ; To avoid nested call
* q: e0 C: @. ]4 o9 T9 Z( {8 Y  (setq err_alive T)
$ o& c  v/ {* c6 w! l+ N" a; e  (var_save e_lst)                      ; Save the modes
; Y: U: k2 N1 \8 E  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status( Z1 W3 k% I9 w1 v
  (setq err_old *error* *error* err_main) ; Save the handle of *error*2 A6 F+ n6 g# ?/ v
  (if add_fun                           ; Add the user cleaner% R; d; Q: c& g; q: r
    (setq *error* (append (reverse (cdr (reverse *error*)))
- N: W9 w' u# p4 ]3 K  A' g8 o                          (list add_fun (last *error*))
* M- R. N9 K8 l# v/ G( G/ i                  ); append9 {: N. N7 w- Q/ g3 `
    )
1 ?& ^! a1 u) |$ b  )* d7 y" F1 b7 n- D7 D5 b. _
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------4 z6 P# u3 z2 e; x+ L9 U
; Error routine body
; S' B' {+ w) O' h% k% I;----------------------------------------------------------------------------
/ }) U- [' A) W1 }(defun err_main( msg / )                ; Body of error routine, h& G$ `6 q3 j8 d3 I' J
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs+ Z9 ~4 L3 l8 m* M! s* x
    (princ (strcat "\nError: " s))      ;while this command is active...
0 N3 U$ w3 i5 I5 J4 X  )
2 h; s4 s( O9 P6 ^  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
, A  p- H% i4 e+ P( F
  _8 {9 X  k$ a) ~  `) t  (if old_undoctl
# }5 k- M! w  J7 S! f# Q    (progn
/ M+ o7 i4 v. A# F) s2 x      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See- M2 t) G! j; v
        (command "_.undo")              ; if it's in UNOD command5 g- K+ ?6 g2 X( w# i3 A/ s
      )2 v7 t' A  L5 t) R- S2 l8 V5 k/ a
      (command "_end")- {5 x7 d$ z9 b/ Y2 @+ `
      (command "_.undo" "1")! D4 p  _) B' I
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))8 S4 t6 ~; \5 ?
      (undo_restore)                    ; Restore the status of UNDO) S3 W7 N. E, f2 a* l. s
    )0 e2 i7 W2 D1 F: t
  )* B4 |* X9 C# p9 Y" |- a( e5 C
6 @) Q8 J+ }/ l9 L: S6 \* ]
  (var_restore)                         ; Restore the variables
2 v' b  |0 N' F, A/ M/ M  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
8 R- U- m* y* j! R" L) Y  (setq err_alive nil)
4 G" a" \( L) Z7 J- d+ T  (princ)
2 Y3 u- _4 w& r4 K); defun err_main7 ?7 D# h  u+ r0 t

, X0 y4 Z8 V9 i& L$ K' S6 C;----------------------------------------------------------------------------
* s6 F- S9 p0 i; Restore error status8 i8 k- B( y; j5 b4 R7 t, E, h
;----------------------------------------------------------------------------
; a: D9 n" ]3 I1 n0 E$ v1 b(defun err_restore()' c: u( m# M' f4 s+ H1 d9 Q4 b
  (undo_restore)                        ; Restore the status of UNDO
1 Y" M; o' O5 b  (var_restore)                         ; Restore the variables
( g6 K* y) t: N3 r7 R  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error2 s5 e' |. V; M, @+ @: p) O
  (setq err_alive nil)2 c& n1 O- ^. K4 h: o' E' f9 P  e
  (princ)
1 K9 p/ o* z* q, m6 r, q1 x); 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-12-13 17:45

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

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

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