CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
- P, o5 s. {; Q; @/ }1 W “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
. _& i( e' |  b$ A3 k' m; i! l. i提示:加载成功
- Q+ Q# z1 b& \; Q6 U3 ]' V然后使用CLOUD命令," [- K4 Z) A6 S9 }1 Y: ?
提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”, K0 ], d1 E* ]; s, P+ K0 Z
请高手指点一下,这个是怎么回事?应该怎么改正?% _. I: E2 G# Z5 a% @& w
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx
- M# W, N+ z+ U;;;
8 [9 b1 q0 }$ J* K5 X( Q6 ]: L;;;  DESCRIPTION
  r6 @- W$ R/ E5 @  v5 a3 };;;     Draw cloud and you can specify the globals variables listed below2 o/ @8 E% n! W+ e. E6 l' C. r" B8 p
;;;     to decide the characters of cloud- {: h% }: P( M
;;;
' T- t) C, P2 X9 C* ?; C;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98" H3 V" C5 h2 V
;;;1 H2 o2 S- q* d6 w9 V4 x0 k
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed* s  H2 }3 d3 U3 S; D$ Q9 v; G
;;;           Change CLOUD.001 to use CLAYER to perform the same function! ?' O$ b2 O8 h4 c8 X$ [
;;;           Use the common error routine UNDO.LSP to optimize this program3 E# N" d* c. K- Z, v
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
7 N# ?2 ~) }. N3 M;----------------------------------------------------------------------------( R9 q/ K* J0 P7 ^% \
;  GLOBALS:* `* L- t/ v; Z1 u
;     cloud_layer -- layer of cloud# `$ D" L4 a4 W; Q" {) u0 n' ~1 F* i
;     cloud_scale -- scale of cloud0 C0 \! |& f8 K/ H5 v, x$ L
;     number_rev  -- revision number3 y3 M! B& Z0 l
;----------------------------------------------------------------------------
1 F7 {1 i2 \  k3 k- H(defun cloud (/ locked temp first_point next_point relative_point5 V! L9 a! {# }' Z
               last_point point_tri point_ref corner_1st corner_2nd length_tri2 ?! h  E; T: A- D/ Z5 j
               length_cloud angle_l_to_f dir_tri repeat_count & h2 _% L" a) N& d7 a" A
               table_cloud )
: U+ ^0 `( ~$ V: t6 I        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))
6 L, O: h- @3 E  b4 Q          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit)): a3 H* M. g& j, l1 E
        );if5 z3 H3 A% M- d9 V! S* I% d+ T
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
5 D. T2 |( e8 h! G$ U: \                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
+ E6 }% M3 d$ B  G% k9 {$ T        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
$ z5 w8 g& u6 F                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))" W* c. v  `0 V

5 P$ i9 k/ g, M! z  r2 J        (if (not (numberp cloud_scale))
4 W1 }; Y0 y5 u8 ^% l1 d            (setq cloud_scale (getvar "LTSCALE"))
  F( l8 k5 g- j        ); if
) P+ o* j3 y: g5 [( m* y: A1 q        (if (not cloud_layer)9 R5 @  W8 P- c+ X* j1 z, h) J
            (setq cloud_layer (getvar "CLAYER"))' ]5 R5 R# }: k4 O8 B# y- }
        ); if
9 B! c+ T! f1 k: \; ?( K        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
0 }8 s. o6 M/ W" r2 X1 o. \" v        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))6 u3 a' t) [7 L1 f4 ^7 H, B
        (if (= (cdar (laychk cloud_layer)) "No")+ |9 V2 G+ W3 r% Z
          (progn9 n) W7 P4 I3 i# u- \
            (laychk (setq cloud_layer (getvar "CLAYER")))
, E# N1 M( M- F9 z/ i  L2 U            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
1 O; K+ F) R' p$ K( h          ); progn' B7 T. w, H2 c4 H
        ); if
. n' S7 A# X! l# Q0 o$ `
" Y: |; T: Z% c8 l* h+ G5 E- b        (while (/= (type first_point) 'LIST)7 D: \; J2 f2 j' B1 b1 g
          (initget 1 "Layer Scale")
! S4 L, i% a3 K+ p; `          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
6 H0 Z9 z+ U) ^, d          (if (= "Scale" first_point)      
* h: o5 e; o: {, o3 }            (progn
7 r2 g- }! `& V$ t0 w+ g) @& e; C              (setq temp cloud_scale)
# c  A  q, X+ S1 w' b              (initget 6)
' \, e7 e+ J/ `" y9 c/ ]$ X              (cond) P3 m6 G( y% w# `9 R7 C3 w
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"2 b$ Y5 k0 W  w
                                                          (rtos cloud_scale 2 2): z2 x$ H2 u, ]! Y9 L+ d" X
                                                          "> "))))6 A' {+ f8 x: B, |
                  (setq cloud_scale temp) )
, `' d" U6 L/ \5 N              ); cond
, t( h( w- ]$ h1 N! \( W2 w1 g- c            ); progn
* B1 z1 D4 G; p# e6 @          ); if7 d& r' Y+ h8 J
          (if (= "Layer" first_point)
/ B- ~& `# f, U            (progn+ q% L% n: U6 d
              (setq temp cloud_layer)  L; E+ ?# C. U
              (cond0 I7 A$ o6 O/ }! E) r. \1 X9 }, [7 M
                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"7 E* o' l8 m; b# q4 @* M
                                                          cloud_layer "> "))). Z. [& A5 C' r3 e9 J( e$ g
                     "")5 l; y5 W+ t, L2 f/ M1 m, u8 N2 Q
                  (setq cloud_layer temp)+ w$ R9 A; J3 Y5 _0 K
                )7 B3 W' I8 W$ j& K9 E3 ^* Z  ?
              ); cond/ z8 W) o! l6 i# E
              (if (= (cdar (laychk cloud_layer )) "No")
0 @, R9 Y. {+ q+ K7 b                (progn, _3 Q3 T% ?9 Z" I; ~! ~5 F& D9 g
                  (setq cloud_layer temp)8 U' O5 u; B9 S4 t, }
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))9 ?+ f% R* i, E+ [
                ); progn
5 T& f* z  Q9 [              ); if
3 p  P: N4 Z0 Q4 X- U# D  V            ); progn
) s5 k/ s& D5 Z1 I          ); if/ ], u; G1 @5 S, k
        ); while
  f2 j, T6 ~1 {        (setvar "CLAYER" cloud_layer)9 T! f, Q( K1 O  X
) M# M8 M9 V- f. ?# G/ |3 \) g
        (if (>= ( getvar "LUNITS") 3)% V- Z4 \8 ^  O, B8 ?! Y
          (setq length_cloud (* 0.25 cloud_scale)
- H" f1 r( {( O                length_tri (* 0.3125 (getvar "LTSCALE"))): ~! o) _. }1 `' _: J+ T& I
          (setq length_cloud (* 0.3406890 cloud_scale)
+ d7 E$ W4 z$ }  d) J2 \2 ]                length_tri (* 0.438366 (getvar "LTSCALE")))
) a6 R/ I1 ]3 i1 L# ~% \        )5 ?* Z, j- K, D. H
        (command "_.PLINE" first_point "A")
- s# ~3 ]& v* ?$ _- o0 l' t        (while (not (equal next_point first_point 0.000001))
  D4 e: c2 s; A. j0 r! ^! b6 b          (initget  "Close")
3 Y, ?- c3 ?3 u+ r          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:")): U! S, Y9 _1 \+ D, d
        (while (and (not (listp next_point)) (/= next_point "Close")); Y. k7 X5 h. b' {  @  t$ P( y
          (initget  "Close")2 h9 r; u- a6 v9 d% X/ ~& V" I8 k
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
& J3 D! S) k! I( v2 ?        )
+ y1 ^/ V6 O5 ~! E# B& _          (if (= "Close" next_point) (setq next_point first_point))/ ?, ^1 d7 y0 y. |: S
          (setq angle_l_to_f (angtos (angle last_point next_point))
# V7 U: C/ F/ ^( N7 y# a                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
+ j( j3 U. I  C8 r! Y          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
' L' ]% C; D! }% Z! u: q/ i/ W) o             (setq repeat_count 0)1 c$ W# G* }, K" I; q$ `; z6 y
             (if (>= (- repeat_count (fix repeat_count)) 0.5)
$ d4 k" \7 y0 l4 q               (setq repeat_count (fix repeat_count))3 C$ C: n8 k' i# F; T7 _
               (setq repeat_count (1- (fix repeat_count)))# v+ c" x& [7 E/ r$ @
             ); if
; T% y7 w6 w/ X( b. G2 u4 a% m          ); if" i$ y, s6 k, m) |) i+ E$ I
          (repeat repeat_count (command "A" "-100" relative_point))- I; j1 z  i4 S5 A
          (command "A" "-100" next_point)
& F1 ~& `3 \2 ]9 a          (setq last_point next_point)
) o5 }- K& a% ^+ C' D        )
: r# K: \; p. o$ ^2 _* Q, L7 i        (command "")
$ l& @: z+ T. v& d        (if (= (type number_rev) 'INT)
; a$ n% `! j( ^$ y9 X) ]! t$ A           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))) _, p' j- c9 Z% i, ~6 d, E* b
           (progn
- ?3 H# t: t- ^: j4 ^+ J             (initget 5)' I1 F& u' k; e( F* n( W, U7 H
             (setq number_rev (getint "\n请输入版本号:"))
1 K- j$ _: r& e7 ^0 q9 N           )
' L' p- A% ]7 Z. N/ \$ i9 @        ); if
9 p* X/ V5 P. o  D        (setvar "OSMODE" 512)
0 K0 I  `5 i5 k8 F8 R. p& Z        (while (/= (type point_tri) 'LIST), C( K0 B6 K1 C$ |: @& M3 Z
          (initget "Number")
% m9 a5 {$ n1 |9 b: E& o          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
: A! A" p! u- j0 E          (if (= point_tri "Number")
8 R7 [' }& @8 p2 G5 G1 W0 S              (progn
  _8 r, r; g  C5 x% x                (initget 4)2 B- ]5 |. k" @! u" H
                (cond
3 H. K  c2 n( o/ P; `* l3 t+ n                  ( (not (setq temp number_rev ( P  S1 v4 ]* `$ H
                               number_rev* }) O$ |; |( M( w0 m: Z/ \" z
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
+ V# |5 N: |/ ]& b; F. u9 n                    (setq number_rev temp)
! {0 v6 e) U) X; f* g                  )
; t# c  M' h9 P; K4 w9 y1 h                ); cond
, c7 ]. ?+ x7 G1 ]              ); progn( n3 x. J# I; b. ?2 n3 x( h
          ); if
- N4 H4 O& e0 H3 C# V        ); while
6 A( {) `5 t. x  ~+ F        (setvar "OSMODE" 0)
0 J/ S- E# X8 M4 v" C+ [! n5 w        (initget 1)
% s- E3 b3 m& c. y        (setq point_ref (getpoint point_tri "\n请选择方向:"))
; w9 e: {+ j5 \# X        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))& m- A  ?! q9 |. y/ B
        (setq corner_1st (polar point_tri, @; _# ^; N) Z; G0 G& m% H( l
                                (+ 1.570796327 (* -1.570796327 dir_tri))
3 y; E4 U& P6 m: l                                length_tri
, b0 O* q* U/ @4 _                         )
2 S% ^& r% Z# t& o9 d        )
8 ^0 ?1 I: V$ A        (setq corner_2nd (polar point_tri
/ k. V& f: l1 ?9 Q, i                                (+ 1.570796327 (* -0.523598775 dir_tri))" e9 b( S1 h  T8 {6 @5 a) w
                                length_tri" {' z; O$ q# E5 z/ x, `
                         )$ h4 w9 a! Q" k; N0 _4 l2 r- y, F: k0 B0 l
        )' i% y5 h% p" a* C7 c5 s2 [  d
        (setvar "CECOLOR" "2")
! m: |6 ]  Q7 e# X! |0 R( c: V        (command "_.pline" point_tri corner_1st corner_2nd "c" )
6 R$ r, d. s9 P: i0 L+ E5 A  \7 e        (setq textstyle (getvar "TEXTSTYLE"))' `  A' v- Q2 c6 E
        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
' P2 W! W  U3 z- J- @+ F        (setvar "CECOLOR" "7")
1 A  M' }/ |5 r% s7 \0 ]( u        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
2 V4 {1 p" M% }' }2 n                  (* 0.4 length_tri) "0" (itoa number_rev))
$ P4 w4 |; [) ~8 L8 U  `& q0 B        (layres)5 ]4 S  H/ D" ]5 r( N6 P
        (err_restore), g5 ?( q  O0 K/ W
        (princ)2 U" r" f( {) M9 Y1 ^
); defun cloud
( ?" I5 E) k9 v2 I8 }
" T6 n. {% x  |, \: v! r& M(defun c:cloud () (cloud))
" ^; R* x& N/ ]0 }- p% _(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy  X1 `7 ^. l' {' }4 h2 t. U1 s
;;;8 o" W& a0 ]1 f9 `
;;;  DESCRIPTION( Y& L7 A; T: C9 H( O5 k3 `1 ~
;;;     These are general error routines which can be called by 4 q  d% k7 q  P% o
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference
8 l2 B. a: P0 D: q% n;;;/ c7 b/ M# u/ m5 V6 y' B4 I' ]% e
;;;  SUBROUTINE INCLUDED IN THIS FILE- z9 a' k/ ?8 B. S, ?8 @9 x
;;;     UNDO_INIT- k. D8 ], S. ?8 ^% N
;;;     UNDO_RESTORE, d' E2 U0 J0 M6 A
;;;     VAR_SAVE
( N; B/ x7 i+ r: {;;;     VAR_SET  6 k8 T2 K# e; g. E$ ^% k) C/ \
;;;     VAR_RESTORE  h/ i) R. `/ [% i/ @
;;;     ERR_INIT 7 V5 S+ l  L. q, y9 d7 Z4 v
;;;     ERR_MAIN
  \: q# l2 M  S;;;     ERR_RESTORE
% X7 e  N0 c3 A;;;
& m, ]0 O3 l+ S4 i! b6 `' Y;;;  DATE: 10/17/98; 03/31/99
: G! |; `: w4 Z5 G' v;;;1 W% W9 H* J1 o
;;;  HISTORY:
8 N5 N  K1 I1 u2 S0 Z3 R9 M  Q# S;;;    Add routine of mod_att
1 I2 K5 z+ @& h8 Q( P9 U;;;+ p/ N7 P# H  i- a9 T9 k* U6 f9 J2 o
;;;  USING METHOD
; C, g; @: C% _# h# ];;;    ERR_INIT:
+ V2 ~% ?8 k% |2 q: k3 };;;      This routine initialzes the error handler. It should be called as:
' U, M$ P- t6 Y0 m: W: |5 L- e;;;
  Q& K7 [( p' S+ q;;;      (if (and (not undo_init)
2 Q* H. X3 s& e9 S;;;               (equal -1 (load "undo.lsp"  -1)) % {2 L: n( i/ S  j: z3 G8 {) ]
;;;          );and6 J! w8 h# c8 W# p- f. V7 G
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
( K2 K4 v6 D/ F0 i( l" J& x2 c  T;;;      ); if
: v- a# o) d# Y9 o! h* x/ S;;;
2 K( F4 A& E4 U+ z/ v# ?& F;;;     ARGUMENTS:6 p& A$ x3 U+ h" X" U
;;;       err_init Takes 3 arguments.
6 s0 @/ T2 _, l;;;     1. - The first element of the argument:
5 G6 Q7 |) p" [" k( J;;;          This is a list of system variables paired with
- j1 o8 N. _* X, g, S! {1 Z; O;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")+ U; G- J5 x/ b* l
;;;     2. - The second element is a flag) O" u& N. X. e6 V% q  ?" Q
;;;          If it is true, then in the event of an error
- _4 Q- d% ^- g;;;          the custom *error* routine will utilize UNDO
1 w/ L" q/ |/ {. V; e;;;          as a cleanup mechanism.
6 m4 X' Q5 h! w2 ^3 U7 c;;;     3. - The third element is a quoted function call.
4 M/ \/ E0 W, M;;;          You pass a quoted call to the function you
- n8 N% t/ q. ]$ l;;;          wish to execute at the end of nomal routine if an error occurs. : b9 I+ o; F4 V, o9 @* [4 I
;;;          i.e. '(my_special_stuff arg1 arg2...)
  n% x/ y# [" Y0 A" O/ a;;;          Use this arg if you want to do some specialized clean up $ K/ z, B. F) _
;;;          things that are not already done by the standard bonus_error
- x) ?/ ~* ?! o3 P' k;;;          function.1 _7 c7 c1 P/ i/ p
;;;2 U  w) S' F5 ]# K
;;;    ERR_MAIN: Body of error routine6 O6 ]# H  E+ {4 i7 c' a+ t
;;;
6 A+ _6 p; J1 Y! N0 B3 N;;;    ERR_RESTORE: This routine should be called at the end of command to
$ {7 s) D' @8 e- P6 W& O;;;           restore the VARIABLES, UNDO & *error*.& F# }5 A+ I+ U: A
;;;1 r" Y, x0 I" M5 c* h; m0 ?7 b5 [% G
;;;    UNDO_INIT: Initialize the UNDO status, L; m& E# S7 I! t
;;;
: F0 C, W# |( ]$ _6 u6 M;;;    UNDO_RESTORE: Restore the UNDO status
) j' D$ E/ m* {+ C1 h;;;! O5 e, \! H  h- ~7 ?; ], e
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
# _" Y4 V6 [- N. ~( E+ X" [;;;- {1 m' ^! ]2 k0 V4 e
;;;    UNDO_set: Set the variables. the argument is like
! V, g7 M; E! q) Q; {' p8 ?;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))' z# }# m  [+ i7 `
;;;6 H+ U3 F4 G: w$ h
;;;    UNDO_RESTORE: Restore the variables/ {# n$ e& Z: v9 `' W9 n) J
;;;
! v+ t3 |" B3 [6 y9 V;----------------------------------------------------------------------------% V1 R" H  b/ V% @& ^. U/ J  b6 ^
;  GLOBALS:) ]7 `' @9 |3 n3 @% f
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)1 _0 x$ q, Q7 G: {7 ?
;     m_lst       -- list of variables (voided by VAR_RESTORE)
' s. F/ w! N" h# }% m% @5 r4 n1 p6 _;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or5 O; f: l& k# ?  h) F! W
;                    ERR_OLD)
# m3 b) R9 r0 \* y4 _2 _& m5 n;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
& Z# M3 C+ J  y2 ?& n. y& O;----------------------------------------------------------------------------
, q. u8 {5 C$ Q$ C- }; E. F( s3 Y& N3 c4 z% i
;----------------------------------------------------------------------------
) D' X6 F' v( X& e; Modify attributes according to entity name, attribute name, dxf_item
; C( d+ p+ C# c; r+ U;----------------------------------------------------------------------------
& `+ q4 B1 Z& {  M- E(defun mod_att(ent id dxf_item)        ; f' y) B1 I* x4 M5 P% t
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
+ j$ E) J( G# z: u0 `    (setq ent (entnext ent))
2 F: X: B# @) g0 m; `% m* l9 @3 P  ); while  
4 ]/ K$ v* C! r4 y& s0 `  ((lambda (x): Q( P; _- S# r
        (mapcar '(lambda (y)9 _+ g+ l( V4 M7 Q0 u4 ^
                   (setq x (subst y (assoc (car y) x) x))6 A  e+ u6 b& \+ ~: F" m* Q7 |
                 ); lambda
) x  J' C' q( Y* @) B8 Q                 dxf_item
3 a# L, ?. u% [: y5 }1 ?0 S        ); mapcar
! _: q/ H& J0 K' n& H( E( ~8 d     (entmod x)
) C& t: f( z: w, I6 S     (entupd ent)
4 X" N6 n4 S# G# i$ I: U   ); lambda
% A/ ]& |- v. V. n: M$ _( ]/ o   (entget ent)
; i' `% M6 t$ Q- J )  M- {; k6 P3 s# a+ v' M7 X; Q4 L' s
); defun mod_att+ z7 x, w8 N( w5 H& ~' W& z

1 b$ @! R# a5 U( o- ?2 L% ]( o, T;----------------------------------------------------------------------------
2 e/ P% h$ t6 O: O1 P; Check layer status, return a association list which contains layer information
# f) `" x( U2 g& F;----------------------------------------------------------------------------
- }6 B! K) a2 \% L- ^(defun laychk(lay / l_sta)
- H7 `6 C: B( K2 L! N  ( (lambda (x)1 e1 P4 ]" k# F6 S4 g/ y
      (if (not l_s)( j# u5 j3 d$ C/ Y3 B  e
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))6 _. I; q; f2 i6 u1 }; V; Y6 `0 {6 ?  w
      ); if8 S* F& z& L4 S
    ); lambda
! Z0 D1 E8 s' K    (getvar "CLAYER")6 }0 V- P6 \+ x: k; `' y2 {
  ), z% a2 v, T) s2 g6 T
  (if (not (tblsearch "LAYER" lay))7 ~# z' w  m: m7 P: M
    (progn  
6 Y- y1 U1 \' z# J2 V1 a      (initget "Yes No")
0 R  v0 m& N; x$ n3 o- R5 Q      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
% o4 H% W& V. u9 H7 g        (progn0 I4 p/ i$ n5 f) s. y
          (command "_.layer" "n" lay "")5 \; f" V" o  f: ~, z. d- D2 M
          (setq l_sta 0)
! I: O/ ?6 j$ I! r0 }* {7 `5 D7 f        ); progn
: ~! A1 J0 \: M+ E+ Y2 k      ); if+ Y& Q3 B8 K2 t, g- k4 \
    ); progn
% d% O) d* f: n    (progn
) E3 A$ j4 b3 G# u2 ~3 U. B      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay))))), U$ `( ]; E; P3 u* I% a, a; m
      (if (= 1 (logand 1 l_sta))8 w3 S) r, T. ?7 q1 }; p
          (progn% E$ q7 I4 x/ W7 T! T+ Z7 P
            (initget "Yes No")# ^3 q) T! G0 ^+ ~2 \8 g. F
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")
1 J" y! G) N+ E0 _" x+ [0 ?/ K              (command "_.layer" "t" lay ""). h4 @0 A$ ?0 ?2 I! a: C9 y
              (setq l_sta "No")) i  p  q; o- D9 R) b" u5 b
             ); if2 y  I5 D$ }( V
          ); progn2 K' w* K2 K, f5 ~
      ); if
5 M2 @! d! J( a      (if (numberp l_sta) + [' C, A( z& T; Y5 {
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if, N- z$ a  F/ L: p7 x" v
      ); if
8 _9 E/ h. ^9 h    ); progn+ B2 O4 o9 i$ L" }
  ); if5 V7 L  J# ^/ l+ s: |/ E- f* J
  ( (lambda (x)+ R/ {$ r& p8 p. }* w* m! \
      (cond
( r  I: p: D% g; `- o        ( (not x)
' {3 w6 M* B: g* u" G* G          (setq l_s (cons (cons lay l_sta) l_s))4 x% W0 [7 F7 o2 i  I0 F0 F1 |
        )
5 \$ Y; v8 V; M        ( (= "No" (cdr x))' m; K8 T0 Y; ]
          (setq l_s (subst (cons lay l_sta) x l_s))
5 x0 a" n* ]+ P7 v9 [1 h2 H6 q% g        )4 A/ Y! X# B! S: Y. |7 b" G
        ( T l_s)
; S% v) b9 a! ~( W- s      ); cond
  r, T/ t0 D( O5 x     ); lambda9 L0 m5 _0 J" M2 m
     (assoc lay l_s)# u5 p, H/ K0 t" u6 _
  )
& k! j' n& p! f- n( `. M, V' N9 I6 A  l2 g- ?1 ~4 w
); defun chklay
9 P4 y9 B5 q' d* s. U8 |+ w/ s9 @# i
;----------------------------------------------------------------------------
4 p$ O. u% [  [; Restore layer status according to association list l_s
) U/ K, t0 d% a" z% S: k' I4 h$ B1 x;----------------------------------------------------------------------------/ S7 R# E( F' m
(defun layres()$ C( G) j" C; ]
  (setvar "CLAYER" (car (last l_s)))- J4 `" I* j* a3 h" t4 }6 c
  (repeat (length l_s)2 I5 R- T3 B5 I
    ( (lambda(x)  
2 |2 {3 H* h: L: h! Z8 J) G: U) r        (if (numberp (cdr x))
1 a; n- [) h: Z7 |  k! ~0 k          (progn
* e7 L3 l6 l, ]0 f2 p, c# U9 }1 e            (if (= 4 (logand 4 (cdr x))): W/ S" Y; c  h$ B) q/ S8 H2 B
              (command "_.layer" "lo" (car x) "")
* @* b1 {. i/ c8 @# x# A            ); if! L) K5 q8 f: I. i- z7 x
            (if (= 1 (logand 1 (cdr x)))
9 c2 {9 F/ r" _  y2 C4 k              (command "_.layer" "f" (car x) "")% L/ c2 P. ~) ]' g! |* A
            ); if1 g  b) t( H2 x) `
          ); progn5 Z. T( J4 T- R. G( x$ R: W
       ); if  ) O( X/ T8 o) A- u  a
      ); lambda
6 v0 u$ u9 L5 \+ N; F1 u: m      (car l_s)( K- C. Y& P) k: ^$ ^
    ), X2 G6 h/ g6 X  W
    (setq l_s (cdr l_s))
* B; ]2 Z/ v' A% h& H  }' g! c  ); repeat5 @) {( x% b- [5 C
); layres( h$ D. Z! V1 B! U. G( M& }% {

" t0 K" o, K- N7 s) y;----------------------------------------------------------------------------$ w- _; d8 V* n
; Get DXF codes
5 x+ y; m! j; \+ @, R/ V! f7 p;----------------------------------------------------------------------------1 @8 @) m1 j+ E# V
(defun entgetf (index ent)
1 f( i( ^, T( n8 c2 J! ^& G  ((lambda (e)+ u7 c9 D1 m6 a* \  ~
      (mapcar '(lambda (x)( \8 ^) c6 n: I9 |% f: p
                 (cdr (assoc x e))
5 ?' u2 D, [5 t( X6 z               ); lambda, X3 F# ^6 e) M
               index) ; internal lambda function
) _# I9 g  E7 }3 t- s    ); lambda  @0 b+ ^2 S. C9 X7 P
    (entget ent) . g  [2 q+ l7 J& T. V" L1 w! r
  )& w1 t; i# {; R" w5 R# {
); defun entgetf
4 M. s( I# R0 a9 I! a' V8 R: I4 J0 v% U$ k% g' J
;----------------------------------------------------------------------------
4 F( D% f. N# i3 X& i; Save UNDO status. ^7 g+ W8 l2 H7 p
;----------------------------------------------------------------------------
4 c; U. P2 }! @# q; q- A% z/ S' t- I(defun undo_init (/ cmdecho undo_ctl)   
6 `; V& A! Y# V( ]( s  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
  k/ Q: b8 I" E% ], G9 U  (setvar "CMDECHO" 0)
8 R2 G2 H+ E" R% A5 t
* X! e. p5 Q4 J# c; ]6 ^: z  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable7 M. c7 v& C& Q9 K8 b
    (command "_.undo" "_all")
# m; I7 }+ z) W    (command "_.undo" "_control" "_all")
6 i' q# t; a3 ~4 m2 P  )1 q( A2 S6 h% q1 G. s- t

+ l7 V2 e0 s+ j4 X& Q3 [6 n  O$ ]  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off* x8 b9 {2 C+ e) N: P; h1 o7 z
    (command "_.undo" "_auto" "_off")  L5 G# j. v  Z: G1 L
  )
1 I- o( T/ T% V) M9 U4 u& Y
# c% R: x1 G8 H2 Y7 D' c  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
7 B( n" `. h; U6 n2 [( u    (command "_.undo" "_end")& R! V5 \9 m4 c) [
  ). P1 a% ?' |, j
/ [* _9 u; N" x! G9 D. D3 N# @
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
8 E/ c; d, H  Q3 V' ]& @6 X    (command "_.undo" "_group")- m" K) q. w% d& z2 k* _
  )1 `1 `# y0 ]! Y

6 R9 C; p3 k) P  (setvar "CMDECHO" cmdecho)) ~2 J4 Q+ V/ D# a6 @1 J9 K
  undo_ctl9 J. H4 Z' F' D3 T$ p: N9 F8 p
); defun undo_init+ \8 m, f/ T- t3 r# V$ u9 d
( e1 F1 C: g8 a2 J' Z* V
;----------------------------------------------------------------------------! `5 @+ h/ k( v. M3 c6 s/ h
; Restore UNDO status! @  r9 P0 h; H; H# Z
;----------------------------------------------------------------------------6 H1 V: Q) y& B
(defun undo_restore (/ cmdecho)+ A5 [  F' ~( q; T
  (if old_undoctl
3 u/ {7 ~5 @, d1 t    (progn
# N6 a, P" Q  |. z. L2 M  u      (setq cmdecho (getvar "CMDECHO"))
$ D1 c. d0 i; ]+ D) k& ^3 T      (setvar "CMDECHO" 0)) H  H: S4 I1 M* ?" t+ [. D* s
0 d: y$ O6 l7 c: ~$ T1 W
      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
+ Q* U2 k9 ~7 f, a, q+ i      (while (equal 8 (logand 8 (getvar "UNDOCTL")))4 t" Y: ]" l' T! A  E
        (command "_.undo" "_end")& |! C" N1 Z1 M+ x7 w
      ); while* |+ L- |, z& F, ~. ?
$ b$ |9 j4 p* M# z$ m% X
6 Q6 B; p/ ^2 d8 u/ f6 ~% y  ]! E
      (if (not (equal old_undoctl (getvar "UNDOCTL")))
5 k: s+ {) h. f# |+ V7 a        (progn1 x5 K* ^6 |( M% w3 g- J
          (cond* ^6 o* g0 @% I8 a( K/ L0 b
            ((equal 0 old_undoctl)) s: }' h: g' _$ h
              (command "_.undo" "_control" "_none")3 a& [6 k. F1 I* H1 q
            )
' j+ V" H$ e; U( e% W            ((equal 2 (logand 2 old_undoctl))
" `! o/ q% c& v, ?              (command "_.undo" "_control" "_one")
9 E/ e" {6 j% n% B8 u            )
2 N6 i' ~2 E* @" ^3 Y          )$ W2 F8 N) g+ v
          (if (equal 4 (logand 4 old_undoctl))
' ?$ C& g1 u+ C, ~' I% S              (command "_.undo" "_auto" "_on")
+ ]5 G' L3 c$ h              (command "_.undo" "_auto" "_off")5 w" T: x% @- w( {8 q) z, \
          ). B! I! B! f: H; Z( O, Q
        )
( |3 L" l. P) C6 x7 u( r      ): c6 s/ H1 ~3 \6 o: c) g
      (setq old_undoctl nil)
. _9 P7 |/ S) \9 M9 ^7 Z      (setvar "CMDECHO" cmdecho)
8 u' D2 |; u/ t+ s! r/ ]: R7 q    )
# u, r% e+ x" P9 d6 s; M: s' G7 Z* ?  )8 k2 {3 h) y& B( b2 d
); defun undo_restore6 _9 A( P6 S" ~" d4 B+ E1 W* Y

$ p' v" \3 d+ E) J( [1 R;----------------------------------------------------------------------------
9 t" P: P/ s# X; Save variables6 z; |) t0 T2 u% y& a- U/ f
;----------------------------------------------------------------------------5 l/ g' E% e) E1 i) W  m* `9 J
(defun var_save (a)5 S; a3 b4 w7 r, s
  (setq m_lst '())
7 \; N  P/ J) `5 f; w2 Y  (repeat (length a)) K1 W% }/ p0 ^, V3 y* T
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
8 K$ w1 y( W6 }" g8 q! t- U# \    (setq a (cdr a)); n0 y& s" b0 W+ d5 w0 i4 z& _# U4 T
  ), u8 w" d' n' [% o; l9 f, c
); defun var_save
; g9 V6 p) v- j$ D3 P  B% D5 D. m# @* k5 v$ B6 [. f: a; \4 w
;----------------------------------------------------------------------------
3 c% K' L% U( ~3 w% q% t; Set variables: o. C1 @+ W  f, G
;----------------------------------------------------------------------------
% f' [0 z) L6 q, W6 g; K(defun var_set (m_lst)
% x4 _# r( c9 K( g& `# @  (repeat (length m_lst)+ z1 [; F9 D& p' O
    (setvar (caar m_lst) (cadar m_lst))
+ }, y! {! j, e/ \  c" _# u    (setq m_lst (cdr m_lst))8 ^1 X- J" L- ]
  ). @" L1 Y2 P0 y7 Z6 G5 B3 Y" z
); defun var_set: R3 ~( d, P! r) B

/ L) N7 g# _! o8 K1 D5 T  P;----------------------------------------------------------------------------8 P8 L6 i' u) N6 }3 X  v3 R6 m
; Restore variables2 V5 C) Q0 e( N& J* [6 b
;----------------------------------------------------------------------------3 J( z' B' @' V+ H  Q% S& g
(defun var_restore (): g; v" h( f' y
  (repeat (length m_lst)6 q/ Q4 w! K1 c9 z; S' e8 k" B5 M
    (setvar (caar m_lst) (cadar m_lst))
6 e" o( P! i; _( E, \) t2 H    (setq m_lst (cdr m_lst))
+ y" J7 F8 N9 K" C5 y  )
8 d5 D1 m; U/ b, x8 D$ M- B); defun var_restore4 b$ o0 j' B2 u( e# d7 D$ j- A$ e

; X# ^' a5 J% \3 s& B8 P8 P0 Z8 t;----------------------------------------------------------------------------
6 W4 U, m. f4 S/ h" q; Initialize routine 0 p' S& x+ [- ^: k) E
;----------------------------------------------------------------------------7 z' n5 p! \/ f! `! X
(defun err_init(e_lst u_enable add_fun)8 Q4 m6 {- z$ e8 g: n
  (if err_alive (err_restore))          ; To avoid nested call
$ M  g, T9 Q4 c- A; K) G  (setq err_alive T)  r( V2 K) T8 _7 G
  (var_save e_lst)                      ; Save the modes2 M. n- R9 e; k. `6 `
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status" I8 [) d) C1 ^" X
  (setq err_old *error* *error* err_main) ; Save the handle of *error*
% z( ^6 C; f& t6 \. `) I, }  (if add_fun                           ; Add the user cleaner1 J7 D; L/ E  S& F( p
    (setq *error* (append (reverse (cdr (reverse *error*)))
/ r! {: O! S+ j+ k' h                          (list add_fun (last *error*))8 ]  F4 p+ Y8 `+ C# D. Y
                  ); append; Z1 {  k0 @5 E! j, L/ h3 k
    )( S6 r/ I' @3 Z1 _
  )
2 P/ e" ]+ P) J- _); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
! i4 a/ B  C& {. `$ n; Error routine body6 x8 b- _$ m6 R$ Y9 x! q1 Z% |
;----------------------------------------------------------------------------! M5 w/ i: o  {; P5 E) ?
(defun err_main( msg / )                ; Body of error routine
& X1 d6 z) l5 ]% K5 `: H6 d3 ~  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs
6 o, z8 d: d3 I6 j) P- {    (princ (strcat "\nError: " s))      ;while this command is active...
- ]8 i% X0 w( M* T- x  )8 }+ M1 m' n6 M% L0 F/ L
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
5 b9 b% x- e# S- ^8 e: d; e& t1 l5 f2 I
  (if old_undoctl& ?, Q5 B$ p& a
    (progn
! T! R' F' I6 Q) n8 [      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See# h* U, y: u. V; o7 }" p" v# O
        (command "_.undo")              ; if it's in UNOD command% @- ]: f: ?) \' R- R
      )6 B1 R/ Y" }0 n6 K& }2 f4 F. e' Z4 ^
      (command "_end")
1 p5 K* m& V% A0 N, y! }      (command "_.undo" "1")% w& r* q: R6 w5 l% F
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))* y' v) Y* T% ^1 R! _5 N' K
      (undo_restore)                    ; Restore the status of UNDO) F7 z  }' {" F# m5 D: R
    )
  ~/ u& ?+ {% P) F1 S4 R& t  )
) E* c6 z$ i7 q4 x- a4 m3 w! R, ^0 t) C
  (var_restore)                         ; Restore the variables% R* g$ t5 n3 P' ]5 Y6 Z
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
  c$ Y5 d' _7 n- w  (setq err_alive nil)! O3 M" r" c: P$ m
  (princ)! q7 s% T1 K' Q9 \9 A6 t
); defun err_main: M. t5 O& ^$ V3 l) H

: I0 q5 h, g! q% C4 C;----------------------------------------------------------------------------
8 g4 g9 A& D! G2 l+ k; Restore error status7 V4 c  _5 p6 S9 z8 I
;----------------------------------------------------------------------------+ R9 k: V/ T2 l; H
(defun err_restore()
& B( @+ }1 c( b" D! K$ R  r  (undo_restore)                        ; Restore the status of UNDO
- w$ V3 q0 t% ~2 ]1 t5 n  (var_restore)                         ; Restore the variables1 P; d+ ]8 Y- M5 B0 M6 e
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error- w( W$ U  U' q) h
  (setq err_alive nil)5 a) t( x# o, Z7 b5 m, W5 m9 p
  (princ)7 l8 T2 E, l$ c  }! |
); 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-9-5 12:15

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

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

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