CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
5 L0 x- M" r) Q* @; V1 | “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”+ T/ E: B& w/ s& W% C1 ~5 Q
提示:加载成功3 _, B- A: j; Z2 [
然后使用CLOUD命令,
, [' ?6 C5 E8 Z) q( N- O3 n( H$ d提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
+ ]$ s5 q2 ^6 h8 I* C请高手指点一下,这个是怎么回事?应该怎么改正?! x* I! d/ V7 J# Q7 g
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx
  R' M4 r  x- V2 n+ f;;;
0 W  ^, y0 r% z5 |+ W. `2 p/ V0 P;;;  DESCRIPTION. D/ L2 _# E6 V& Q
;;;     Draw cloud and you can specify the globals variables listed below4 ]5 A# [, q: Q, P* ?
;;;     to decide the characters of cloud/ e. _  p% n; @
;;;' A" T# Y9 w- Z5 \7 r
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/987 Z  R* B: }! h& q* z
;;;6 K2 |. b* q# O
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed1 ^) p) M, _. A- @
;;;           Change CLOUD.001 to use CLAYER to perform the same function. }, b7 ?1 c- n/ G9 D- q* n2 S
;;;           Use the common error routine UNDO.LSP to optimize this program2 k4 |! P3 ]1 h( H+ h' R6 S
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
$ I7 ]  U" j7 y0 x+ a: [3 |;----------------------------------------------------------------------------
: U5 P( U; p: e;  GLOBALS:
8 S" p( [7 q3 R9 c% A;     cloud_layer -- layer of cloud
$ U$ o5 p, \. h% U& Z5 `% k6 c;     cloud_scale -- scale of cloud
7 s, l3 \5 M: s;     number_rev  -- revision number
3 y& \& c1 k$ a: P6 |;----------------------------------------------------------------------------+ T) ?% {1 m5 U4 Q% P6 _
(defun cloud (/ locked temp first_point next_point relative_point8 r0 E, Z6 A* k# n  Y
               last_point point_tri point_ref corner_1st corner_2nd length_tri
/ k3 q9 {6 q" u) N               length_cloud angle_l_to_f dir_tri repeat_count $ T# w. \( W# s6 H! X7 L1 L
               table_cloud )
- _! L5 z/ x* Y$ E' T' R7 v. I        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))
- r4 l9 S# y: ?          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))* V  ?6 H3 C# T$ `! H
        );if; W) Q/ Q# Z! w
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
# Q* h2 ~4 I4 a+ Q# ^1 j                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
6 L2 z6 O$ g8 G5 A" m3 N        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
" \/ o! _# M' \( G$ s, x' c' `8 N1 ]                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))! B' P7 z/ ]1 c$ T

) N& @* P1 _/ a+ a$ R7 C8 Z        (if (not (numberp cloud_scale)); h4 C/ Q. K5 Z# ^9 i7 Q. M
            (setq cloud_scale (getvar "LTSCALE"))% A5 i$ I& L  P* e) V' X2 j
        ); if
/ j9 Z" |* D" E0 L6 v$ n1 t0 G        (if (not cloud_layer)0 Z* d9 u1 C- ]1 K, w7 S/ l3 S
            (setq cloud_layer (getvar "CLAYER"))
- t& k# i- V3 g, K, Y) o. R        ); if
, }  |; J5 h+ n: |* Z        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))4 X$ N4 g( E" O! L) |7 T
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
* F4 n9 g8 z1 k/ V: P- c        (if (= (cdar (laychk cloud_layer)) "No")
7 Y' k0 f: W* w1 _0 |- _( o3 F          (progn! a. q1 p+ p$ _1 c" t8 r3 a
            (laychk (setq cloud_layer (getvar "CLAYER")))7 ~$ V: m; C. B8 `: u+ D
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
5 J( ^$ B' i7 v) {  y" F' X. {          ); progn# H. n6 ~) p. g: o: A
        ); if
3 t, ^8 }3 j' A: S& |( s- K7 P7 U( W8 M- W/ W
        (while (/= (type first_point) 'LIST)
5 F. I, C  B% A: b( }          (initget 1 "Layer Scale")
. z! L& X: @7 e( y; Q5 H" m( q          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
" u6 N/ s  z) ]& j2 O1 d( h$ Y          (if (= "Scale" first_point)      
5 r5 F# D9 u+ z+ Z9 o, A4 M8 d" P            (progn
; v8 |! V( Q0 D. X  a              (setq temp cloud_scale)
$ D7 K) J" }" Z+ N# g4 g/ ]              (initget 6)
6 V3 y& `% v% o  Y1 J" v. y              (cond
7 ^0 a# ~# A9 O1 Z9 X; y  o( v- H3 f, [  B                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
6 X2 p8 f7 z: q" [% n5 J                                                          (rtos cloud_scale 2 2)/ d* b. I8 {9 g
                                                          "> "))))
/ b* R6 l; i2 K2 L                  (setq cloud_scale temp) )
  I: K) G, @4 Q6 x: x3 D" u  \              ); cond" i; Y, M9 ^5 \+ Y" p; {
            ); progn
+ Z* m( T3 P( a! j% u# j1 `: ~          ); if! t! d4 E" Y* O9 G, ?( ~
          (if (= "Layer" first_point)
) P5 o) B( @9 j0 W  u- l% m8 _& q            (progn
6 I. e( |1 O( d& Z$ N              (setq temp cloud_layer)7 |( C% V" B0 ]% O3 }1 p2 W" Y4 [
              (cond& m( e0 q! ?$ I4 S
                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"& [/ l, H+ T0 Z- i1 h8 D2 Y& i, f
                                                          cloud_layer "> ")))
" m. l0 @1 N7 x. ?3 M- F" n8 V, `                     "")
( l8 _! q! d+ D7 ?  k; X                  (setq cloud_layer temp)* @4 c4 J+ k2 u& y8 m
                )
- a! K+ j5 Z! ]4 B; s              ); cond
# G2 P' s5 }& ], s1 z6 z' z8 v% R& n              (if (= (cdar (laychk cloud_layer )) "No")% @9 |4 ~2 f9 @, |! V! [  c* K
                (progn
  d: g& _1 B# q5 K, C- o2 w$ m( B                  (setq cloud_layer temp)
# Y0 c" }& F% @) g4 x, v" D                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))" C: ]$ j3 H; U& A/ M& U+ G/ y
                ); progn2 E+ U; }, W1 T6 k0 g
              ); if1 Y- [, {" B/ c+ ^5 J$ t
            ); progn
% w/ s) _$ Z" G; _  X          ); if
% l1 `# J' |% K6 {. P! @6 l2 o; q        ); while$ Y: e" D; |  p1 ?
        (setvar "CLAYER" cloud_layer)
9 K$ B3 Q$ g7 U6 `! M' w2 B8 S; Z" W' Z, L) V% q
        (if (>= ( getvar "LUNITS") 3), ]) l" N, Z/ f/ Y, N' I2 g) o- w
          (setq length_cloud (* 0.25 cloud_scale)7 y0 ~3 h% R3 t" l. \
                length_tri (* 0.3125 (getvar "LTSCALE")))' U$ V8 f' q. V+ e
          (setq length_cloud (* 0.3406890 cloud_scale)
% K0 ?; z, g0 e* ]& O& t                length_tri (* 0.438366 (getvar "LTSCALE")))0 C, W5 ]% q3 I9 y2 Q2 L1 s8 z
        )
! ~! \. n* E! O5 ?0 w        (command "_.PLINE" first_point "A")
* k7 O8 K& `! Q7 a# Y/ F: ]4 U        (while (not (equal next_point first_point 0.000001))
. q6 ]. ]3 N0 |1 N          (initget  "Close")
- E8 y9 X5 p& U2 q5 V          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
$ c* k2 S: T, @        (while (and (not (listp next_point)) (/= next_point "Close"))- B; T; N3 h0 e. O
          (initget  "Close")
5 q* \1 H7 ^8 \+ |; d          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
! N2 [& [  }- u3 j        )
5 ^% _8 P0 V# W# d          (if (= "Close" next_point) (setq next_point first_point))9 W- a( o! M9 o, k* A
          (setq angle_l_to_f (angtos (angle last_point next_point))2 }: H3 E, |1 V+ F9 v9 }
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))3 z) T% W: {# u. B7 h* o
          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)8 [. G% U) j. o* y
             (setq repeat_count 0)
7 m  z. g9 d+ O6 N5 _1 C             (if (>= (- repeat_count (fix repeat_count)) 0.5)- K7 m7 f* c. V% Z: }( H
               (setq repeat_count (fix repeat_count))9 G3 w: p' |% h7 q. }% B
               (setq repeat_count (1- (fix repeat_count)))
$ U6 g4 I. C+ i5 S: H3 a             ); if
, f% o2 b6 {6 H; P6 _          ); if
# e1 k7 w; t& k7 p* E7 l          (repeat repeat_count (command "A" "-100" relative_point))( V1 A0 ?5 k6 M8 L( T/ w
          (command "A" "-100" next_point), ?' g! @3 z' \$ y3 c
          (setq last_point next_point)6 _9 [. t5 Z- i  {9 Z( p+ N5 S
        )2 x' y' z5 O. u7 o4 f
        (command "")
6 j9 V- `  u6 |$ B5 W* ]! U( v/ F* M        (if (= (type number_rev) 'INT)
6 ~7 [- E5 d( Q: I6 V) E! Y8 Y; N           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。")): C: D6 w3 U/ f- S3 ~: j8 ?' N
           (progn5 j+ m) T: [" V+ }
             (initget 5)
; }0 \7 U, z" |, l; x             (setq number_rev (getint "\n请输入版本号:"))1 l* t; }/ p0 e4 u$ f! t
           ), `: l" J& J5 V+ N" O' {' N
        ); if
2 f8 A5 l2 I5 ^1 C8 J4 R# A        (setvar "OSMODE" 512)6 B$ N4 n0 ~  Z/ T' [6 ]1 K3 d$ P
        (while (/= (type point_tri) 'LIST)( k* ?/ i$ [5 w. W
          (initget "Number")8 m( B  X# M; x9 T+ O8 s0 [
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))9 K, N0 _6 n/ V  H5 m2 C
          (if (= point_tri "Number")( N5 o# ~2 ?# U: _6 ]% }* @; p! y
              (progn
: G, c" ^  t5 I- |                (initget 4)
6 L; C0 `/ F- Z# V: G6 h7 G                (cond
& m# g5 r- x/ H2 Q) l9 y* x# Q                  ( (not (setq temp number_rev 1 b0 W& Z6 b6 n# `) s- W
                               number_rev
' h4 e, }1 g: b5 P                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
/ C* I2 A! ]& d* ~+ Z                    (setq number_rev temp)
( n- C4 q: l1 i                  )7 h# d( d. @) G' {7 N
                ); cond
7 I( q3 v2 J# f- b              ); progn2 h1 P' n  w9 S% @" b
          ); if
0 O6 ^7 F9 I9 o6 C0 Z        ); while: ?, q. s7 [( x8 Y
        (setvar "OSMODE" 0)
4 j  K  z  y! U% `) Z8 z        (initget 1), k4 ]% c6 d% q1 }! `( F. V& @. ]
        (setq point_ref (getpoint point_tri "\n请选择方向:"))5 r; s) L1 e4 O% p
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))
# x6 [+ Y" f, z2 @        (setq corner_1st (polar point_tri
+ L! m: {% _8 _' U7 p/ G6 C                                (+ 1.570796327 (* -1.570796327 dir_tri))( ?+ p6 e* J# v* u1 B
                                length_tri8 N# ~& u7 E2 k/ P/ S
                         )
) _/ |! U/ Q: i        )
7 b; S+ _2 Z6 n, B% n; q' N        (setq corner_2nd (polar point_tri; [1 g/ A' j; a  {  C
                                (+ 1.570796327 (* -0.523598775 dir_tri))
, E, `) W3 d( V$ a- K                                length_tri+ O8 [8 c1 O/ N8 i2 F
                         )
, ^, ~8 r. k! \0 q        )8 Q8 F4 ^5 A* L7 D/ h) A
        (setvar "CECOLOR" "2")& y' [' m1 w' z, W. T0 b0 W
        (command "_.pline" point_tri corner_1st corner_2nd "c" )6 P9 X# u" W2 d  S+ c/ S8 T
        (setq textstyle (getvar "TEXTSTYLE"))
% w$ E) k) `$ }! M5 V. r- j* y        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
+ T' Z' Y" W- T; l" J        (setvar "CECOLOR" "7")5 a5 [  J& J6 k
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))! C# F/ V& S7 g6 p
                  (* 0.4 length_tri) "0" (itoa number_rev))
# h) }( K  o  C        (layres)
% ]8 Q& J9 f8 A. s( D/ u6 u        (err_restore)( r; Q9 |1 `( z, Y7 W
        (princ)+ f. V& C# S  n* O6 v4 n
); defun cloud1 Q7 K% t. B+ V. {: G

: c+ X# G4 \4 c(defun c:cloud () (cloud))
9 @, J9 Q9 f4 T$ J/ |2 L(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy$ b9 B& k! p! O6 V% `
;;;! I! `6 S% z6 {0 I, w' J
;;;  DESCRIPTION; D4 \% H" u/ m' D2 Q* b- l$ V
;;;     These are general error routines which can be called by
9 q& L5 K: W4 M* i# a;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference9 `. K2 I# f2 n+ Z0 B
;;;
0 q2 L4 ]0 b8 {, b;;;  SUBROUTINE INCLUDED IN THIS FILE* X8 C: t8 ~, v
;;;     UNDO_INIT
8 ]2 n7 [3 L: n! c6 V& m, k8 l- E: G;;;     UNDO_RESTORE9 {. }4 t  z' P2 V
;;;     VAR_SAVE
1 D! s. V8 C8 e  J, j/ q) P;;;     VAR_SET  7 _9 x- F9 S7 |( C" u
;;;     VAR_RESTORE* Q( q9 B& K. X
;;;     ERR_INIT
9 T( `: U, N' ^7 P& W;;;     ERR_MAIN 0 n0 @+ a0 H) M# F) `) P; @4 G
;;;     ERR_RESTORE
" A, v5 y. U1 V' ];;;' v; h2 g7 I- u0 m
;;;  DATE: 10/17/98; 03/31/998 I7 s9 l: q+ y( r
;;;
$ W, y: K" }7 |% K9 `! X;;;  HISTORY:
" [9 M, K9 Y3 h% v" }. i;;;    Add routine of mod_att
1 \  e3 ^$ M$ Y& ^9 n5 j;;;
) o+ d- s  a. ], b0 j, T: k+ J- A+ K;;;  USING METHOD  S. P5 C4 T! o- B0 [. y6 T# \6 }
;;;    ERR_INIT:
; u% a% T% o. S4 h! R;;;      This routine initialzes the error handler. It should be called as:
: a1 Z+ E  A% R9 o;;;
# a1 V; [; ^# J4 I" b;;;      (if (and (not undo_init)& s, y1 [' N& d1 X  G! L$ R) ^' Q
;;;               (equal -1 (load "undo.lsp"  -1))
$ u" c/ M+ D; p7 p+ V( P;;;          );and) P; p4 |. h' a% \# M$ o5 T
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
+ C: _. D5 B( s, B) x" W7 Q; L;;;      ); if
* ?5 j0 @7 K5 I;;;
: g& E4 ?  K9 H- a1 \8 l: c# y5 W;;;     ARGUMENTS:
5 i& F# E" O- K! x6 M2 ]9 B;;;       err_init Takes 3 arguments. " k6 a& W* V6 C0 w' U
;;;     1. - The first element of the argument:
$ O9 D" T; [( r3 @4 D;;;          This is a list of system variables paired with
: Q& J3 `9 x4 S1 p/ a6 E;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
6 i1 J" b" Q( I  F4 `1 p;;;     2. - The second element is a flag
4 Y( ^4 F# \7 O( L9 A;;;          If it is true, then in the event of an error 4 w, N7 ]* |; w4 J
;;;          the custom *error* routine will utilize UNDO 4 `1 J* |6 ^2 T9 K5 s2 z. U/ S
;;;          as a cleanup mechanism.9 Q3 C" H: p* q) H' F3 S, B
;;;     3. - The third element is a quoted function call.
4 ]1 \$ e; U9 i$ r; D0 Z1 |;;;          You pass a quoted call to the function you
: z; U7 T! @6 n$ L5 Q;;;          wish to execute at the end of nomal routine if an error occurs. * u, Z; H1 r- w: L) _$ o
;;;          i.e. '(my_special_stuff arg1 arg2...)6 t$ j% T# q/ M& J. X% e
;;;          Use this arg if you want to do some specialized clean up - D7 Q( A/ b5 w: P" o# ?7 v4 c, _
;;;          things that are not already done by the standard bonus_error ( H) L# ~& V+ x, F
;;;          function.
" g7 q0 ?8 T# [;;;  i5 |' ~) b; [7 l
;;;    ERR_MAIN: Body of error routine1 `  r1 T+ ~- ]4 N7 g0 ]/ e' K; I/ M
;;;
- h2 |% [2 ~7 ^- Z;;;    ERR_RESTORE: This routine should be called at the end of command to/ F" W8 H  M1 G  U3 v
;;;           restore the VARIABLES, UNDO & *error*.
+ `7 E/ @0 V4 Y) |0 [: y3 q;;;# ?1 z) r% c! V- B
;;;    UNDO_INIT: Initialize the UNDO status
: L+ \, Y) U6 q) V! L$ ]$ q% x# k;;;3 L+ R* s, T* c# i" y! T
;;;    UNDO_RESTORE: Restore the UNDO status1 u* G" C% e# l7 a3 J& t
;;;
+ D4 j* K' X$ T. [% \- N;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")3 s& i5 J& K1 H0 A8 N& I% c
;;;6 z( ~& z9 ]7 C- z8 }1 v8 C. {4 m4 l1 F
;;;    UNDO_set: Set the variables. the argument is like
; @/ a9 S: q* G& A- v;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
$ s9 b; r$ ]( {$ P6 V% [2 v/ I;;;+ O# N$ H: m" O% g
;;;    UNDO_RESTORE: Restore the variables* n2 S: u3 G' Z
;;;
4 M, P, z: v! |7 {8 c( d1 a$ S;----------------------------------------------------------------------------
! r/ Q( H5 w/ L;  GLOBALS:
0 d2 u! e5 g: O. A/ o/ q) X7 K;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
7 t$ F0 Y5 n/ H- D* _. U5 h7 t;     m_lst       -- list of variables (voided by VAR_RESTORE)
, s* k; F! ~, U9 g# V9 B;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or
8 |8 W+ {% o% N  P;                    ERR_OLD)
2 E# j, \4 N6 z% Q" t' k6 ?;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)* O( F1 ^) B+ ]( P0 _
;----------------------------------------------------------------------------
; n0 k0 ?9 p+ C1 D, f" d8 I: P. u6 C' M7 B7 S; r
;----------------------------------------------------------------------------7 q/ {/ Z3 F' W- W3 K4 W8 X3 y
; Modify attributes according to entity name, attribute name, dxf_item9 q* Q. @" V4 W0 m
;----------------------------------------------------------------------------
0 K- p% T% L6 p" o: m, M(defun mod_att(ent id dxf_item)        
5 W/ E2 N$ D' y2 @  a" D9 {: l  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
8 J/ [+ G: A  d- c! ^  u' U    (setq ent (entnext ent))
# P/ |; T- Y+ b: k0 w3 N) l  ); while  
1 L; ^# M8 I4 N! k4 _  ((lambda (x)
% [" D3 ]$ r0 x* i3 r  l        (mapcar '(lambda (y)* X+ K( ]( c& c2 L* i. g; t
                   (setq x (subst y (assoc (car y) x) x))0 o. n6 Q9 I- t7 x' y, D. k; }0 e! D
                 ); lambda! J: G. |5 u1 f5 C* U4 J1 b
                 dxf_item2 u: j8 n  X$ @( a; M+ T* F4 D
        ); mapcar
# \9 v9 ?5 N' d2 }3 w2 {$ m5 X0 Z2 @     (entmod x)% L# v0 V! J* M( o% j. r3 m
     (entupd ent)
5 x6 z! j7 M/ z/ v- }   ); lambda  A9 z: r( P/ J2 u
   (entget ent)+ E$ R) N  Q& n' m  [# C$ P$ ?" P
)
( S8 W3 E% ~. P" K5 _' g2 [); defun mod_att) _4 m( L8 {* i5 p, O8 Z

* w1 A& j6 j! t4 U9 N' R;----------------------------------------------------------------------------
# y3 ?- H( o0 V( ^; Check layer status, return a association list which contains layer information
& ~) ]1 _/ _: [- A6 a;----------------------------------------------------------------------------, I# w8 V4 g* `- Y* m
(defun laychk(lay / l_sta)/ m; P/ o* ?1 C/ u7 `1 H" a; b" b
  ( (lambda (x)
7 o5 S" `4 N- B2 o) H9 K9 q( i6 z4 j      (if (not l_s)
; R% L0 c# a9 `$ N4 x& c1 b          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
) h/ Z# A. ?+ ^5 h) R( Q; o      ); if
( \  S9 S; l$ i" o! ^2 |    ); lambda
! |( g& ~* @, Q: y# F, F    (getvar "CLAYER")
5 m9 y9 x$ Z' c6 _( u  a$ D+ i  )4 {) `/ \: ^% \1 h# G
  (if (not (tblsearch "LAYER" lay))
( H9 [9 q1 p$ ^    (progn  ) r( S2 {% ~% U9 Z- h$ t
      (initget "Yes No")
& ?4 A+ Z  d( Y! v      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")  p# y) @: Z. x* E: d
        (progn
& u" S) D1 F& n8 m7 E5 A          (command "_.layer" "n" lay "")8 |8 ]! M% R! U8 m8 B3 K4 ~1 i
          (setq l_sta 0)
0 W2 V( D6 R) z- _1 e1 i2 U        ); progn
+ T0 p1 Z; y) E  {$ N      ); if/ d4 x9 o8 N+ `9 C' }: o: F
    ); progn
. d! x, A- Y/ R3 f* H2 j( k    (progn# ]3 d* T# u8 H6 N
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
- V+ ]: R: J3 A5 `0 V1 N      (if (= 1 (logand 1 l_sta))
& a- h" `2 c. F4 E4 d" n: `$ v          (progn
7 |% ]( T' V# T% Q            (initget "Yes No")( H- M# r. A1 A) e* Q- k/ q# c
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")' E2 z! z  x  S; i
              (command "_.layer" "t" lay "")9 Y4 @: w- Z0 U+ q
              (setq l_sta "No")
9 S- j5 T8 B; }0 u, U" Q2 Z" ~             ); if
) _4 ^# Z& n0 P+ ~- Q8 P          ); progn8 ~2 d" k! z4 q! A
      ); if
4 y6 r4 A. w' Q      (if (numberp l_sta)
3 X" j, Y4 H, A* f        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if9 _4 c, ^! k2 U! ~
      ); if3 S, |; p2 t7 I
    ); progn& R2 N! E% U: y" T( c
  ); if
9 D  q/ h; \  Z* p" N  ( (lambda (x)# c, Q/ v  ?7 {) A  N: n1 {
      (cond
& [' ?: b3 W  y, t2 T        ( (not x)  p- l  q0 P* N0 J
          (setq l_s (cons (cons lay l_sta) l_s))
. i0 V3 o' f4 ^! O' G  k        )
  Y2 v/ r7 W. \; `  l7 V4 Q7 T        ( (= "No" (cdr x))& t& t; B$ a/ S* R- \" s3 M
          (setq l_s (subst (cons lay l_sta) x l_s))
9 z% ]9 m; h) B' G* E  }        )
6 M3 \. v9 D) O# }        ( T l_s)
1 M. M- Z$ r1 Y: P/ P      ); cond
1 Z3 U9 [6 n  T2 \! _# Y$ S     ); lambda2 U. t* r; h* a* A
     (assoc lay l_s)
0 f3 `* B' a. R) g5 o" p2 t7 B; d  )
6 ^0 D4 \0 U- d% s* c5 o7 |6 x6 z3 E  }
); defun chklay$ B7 J# B& b( t$ g

0 w# e7 t/ I0 E;----------------------------------------------------------------------------& u0 H% r+ R0 J
; Restore layer status according to association list l_s
( }: R+ G1 I$ {4 ~3 W- E;----------------------------------------------------------------------------
+ q! Z9 D" I  O. T* p  g(defun layres()
4 ^8 {& E" I) ?; o# Z  (setvar "CLAYER" (car (last l_s))); L6 d7 [) l6 W4 u
  (repeat (length l_s)4 K# M4 f* a3 t$ K
    ( (lambda(x)  
% X5 H" b- m0 P% k3 ]        (if (numberp (cdr x))
1 G, K1 Y4 {. |2 {; w, p          (progn
8 o2 S* Y6 P* n/ S( x            (if (= 4 (logand 4 (cdr x)))) W4 g& [: [" a
              (command "_.layer" "lo" (car x) "")
# T3 Y* e. ^! z. o8 h            ); if
2 `4 N* R& A, g/ z! Y: V            (if (= 1 (logand 1 (cdr x)))
$ t9 u0 u. J3 q) p3 y7 B' I              (command "_.layer" "f" (car x) "")3 c/ F- z8 q! Z0 F$ ]
            ); if' S( P- ~( v" P  f
          ); progn
. o% z% f5 ^3 \+ S# I       ); if  . p, K* v1 U/ R
      ); lambda
# D9 ?9 M* _. p      (car l_s)
6 o% C, V+ R: z& U% C& }    )( K1 i* f4 g  r5 @& d* `1 b; j+ q& R
    (setq l_s (cdr l_s))
# p8 `2 ?# P" G: l1 d( y  Q  ); repeat
% b2 C) l+ {$ D0 X; A); layres  W+ V, {# n$ m2 Z2 x
5 Z; @3 u9 M2 {, I
;----------------------------------------------------------------------------6 j! L. u/ k- R0 G; s8 |
; Get DXF codes$ q* q/ X$ _5 C
;----------------------------------------------------------------------------
( d# t; n  \; ?! g# s5 k0 F  k(defun entgetf (index ent)
9 [: h1 r- k. j% s1 z2 R3 B  ((lambda (e)
5 q+ O$ r8 F3 }* z( |6 o      (mapcar '(lambda (x)
$ @$ Q5 t. q, Q: o                 (cdr (assoc x e))3 e9 ]" d/ q) y, a0 X6 M  J
               ); lambda$ h! {2 R$ ]& w% m) W: y2 k+ R
               index) ; internal lambda function
% j6 ]4 k# @) R( S    ); lambda
4 j+ A2 j4 k  V* W( U* O    (entget ent)
) r/ E1 P" @6 b2 }9 q7 \; y  )
5 N1 x6 b9 p: J' C); defun entgetf
, Y( L. a4 R) @( C  h
# Z2 ^8 D2 W! S+ l/ l& V- z;----------------------------------------------------------------------------
- ~9 {2 F& i2 a4 p4 h; Save UNDO status- @1 q) p; N+ z5 h9 G
;----------------------------------------------------------------------------& L/ W' d2 A2 Z0 b9 ?" E$ k
(defun undo_init (/ cmdecho undo_ctl)   
. J- B5 j0 C$ O( V  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
, {/ v8 |/ q. H; C$ h2 T% \/ O  (setvar "CMDECHO" 0)
# k' U% w1 K0 c2 [9 t1 q' W* f5 u5 X" m  H+ r
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable; f7 q+ q& e0 u0 G' C) M! m0 Q2 [
    (command "_.undo" "_all")
+ X* V% L# h( @% h- X    (command "_.undo" "_control" "_all")9 q( C: t4 V. t1 P8 g0 R
  )
0 X/ p' X. C# J# Y& Z6 q* _% B- |& X  z3 y' M* B' [
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off
0 H2 E' O9 `/ T% _. Q4 f3 g" e    (command "_.undo" "_auto" "_off")# Z0 \: W+ C; `3 p9 ^
  )
$ V" J/ {" E% B( [2 g
6 Q! f. O0 |7 o4 J% ?/ W  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
- o& Y/ ~! N9 G! ]1 o8 L    (command "_.undo" "_end")
( G, G% }9 p* F1 Q' H  )8 Q; t8 X  D5 c! q) M' G$ ]; |

7 r: `8 T  g: C$ G, F  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
  F$ w& J) Y* r2 Z% P5 \# c    (command "_.undo" "_group")
" \6 Q- r( \7 U5 m! i) Z* A& [. Y  )1 Y( w4 g- c0 b' ]3 M9 g8 C3 l

0 t0 w; y6 h' ?  (setvar "CMDECHO" cmdecho)
  l7 b: s7 ]3 \6 k7 D  undo_ctl
: o9 C! d( q2 e* W# m$ u2 h) k3 A); defun undo_init
$ a9 ~3 X) V6 v0 [
3 u3 V& x, M! E+ o  I0 Y;----------------------------------------------------------------------------% \! N( g! ^' a
; Restore UNDO status6 U1 `5 o# s2 Q  q+ ^" \- R4 H
;----------------------------------------------------------------------------: \( [5 R7 ]) O1 ]
(defun undo_restore (/ cmdecho)1 i. T- ?9 M! k+ |% F0 T# k
  (if old_undoctl
' X/ U: V4 ], e* {# H    (progn
0 D/ ?* P+ p6 c8 @7 G' g; u      (setq cmdecho (getvar "CMDECHO"))# p9 J* M- [0 z" m3 `4 v
      (setvar "CMDECHO" 0)
& A5 g" M; P4 w- ~! n
& V: ~9 i: t% T, d- i      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
: b0 J& V, e. ?; c" W5 W" F      (while (equal 8 (logand 8 (getvar "UNDOCTL")))9 W0 A! I" z# e: X$ L0 j
        (command "_.undo" "_end")
+ A6 _0 a, R% r: _' s. S      ); while
" S  h/ O) e3 k) u% e: T+ c- m5 Y- R8 N* x4 M

2 j! U1 l* _. A- Z, p4 S) s      (if (not (equal old_undoctl (getvar "UNDOCTL")))! }" r+ O, Z4 [9 A1 D& F# C
        (progn8 F8 B5 {' a6 G% C
          (cond* I$ w  F$ O. X- L6 ^
            ((equal 0 old_undoctl)8 J* B  p/ }) N$ l: A  E
              (command "_.undo" "_control" "_none")% b7 Z6 ~" v  q0 h5 a! \
            )9 x, w0 ~9 w  K1 |, B
            ((equal 2 (logand 2 old_undoctl))
5 l) d/ v; a% B, [              (command "_.undo" "_control" "_one")8 @& n5 ~7 M0 y& _1 j- @7 g
            )+ F! h& {7 j. d9 d; o# P/ W4 `, E: W
          )# z) J# R# ~  b$ l+ T
          (if (equal 4 (logand 4 old_undoctl)): g0 a" }# v- V) K& A8 x1 k- r
              (command "_.undo" "_auto" "_on")1 Q0 O8 p7 B1 H- [9 T6 S, _7 b5 K
              (command "_.undo" "_auto" "_off"); x. Q0 ^0 f7 A. e" Z
          )
* }4 J' p. @( h2 V6 T        )' X. }. p- i* u. Z7 H- l6 q  }
      )6 b' R7 J' J/ G0 t) |
      (setq old_undoctl nil)
$ A2 o/ v  T' b% m      (setvar "CMDECHO" cmdecho)
5 B+ R4 ~: q4 S    )
8 J1 b) W' O* j4 W4 v/ j  )
( P8 k7 W3 M& H2 ~5 i( f" \); defun undo_restore
: [3 w- g7 g% q& t8 j4 D; x  s! i1 R2 ^
;----------------------------------------------------------------------------
3 k6 E  r3 Z+ C$ \* V+ m+ V. v; Save variables/ w. o& D  b: D) A0 d$ ]3 X) U( F+ Z" j
;----------------------------------------------------------------------------
2 U' w- S% Q8 ~, n) c! Z0 ^" \(defun var_save (a)
: @/ k$ D- ?$ F' v4 g1 l  (setq m_lst '())- Z7 \4 ?% l9 `; x: s
  (repeat (length a)
& H1 R" Q) q% }3 z$ r    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))/ e, K6 I8 |2 s9 O' `  B* S
    (setq a (cdr a))
- n4 A1 |& J; o* C) {" _" j  )' Y5 O% _$ b0 F/ H) |+ u' S: ~
); defun var_save
4 h3 ], L! s- B
- d& V+ a$ t+ s& l' @( @: H& x;----------------------------------------------------------------------------
, S& ^: T% ?; V0 i2 Y2 v, \8 o; Set variables9 y, h. t7 g& K5 g
;----------------------------------------------------------------------------
- O5 N1 p. \" y7 B1 t" N(defun var_set (m_lst)
* x3 U: q, Q; d9 G4 I( }  (repeat (length m_lst)7 d' f% a3 p" }  x9 I  G+ Z  ]+ d
    (setvar (caar m_lst) (cadar m_lst))
7 v# v5 h0 N1 q9 j    (setq m_lst (cdr m_lst))
3 y, B' w! s# c3 Y4 B' Z& U  ); s, m4 a( O6 w9 f3 l  P
); defun var_set5 ~  b: i! b- @' Y( ]
3 |7 E/ _, W! X: b
;----------------------------------------------------------------------------% v9 A5 a- Z1 f
; Restore variables# c3 T' r+ Y& C+ f
;----------------------------------------------------------------------------! |- h) _; c8 {+ A0 _+ L3 i
(defun var_restore ()
! b7 n% @+ s  _  v; x6 v  (repeat (length m_lst)
, y) l2 s' p+ }; O! h2 [    (setvar (caar m_lst) (cadar m_lst))% k3 s  {8 u) K
    (setq m_lst (cdr m_lst))
' v1 r! n" T. M) x  )
* g  C: E. o; C); defun var_restore
# y* ?! ?& s" q6 P6 X7 x' u
" g; V  B$ a( D5 O$ `0 }: I, T;----------------------------------------------------------------------------- l) ^% d! S1 Q6 o: N% y
; Initialize routine ( g0 ?+ B: \! O4 n' a/ U2 @
;----------------------------------------------------------------------------+ \2 \9 m- [5 p
(defun err_init(e_lst u_enable add_fun)
8 l& o. D; J9 b) ]  T2 B  (if err_alive (err_restore))          ; To avoid nested call5 w& ~) l* Q& y( Z' {$ D
  (setq err_alive T)$ ]2 w( \- L0 S# K3 d
  (var_save e_lst)                      ; Save the modes
. C4 f6 B7 j2 `  L* @) K  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status7 \* {: |' Z( n. T/ n( y
  (setq err_old *error* *error* err_main) ; Save the handle of *error*  Y8 N) F+ I4 \2 G& P
  (if add_fun                           ; Add the user cleaner
) @4 F* R# y+ {+ R1 e* R! B6 p3 i8 @    (setq *error* (append (reverse (cdr (reverse *error*)))
- ^1 |1 |2 U4 L9 ], Q; s% {                          (list add_fun (last *error*))9 y0 E( Y+ o+ a, c8 f
                  ); append
/ x: g& D. y) C+ z/ w( A6 @. G    )3 ]' n3 M* f2 G' @* _8 N
  )
0 S- S  I7 ?# s2 r); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------. H4 Z$ |! ~5 p  p, P/ ]
; Error routine body4 c7 S3 B) J) N) V
;----------------------------------------------------------------------------5 D. J) u5 p9 \) e, a% K
(defun err_main( msg / )                ; Body of error routine
3 L4 T7 v# h' n* U# b5 h- j  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs
, W# }' p/ h% a& q8 B    (princ (strcat "\nError: " s))      ;while this command is active...5 h, v- i! ^8 d: D( ^: z
  )
* S4 b: Z  O  i- O2 f1 f0 l% a  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
; H4 _/ g- {% g( s* r% a/ C1 \1 p( D$ ]' f
  (if old_undoctl9 G. }  f5 i8 z1 T( z8 [
    (progn
2 }: Z* E8 U+ B      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See( M: K) h* Y% y0 A+ ^
        (command "_.undo")              ; if it's in UNOD command
% s. f1 j# q$ M* _      )
/ F1 }2 ?7 R' V' z# o) A2 ^. Y6 ?      (command "_end")
8 D8 {6 Z% M! f$ Q8 k4 \0 W      (command "_.undo" "1")) _+ k3 R) q3 e6 K2 e' b
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
0 J1 Q* v3 R. d4 `      (undo_restore)                    ; Restore the status of UNDO
# R! J/ X3 J2 `. ?" M; F3 j4 N    )6 {' t8 a6 R' d8 d- t
  )4 j2 H  w9 `: B$ r; ?7 ^
3 p. o( s3 c0 V. k4 d4 J; L& O
  (var_restore)                         ; Restore the variables
" \/ s$ H9 u8 i9 O  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
! g* Y8 H& @: E" |  (setq err_alive nil)/ U3 H0 v, S8 B+ l  z
  (princ)" a9 Z- w* v' {: N$ H& o
); defun err_main1 q6 R* Y8 r9 ]$ i, d
; u3 \+ t6 c: _
;----------------------------------------------------------------------------
4 b- j( f! R( k! a+ T: C8 u; Restore error status9 T8 l& p8 l+ Y# `
;----------------------------------------------------------------------------
4 U! j2 C" a# r5 Y$ y) ](defun err_restore()8 A+ U+ @0 V: f  |, ]# h+ s$ R
  (undo_restore)                        ; Restore the status of UNDO* m: \$ l0 m. k1 a! @2 I( u
  (var_restore)                         ; Restore the variables+ w% s1 Y5 v2 i$ ^& m6 M! \
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error$ e% D" D1 G! @9 l$ r
  (setq err_alive nil)
* {( b( G" D8 u" D' N8 _! H  (princ)
9 d, U. h& M% o( i, a% i); 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-6-13 04:06

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

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

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