CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:" s' r3 j$ l9 E" g9 h- g! O. j1 y
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
. |. S! G) j4 O: e# G! n) \提示:加载成功; t: w: e8 v: f" C6 T& H3 n3 Y
然后使用CLOUD命令,
3 M( O. [; ^% m提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”0 p. i5 B! Q( J' H& d* b
请高手指点一下,这个是怎么回事?应该怎么改正?( Y# K, p  S4 f& p3 t" D+ D# O
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx! {* ]9 K( V6 t
;;;
( F! P6 b& ^1 e;;;  DESCRIPTION
8 H' F. j/ F8 I9 p;;;     Draw cloud and you can specify the globals variables listed below
! _; P' H- Y, M$ f* M;;;     to decide the characters of cloud
! n# a) y$ d" B( x;;;
( P# G, ?' L) y, P( M1 O;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/980 p: ^# N& q/ c8 R1 M+ U
;;;/ V  ]4 F9 R" S* C. e* I# P6 W$ K1 N
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed# L3 X* ]# y$ g4 T
;;;           Change CLOUD.001 to use CLAYER to perform the same function
" G$ j/ c# K1 F# D6 a) H- h;;;           Use the common error routine UNDO.LSP to optimize this program  P5 Y. G( d; ~* s1 _
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE6 q* |  k# Q9 O! m8 R" d( |
;----------------------------------------------------------------------------8 q" D  W6 I* N' a
;  GLOBALS:
3 U6 [: ~' x# u! c8 U' q0 G;     cloud_layer -- layer of cloud
% x7 }- @& r( s) {  d;     cloud_scale -- scale of cloud
+ q/ e6 l0 n0 F' X$ j;     number_rev  -- revision number
6 o' b; e* C. [* {;----------------------------------------------------------------------------& W. m5 ~9 i4 b$ ~8 ~0 y
(defun cloud (/ locked temp first_point next_point relative_point8 M! \: a0 ?8 b- P" @( `4 M0 j
               last_point point_tri point_ref corner_1st corner_2nd length_tri$ Q, Z5 M( [4 y& N6 m
               length_cloud angle_l_to_f dir_tri repeat_count
7 B( |4 H* S' x! f3 O               table_cloud )+ M$ p" a% R3 l
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))
. L( K/ e0 @5 \. J' }$ ]          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
9 T* c6 |+ z4 T        );if
# H/ S5 }) f% k) M        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"5 t4 w! F' l9 r# X
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))' u& v' `" |8 ^+ j: d# @* Y$ `4 M8 u
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)9 \9 P; ]- n5 m. @- g" }# D! C+ A. g$ L
                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))# q. u5 j$ G2 A
( v+ H: m4 e' X  [& ^' t5 z
        (if (not (numberp cloud_scale))" s3 o# I+ ?- t) P! y% ?. h8 u
            (setq cloud_scale (getvar "LTSCALE"))
" e( H2 \5 @5 j  F        ); if5 z5 U8 |! R" _& G
        (if (not cloud_layer)
9 i: x+ f8 l6 J! \* K            (setq cloud_layer (getvar "CLAYER"))
% x& G2 [/ L- Z/ q" e        ); if$ y7 b$ K4 Z' h: A0 m6 U9 h: @# e
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
1 A2 a- p( m, Y. X3 i8 }% ?        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。")): {; R2 ^) u& h" k
        (if (= (cdar (laychk cloud_layer)) "No")
: E* b/ I, C6 h- x: y+ B          (progn# ^/ F1 P. {  V+ }, A4 x
            (laychk (setq cloud_layer (getvar "CLAYER"))): ~* G0 o! H+ e# }
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))' p7 w; N7 q& b/ z) I4 q6 s) T
          ); progn% B3 W- \3 N& B4 u8 g- i: N
        ); if
5 M+ @% {. x  K; g* }
$ M( C. g4 @0 W& H5 i$ }2 }        (while (/= (type first_point) 'LIST)) e/ ]9 L8 Z1 b( K! m# p5 ?6 D* v
          (initget 1 "Layer Scale")
4 E- }' j% u8 P; \          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
4 E' a5 G! j2 h0 c* m' e+ K5 M- w) K          (if (= "Scale" first_point)      . H- s. m2 c. n! b. k; A
            (progn
) N  q* k' d' S5 L" \- ^& D              (setq temp cloud_scale)
# _- C! k4 u# q  D$ {1 \              (initget 6)
( n0 V; e8 k6 [  b0 i+ B              (cond+ b- Z  t4 t7 a3 Y7 s, T
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"3 _& f& {1 Y5 ^; g. b
                                                          (rtos cloud_scale 2 2)# _: q. k+ S# G8 |, }
                                                          "> "))))9 N( s4 k0 B9 U
                  (setq cloud_scale temp) )
' Q6 j  @1 L# Q1 O              ); cond  N' V" |5 o- d1 @7 r
            ); progn7 ?0 i' T( T, Q! \
          ); if0 R% Q, t) I4 D+ G8 Y& s
          (if (= "Layer" first_point)% `! z# Z% g+ W1 I/ n, D
            (progn
3 m- o4 }3 x, P; f0 O              (setq temp cloud_layer)
1 j/ ?0 g2 R+ i              (cond
4 `2 X: f. `% E- }6 Q                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"& X' p/ \1 p$ a0 E- z
                                                          cloud_layer "> ")))
5 A$ L4 n0 D! L0 r" Q                     "")
. h& s9 O% t% q, u* v' G9 k                  (setq cloud_layer temp)
/ k, X+ Z" {' A5 ^8 c; K$ U) P& p                )9 C" p. `- B0 i2 U1 m; X
              ); cond
( k2 S  y* u$ @3 _7 ^* r) x/ l              (if (= (cdar (laychk cloud_layer )) "No")" d  Y2 m: S  }, g' T: k$ `4 H1 n  j
                (progn& E/ _  e$ A1 _$ P% ^" h
                  (setq cloud_layer temp)1 ]- M) G* H) U5 q
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))$ b& d( @6 n. g: A4 f. y  T
                ); progn
" K9 i* @7 i' b              ); if
* ?4 n0 l) B6 o) c            ); progn8 x$ s5 N% l/ P+ Q8 X
          ); if2 N. j5 D/ E) J( X7 Y
        ); while5 G) X9 s/ y- Q- L' Q! I: i
        (setvar "CLAYER" cloud_layer)
: V: A/ G4 r1 _$ U$ i( p- A2 J. l3 M: x
        (if (>= ( getvar "LUNITS") 3)7 t5 T/ B4 O& y7 y9 O1 V% [' q. B  [
          (setq length_cloud (* 0.25 cloud_scale)- B% D( E; G" `
                length_tri (* 0.3125 (getvar "LTSCALE")))  o1 B: W4 E" _
          (setq length_cloud (* 0.3406890 cloud_scale)- n* q! R! Q% w4 ^9 c
                length_tri (* 0.438366 (getvar "LTSCALE")))0 z* _; \8 o" ~; {+ `) ~+ d
        )
+ X7 S# U; ]! r7 v# ~8 ~        (command "_.PLINE" first_point "A")
2 \$ T! x- W. I0 n# `        (while (not (equal next_point first_point 0.000001))8 I9 o; s( I. x- E+ a2 J
          (initget  "Close")% M6 J3 B3 p9 }5 P' }  r4 e& Y, g
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
3 m  [1 k6 ]# \: }2 N2 A1 q5 ?        (while (and (not (listp next_point)) (/= next_point "Close"))0 ]4 O7 y' y( Z% J; L
          (initget  "Close")6 ~+ R6 d: ]1 g6 o( n4 P: d
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
" [2 s1 ]* A& U/ b' Y+ w        )( }* j+ ^, ]5 U
          (if (= "Close" next_point) (setq next_point first_point))
5 N0 n% w4 i+ S( X          (setq angle_l_to_f (angtos (angle last_point next_point))
" Q* O4 a  R! g) k7 B                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f)); N" c1 O: w) T$ E0 ^+ X  B
          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)2 r- A' h, B2 X
             (setq repeat_count 0)
: ~( f* g; K. i3 A* q+ C/ ?             (if (>= (- repeat_count (fix repeat_count)) 0.5)
# O) U; a' q2 R) ?               (setq repeat_count (fix repeat_count))2 n: ?; q0 R2 W9 x* x
               (setq repeat_count (1- (fix repeat_count)))
& w/ J7 F( z5 b             ); if
, d5 a' W0 Y2 D          ); if
; w) Z4 h+ T7 [7 D          (repeat repeat_count (command "A" "-100" relative_point))& L0 b! c. h1 Y8 k/ _, i
          (command "A" "-100" next_point)
! c, ]4 i7 o) E0 v5 n0 r* L) m          (setq last_point next_point)% Y/ g: {, a  I7 h/ C4 R
        )8 u9 m# ?& I! N* z4 ?8 d4 g1 F
        (command "")# p5 K3 n& p" `) m/ A) o: F
        (if (= (type number_rev) 'INT)
: H! |8 s2 j; Z6 G           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))( t. Y. D: l" m! t: E: K2 f
           (progn/ w3 A2 `# R6 m' _5 o) v* S
             (initget 5)' `* {9 H- e5 F% C8 V0 f; I6 r
             (setq number_rev (getint "\n请输入版本号:"))
8 q6 q8 V5 |6 V9 A           )
& ?+ ~% b& x) ]: @        ); if. L: @) n9 j8 d& c( ^+ L- [, ]
        (setvar "OSMODE" 512)
) L9 l2 y# M; h6 p        (while (/= (type point_tri) 'LIST)1 I9 X+ k( s  c2 ~
          (initget "Number")3 E' i+ C# ~! U8 [
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))# f/ m: m' r7 a, U2 d( k$ [2 Q
          (if (= point_tri "Number")4 r6 @: g1 z6 m/ F  t' I0 {* m
              (progn; L! H" v$ h. }! e9 Z0 v  v# J. N
                (initget 4)
! W0 l/ i( C/ z7 s( [                (cond
5 \  G% u: K. K8 ^: ]7 W. c& N                  ( (not (setq temp number_rev
2 d' d) g6 [3 V) F3 Q                               number_rev8 k* P& J# ]5 l! Z1 `5 [
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
3 p  V# c3 O$ `7 ^6 [                    (setq number_rev temp)
+ C8 w) g" u  a; k- R6 x                  )
; y! j7 ^3 J7 s0 S! O+ v" {7 @                ); cond( N9 T+ n9 T/ `% o" B+ {0 I1 G
              ); progn) [% r, a5 Z' z
          ); if
& L/ v& z3 ~$ o! u        ); while
+ T8 C0 i! m) d. t# S8 e- W# e4 l        (setvar "OSMODE" 0)1 G& F, D$ c7 e( S
        (initget 1)
. Q- Y3 d7 Y9 U9 \: ~% t) K        (setq point_ref (getpoint point_tri "\n请选择方向:"))/ U7 |5 f) B+ v: P
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))) ?% f( o9 K# u/ b6 |
        (setq corner_1st (polar point_tri9 N7 K/ H* \2 \$ i  D$ U
                                (+ 1.570796327 (* -1.570796327 dir_tri))
7 c0 J3 {+ |* X  t                                length_tri* X/ c! X* ~2 g0 e
                         )
7 V" {) E$ C1 ?, z$ Z0 T" ^        )
0 U: O6 i. D4 N$ N2 m1 D$ f. Z        (setq corner_2nd (polar point_tri; `: q$ c, T4 e1 Z
                                (+ 1.570796327 (* -0.523598775 dir_tri))6 [* i- u& t7 ]2 n* B
                                length_tri+ n6 N( P# d- i7 N( I* G
                         )
6 e/ Z" v, i1 z! E2 a  `. m        )2 C' H( s! Y) U/ O& M! I) o# I" p
        (setvar "CECOLOR" "2")
- ]2 S  G  z% u* t& ?9 A        (command "_.pline" point_tri corner_1st corner_2nd "c" )0 S, P" u4 |+ r% n' O
        (setq textstyle (getvar "TEXTSTYLE"))
) b0 t( J7 Q% a& {2 d: I$ B3 n        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")+ z- ]0 [9 D4 F6 |' o0 q
        (setvar "CECOLOR" "7")
& k/ l5 z& @, A- _- q4 K        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
, E4 F/ M' G/ D3 t7 F$ g1 N6 ^                  (* 0.4 length_tri) "0" (itoa number_rev))/ W& n. Y: b  r
        (layres)% a6 w1 N% f9 I$ [
        (err_restore)8 W: l; x& t5 V+ @
        (princ)
9 v# Z; R. |% c& d7 e" ^5 o); defun cloud
- m1 u/ P# [0 ~  R  j7 i. I
7 n" K7 e  ~- L2 x5 A7 F5 T(defun c:cloud () (cloud))
; P9 I, V0 b- T$ m(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
6 [* ~' X! k" p0 O. _- _;;;
  ]" e4 Z3 b& h' n) K: o& U;;;  DESCRIPTION! O8 O4 n) [9 P% A. [; L/ s
;;;     These are general error routines which can be called by 5 T6 k( v9 c% {. x+ B3 R. Z1 v- `
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference
" }  y: ?5 j9 a0 ]; };;;
- C2 ~/ x# t$ G7 {  d6 G0 D;;;  SUBROUTINE INCLUDED IN THIS FILE0 s" w0 x9 y  I6 ]$ `0 J" z
;;;     UNDO_INIT
6 v# R" x- ?) E' A2 A; }3 |;;;     UNDO_RESTORE
6 s9 x( z' c$ A* I. ^* ~# q;;;     VAR_SAVE 3 v3 [& h4 V. ]* l% r
;;;     VAR_SET  
  |: e+ t3 P! ]/ `;;;     VAR_RESTORE# E) A5 ]- S, J. [$ s
;;;     ERR_INIT
) C7 R$ \, r  L: u. M2 K;;;     ERR_MAIN
3 D+ K3 v( _2 j2 a1 J4 m7 G6 t+ ^" {;;;     ERR_RESTORE
7 v8 L. _* [* |6 X) C7 w+ ~' r; ~;;;
# m% E/ c( d; x;;;  DATE: 10/17/98; 03/31/99
" P& l7 Z2 t( b4 a6 t1 [;;;/ I, L6 L, a2 U$ w; `+ W
;;;  HISTORY: 3 o! Q! [0 _4 I* s4 _
;;;    Add routine of mod_att# d5 y* ?: q8 }6 u, U( a
;;;
7 f8 {7 ]$ N; F/ Z# s2 E;;;  USING METHOD3 O* @- W" n% l0 V( i
;;;    ERR_INIT:
; g+ \+ k% j0 N2 a# u! m8 g;;;      This routine initialzes the error handler. It should be called as:
! N5 a+ G7 o7 Q3 v3 u;;;* \, V' d" u4 V7 Z8 h& {) P# y
;;;      (if (and (not undo_init)
/ N: c- @" p7 c/ T$ l" k;;;               (equal -1 (load "undo.lsp"  -1)) ; R( ~) c8 X0 Y! f
;;;          );and6 k/ r. D3 ^' k, C; T) l% o
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
  r& N0 i- g( v;;;      ); if* S2 R3 ]: @5 m5 `! ^
;;;" Z) p2 `" T' Y8 ]$ i" q
;;;     ARGUMENTS:0 f2 \# `1 \# k3 \
;;;       err_init Takes 3 arguments.
2 y' V7 e$ \6 R$ d. m. T;;;     1. - The first element of the argument:' c) x0 E. P# F- \, B# v
;;;          This is a list of system variables paired with
2 ?# z% m# o7 F) J' M- v, h;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
- v3 S- W) r/ [# v0 w;;;     2. - The second element is a flag
* k8 W5 r. q7 J: ^1 w. m+ M! T2 Y;;;          If it is true, then in the event of an error * M3 i$ }/ V9 u. D$ j7 `
;;;          the custom *error* routine will utilize UNDO " y3 l  o9 \. b" {/ s
;;;          as a cleanup mechanism.% w6 t) u1 u8 F' }
;;;     3. - The third element is a quoted function call.
' y/ V1 D$ \- g7 a9 z3 _;;;          You pass a quoted call to the function you) K& I9 L( H  o1 Y9 \! U
;;;          wish to execute at the end of nomal routine if an error occurs.
5 [% s. h/ D, f$ I7 s;;;          i.e. '(my_special_stuff arg1 arg2...). ^3 G8 I  E: }$ u9 j8 I) D0 d' V
;;;          Use this arg if you want to do some specialized clean up ) I1 d/ R8 k( }% S9 i
;;;          things that are not already done by the standard bonus_error $ ?: O" ?# ~$ P3 E7 H- S/ s! C5 t( ~# @
;;;          function.4 R. k% F) H+ [. h! o
;;;* t3 B7 G: u3 Y) `6 i% i
;;;    ERR_MAIN: Body of error routine8 L% T5 m" \0 h, y- n. Y# W
;;;5 @  l" l9 P: e2 u" K. m; X- S
;;;    ERR_RESTORE: This routine should be called at the end of command to
3 u2 O) F2 q3 ]8 ];;;           restore the VARIABLES, UNDO & *error*.! I+ y6 r" w7 n4 H- g
;;;6 W7 g; `- f) ~$ i% K
;;;    UNDO_INIT: Initialize the UNDO status
6 |7 h6 x5 e, a2 ~6 Z1 P& J( ~;;;3 r! C! I6 ~, G/ p0 \
;;;    UNDO_RESTORE: Restore the UNDO status9 o) L1 d( n0 A/ C) S: h; L# R9 S
;;;! \; `6 q* q5 W$ K! P, I
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")  I0 Q* Z' Q: i0 J/ e8 Q" ]4 M' T
;;;% g4 C5 F/ K2 W
;;;    UNDO_set: Set the variables. the argument is like
6 }3 {# B5 @0 m& i; V1 n2 s;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
* Q+ A  T8 w% c* e# `' ?2 N& N;;;9 d8 V3 v: p( ~
;;;    UNDO_RESTORE: Restore the variables
+ ]% `5 l" B" N8 j;;;# ]& y' w5 T9 f! g9 J, _
;----------------------------------------------------------------------------8 N4 A; Y# v, Q- ]  s9 ]' a
;  GLOBALS:7 Z4 [/ {: m; _
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)# o+ ]5 k, S9 b! P2 h8 M  k
;     m_lst       -- list of variables (voided by VAR_RESTORE)
$ I  e6 x1 {1 F& c! D! _3 J. u;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or6 l/ M" q0 G# x. L
;                    ERR_OLD)6 e( S# u6 X" N9 N# R: f
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
. b' w& u% V) j;----------------------------------------------------------------------------
! P2 A% ]2 Z" N) b" h( U
2 K8 t. ]  g2 \- C, g;----------------------------------------------------------------------------
+ B# h8 [- V; D/ ~. u+ I1 N8 R; Modify attributes according to entity name, attribute name, dxf_item
# I) H; b" i# @* D;----------------------------------------------------------------------------
5 }" o; V& G  i5 b# o; a(defun mod_att(ent id dxf_item)        
  P" z! _( t5 R+ w9 t+ q; v$ s) G0 g  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))2 q9 O! p# z, J/ ~8 i
    (setq ent (entnext ent)); C! `3 P; J! }5 T
  ); while  
; B$ o- W- S9 _! i  I6 D  T  ((lambda (x)
& h; F6 ]5 p2 s+ s$ S, x5 S: B        (mapcar '(lambda (y)  I& P" k4 U, E' p0 x# m
                   (setq x (subst y (assoc (car y) x) x))( |! T5 W+ Q; D
                 ); lambda. R0 i/ B1 V0 a/ h3 m7 C& R, e8 x* C
                 dxf_item
# a! j' V) ^* L# P  p. H+ a% m2 P        ); mapcar+ e: e5 c8 ^4 U8 {1 B* M* A1 m0 K
     (entmod x)
3 B/ u  X' D( p% s8 K3 Y     (entupd ent)/ [4 ?. q' P7 P  n  K& Z& ?
   ); lambda
: i) _' `; u) B7 X$ d   (entget ent), g& l8 B& r# ?, P6 ~
)
  h8 z/ G) {% j' H2 S6 v* k( T, }); defun mod_att" i$ f' Q" R: f
3 O( m/ G% R: e! y9 g9 ?# F0 J$ P
;----------------------------------------------------------------------------! A6 }$ n4 [, `7 c1 g
; Check layer status, return a association list which contains layer information
4 l3 E+ f7 h% {- Y3 o* a6 G( ^;----------------------------------------------------------------------------
' u5 j& g7 Q1 k3 a: x2 M* a4 o(defun laychk(lay / l_sta)
6 F- Y& `% h$ d; Z  ( (lambda (x)5 \3 b. Q$ T8 e
      (if (not l_s)# S. `1 u: A5 ^% F7 w: j3 y
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))* f- k- N8 q9 X! H2 C( T
      ); if/ B/ j) g: ]. o4 g. ?
    ); lambda ; g+ M& e% c: N+ S* E
    (getvar "CLAYER")
* Y1 \6 P* X, T) M2 w  )
* ~$ U* w9 |. S4 D" X0 p* L  (if (not (tblsearch "LAYER" lay))+ A8 C7 ?( ~9 ?' j
    (progn  / k7 y9 [3 `# b, y+ N
      (initget "Yes No")
4 q* F( N8 g8 j8 [. b. V* E3 v      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
1 ^) s- l8 M9 P; l/ F        (progn
2 y5 [4 n6 ~; I1 I$ }% s          (command "_.layer" "n" lay "")
3 B2 G) C; v' L6 z" U/ A          (setq l_sta 0)$ r. L( I3 c) ~; o  i# M7 |/ i
        ); progn6 I' B; [& ]) K/ \
      ); if
+ g" F! a9 q# }" F9 y* T& ?9 K    ); progn
* V  Z# n; G  s: E    (progn
* G% n6 x0 F- n$ u$ u      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
. Y' V3 m8 O5 G; C      (if (= 1 (logand 1 l_sta))
' d' Q& {( _! q9 {* B1 Y5 g          (progn
2 i3 f  t2 ?5 D4 G" C2 |8 c            (initget "Yes No")
3 N# Y* ^* M7 T! U7 \; ^) S/ h            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")
' Z" l- G" v+ I6 `4 Y* T% Y* n& i              (command "_.layer" "t" lay "")6 w3 @7 r- E0 {$ x% }
              (setq l_sta "No")  m! L6 V/ B" M, J. e; E+ \
             ); if. J: K5 h# m5 }1 `/ q
          ); progn
; k. G% n' x0 e      ); if3 e1 C) `$ N0 o- m6 {4 f- H/ x
      (if (numberp l_sta) & }7 o' t: r# Z
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
% c' z3 A; K' m% ?      ); if
/ [/ A" a+ C- k' y' p5 Y; P- V    ); progn# e. y9 r. v5 U$ u$ H
  ); if% `. X$ G% o3 W! y5 N. P
  ( (lambda (x)
. |+ P" \& B! ]      (cond
' c. J5 H6 E$ h        ( (not x)
: R- T* x  f- D9 t5 m          (setq l_s (cons (cons lay l_sta) l_s))% z! k! W  [; P, x# m
        )
! n3 c! D/ i, Y: M, F% [        ( (= "No" (cdr x))
  v! v( {1 u* v( q6 G' n9 d! I  ?          (setq l_s (subst (cons lay l_sta) x l_s))
" a! t0 X/ {5 ~  |" l3 s        )
) W; ?+ w! @# M$ j( F$ R8 l: N; _        ( T l_s)
% t. H% D! y9 D: U' Y$ l/ n0 Z      ); cond9 W; a% d2 `, W. n5 }% q8 |' a$ z
     ); lambda
: f3 \2 D5 I0 h5 l% U; X- u  S     (assoc lay l_s)
( v0 f- r0 g5 r" C  S, p+ s* f  )
* h2 V! V9 V8 y8 ^/ `/ X
6 x. ]$ ]+ N# i6 b) S); defun chklay1 f) r2 u* g& c) g( o, G; Q
' b  b1 S9 Z4 X7 h" \; R+ u% D
;----------------------------------------------------------------------------
9 B! _( k; a5 w! T7 p. b( ]# V2 R; Restore layer status according to association list l_s
2 G) |4 R2 U0 \+ M' t3 m;----------------------------------------------------------------------------
4 i* ]9 p% s6 ^( @/ i6 K$ w' J7 d(defun layres()
8 o1 T  Q; B: l+ F) `2 r  (setvar "CLAYER" (car (last l_s)))
" _; [4 Y' a+ l+ Y  (repeat (length l_s)1 p, j% Z8 o2 K1 f5 O* x/ p. t
    ( (lambda(x)  5 a3 ?/ l3 w2 s" a) F" ^7 d
        (if (numberp (cdr x))6 \0 e9 I2 Z* N9 h0 ]# T
          (progn
. k. H" Q# i8 q& P            (if (= 4 (logand 4 (cdr x)))- z+ r7 X- A+ l1 z5 j
              (command "_.layer" "lo" (car x) "")
$ e6 V8 J# k  l: C1 t4 @3 R. H            ); if
* G  H, b& D. M( T            (if (= 1 (logand 1 (cdr x)))
" L0 o2 I, I+ r              (command "_.layer" "f" (car x) "")
! C5 J, d- x' D8 r/ ]            ); if
3 y# d& s* n( L" S5 K! A0 Y- u          ); progn0 M# e4 I- `" C  G
       ); if  
9 s3 G' \5 P- |3 \      ); lambda8 @* @/ w# D, v' d4 |% l
      (car l_s)4 X6 t) y" t. k7 o( f: [
    )
- @  l! Q0 S7 f! s% D0 q6 I0 C    (setq l_s (cdr l_s))
. Q* v. s  {: _( ~. t  c* O1 t7 f  ); repeat
9 Q: [% Z; Y! ^" [' }); layres
- O) x% f1 Z* u4 G$ S: X# J' A
$ _$ f  Y. a4 s) K;----------------------------------------------------------------------------
# q, _; G+ Z+ r; Get DXF codes2 c1 J! p, j3 R
;----------------------------------------------------------------------------, ~2 J# p# z( F" Q: c
(defun entgetf (index ent)
. {2 ]+ x& }( v% J& r; L2 p  ((lambda (e)
! X; z, g+ c& b0 r      (mapcar '(lambda (x)- ^  z  s; F" m' \" r
                 (cdr (assoc x e))7 z8 A/ i8 V) S0 x6 i4 T
               ); lambda6 s: z% e6 Y' y6 S/ V) x
               index) ; internal lambda function
% [# n6 O/ k. s' U2 p    ); lambda
/ n2 q& X2 o6 W7 S6 P0 M3 U" \    (entget ent)
- n8 I6 @" w, G( R) A  )& n! t$ q/ u4 o5 Y9 ?
); defun entgetf
, X2 Y. l' ~. j- K1 ?+ ^' _
/ q4 g7 M7 O) t( U; h;----------------------------------------------------------------------------
% {: u  i5 a1 R; Save UNDO status
7 k/ o6 e2 P: x+ ~+ B;----------------------------------------------------------------------------  j, \* H  S/ n5 d
(defun undo_init (/ cmdecho undo_ctl)   
8 b! z# ]/ X0 b0 P2 @  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value+ ^% S: I( H6 a$ c) v' A
  (setvar "CMDECHO" 0)/ k0 X. S! j7 J" w9 s
3 X0 w5 x, y8 U4 N: I" i
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
* y+ \1 s  m& n4 t; M( o0 @    (command "_.undo" "_all")3 _; u2 A, E+ X
    (command "_.undo" "_control" "_all")6 R# u8 N3 j( k
  )
0 l4 N$ S% m# a0 j9 H) J& [6 S' T+ }/ `" u0 r
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off; K9 g& `8 M/ ^" M) u- d$ R
    (command "_.undo" "_auto" "_off")6 R  c( s4 z: w( w( G
  )
1 p7 [7 a5 P( a: m) ?; {6 X0 _8 m% `- j; Y" d6 _1 f2 w
  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here# @( q6 i8 K( a$ ?9 D# U
    (command "_.undo" "_end")
! A; @9 H+ j. C  )
4 [! ~) H% o3 C0 P& o& I2 A5 r- }8 z( R, i* E% s+ j5 P0 l' I/ r
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
! Q1 C) Z2 D# b" h. f: d0 y- O$ G    (command "_.undo" "_group")
+ S% V$ h" m% L  )+ p1 \+ L' ^% U2 p) a% g* v- l7 u

$ n4 _# W! e8 S' X( u  }  (setvar "CMDECHO" cmdecho)
: O/ j, f4 v* s, }  undo_ctl7 E; C1 i: f- J) s9 P2 ~
); defun undo_init
% E& y8 E9 E8 y7 C# ]8 ?( ^9 J# a' ^
;----------------------------------------------------------------------------
. f3 A' q9 L" f% _5 W; Restore UNDO status/ R: V8 H  h9 \6 Y- C; }8 U
;----------------------------------------------------------------------------
( L- G8 P* z( e( z' Y(defun undo_restore (/ cmdecho); s( g/ W0 S7 i
  (if old_undoctl, @7 d2 I! ?3 D, h
    (progn
) _& }5 }8 A9 I7 L4 L5 j7 c" Z! D      (setq cmdecho (getvar "CMDECHO"))
$ ^! g/ p& ^/ Y6 X( k, A: c      (setvar "CMDECHO" 0)
/ K. l& ^1 v1 Z" r; Y
; t+ R9 X$ A! P/ R" g7 F  f      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
: ^2 M8 Z2 B9 C  z      (while (equal 8 (logand 8 (getvar "UNDOCTL"))); \0 b4 k% H  `3 q
        (command "_.undo" "_end")
2 h0 x! b: u1 n8 R% @* G      ); while6 C  z' O; i- e3 A  ]3 j6 I

# V5 t- t* h- T- g3 B% U! t( j! X) g2 l, ?8 A' c
      (if (not (equal old_undoctl (getvar "UNDOCTL")))
( @3 V. v$ F7 ^# w2 G$ ~; R, v        (progn3 k& }6 W* s2 i! b
          (cond
+ s) _5 [$ f% j! x0 _$ R' |4 @            ((equal 0 old_undoctl)4 G6 c( x8 z3 G: b/ v
              (command "_.undo" "_control" "_none")% J' F! _2 P2 m  G2 Y
            ); Z$ E5 g0 Y& w0 C$ t: e8 |
            ((equal 2 (logand 2 old_undoctl))# n4 s" E! Q  K  e6 c
              (command "_.undo" "_control" "_one")
' I, r: N) E1 ?) h( @- Q            )
* X2 o+ l5 r( P# K          )
2 k: m" i( v+ Z7 m, D3 k          (if (equal 4 (logand 4 old_undoctl))
% `) ~: _8 O' u9 m! Z$ d2 |              (command "_.undo" "_auto" "_on")0 ^" O) `  x1 N8 L. B) K$ P. m3 s
              (command "_.undo" "_auto" "_off")
' s7 j; v' V1 W, `          )* j6 A+ q# J2 @$ c
        )
3 B6 e- z- ]% z) _9 D      )
+ |* z2 S3 \. ~/ x9 W  @      (setq old_undoctl nil)! N  I; M7 C. c) M5 @" x  y
      (setvar "CMDECHO" cmdecho)
* b+ D5 |0 i4 h' D$ W3 |4 K7 b    )1 }3 a: W* }! F- K# z$ _( _+ J7 q8 ?
  )! m  a" y: f4 v  o0 e( }
); defun undo_restore, }+ A# ?% C6 G+ I" Z* H1 z4 q, J
9 e8 P; z+ ?( a% j
;----------------------------------------------------------------------------9 T6 l0 {6 [4 O- s0 h# M, j
; Save variables8 K) ^! ?! f- J: r8 r- U! I) J+ {7 M4 o
;----------------------------------------------------------------------------
9 ?" Z! b- y2 [+ ~' p, A9 O(defun var_save (a)9 w, f+ _( [' \; M% w8 l  f
  (setq m_lst '())1 C2 Q/ t0 R- E' I, Z- c
  (repeat (length a)$ L& H( n8 z) j' b5 j% J
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
% P& X2 s8 l, ^/ t1 P    (setq a (cdr a))' _9 c: M8 M, u# y# f! a
  )8 g0 q3 `/ ?5 @4 U( P2 i
); defun var_save
) Q9 c5 I+ |$ x1 j4 C& d4 M( F
8 k) V# s. g& C5 L8 t;----------------------------------------------------------------------------3 }8 P0 r  U8 X: I
; Set variables) i# d1 _( L) u: y" }& W( n
;----------------------------------------------------------------------------, C/ l+ T8 D$ Y$ ?& @
(defun var_set (m_lst)
" i* _/ O; H5 g, M1 O( H  (repeat (length m_lst)
7 r7 u6 I( w, M& c% @    (setvar (caar m_lst) (cadar m_lst))4 y7 j2 v% b; T
    (setq m_lst (cdr m_lst))
) ]( s- Z( `: K" o; C* Y$ d  )
/ z! }2 ?! b# s); defun var_set0 [0 }" g/ P2 ]3 p( ^- T5 q- X" h
. `, |# d8 ?! O. }/ A) Q
;----------------------------------------------------------------------------  V) |; |7 x& Q. P" i; e
; Restore variables
# A2 R7 @! c+ R* Y7 P" ^;----------------------------------------------------------------------------4 c3 a) h2 J# x' a  u
(defun var_restore ()! }# O7 ~& P! h! I9 e
  (repeat (length m_lst)
' Z1 m* n: O5 O/ F! ^( K    (setvar (caar m_lst) (cadar m_lst))) x: ?/ S% T- Y" N
    (setq m_lst (cdr m_lst))/ I3 m9 M: U" X0 g5 W
  )
; v  s: n  F$ Y1 W3 ?" x. o); defun var_restore% G# W& D+ Z, ^$ K: M) b( U& A
. [+ ~) {5 P  a
;----------------------------------------------------------------------------
; N% L$ U$ [# A, ^6 ~) e2 \$ i; v; Initialize routine
4 j. R4 ^" Q# }4 S5 h' X! J( q;----------------------------------------------------------------------------: S$ x! @7 d) I0 F2 B0 S
(defun err_init(e_lst u_enable add_fun)
& R3 }- ^. E; N5 v: S' E4 C  (if err_alive (err_restore))          ; To avoid nested call
* l, \" b! t" o$ O; @& t& d. Y  (setq err_alive T)  T' i2 ~% n0 Q& E& ?  E1 T
  (var_save e_lst)                      ; Save the modes
7 K. `- z4 G8 U5 f! F2 M! |3 h, f  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status6 A2 a9 r) C9 ~# @
  (setq err_old *error* *error* err_main) ; Save the handle of *error*' X! U) f7 F/ t
  (if add_fun                           ; Add the user cleaner
1 F3 X2 O& M9 Z! R3 K# o% O/ N5 x    (setq *error* (append (reverse (cdr (reverse *error*)))# @! u0 k% G" ?4 ?
                          (list add_fun (last *error*)): V% F4 _  j% L
                  ); append
: l, ^  M4 P/ C0 N7 Y5 M    )
3 c/ }  V( [$ f" u: |0 H) p: X  )
4 J/ R* b" Q' C- U; V) f# p); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------* h/ O8 k2 w1 ]) ]6 w" a% b
; Error routine body
& J4 f" a7 b! w;----------------------------------------------------------------------------
- |. X9 Y# v5 D5 H0 ~" m(defun err_main( msg / )                ; Body of error routine
- Y& K8 b/ s- C" o1 i  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs
. N, h+ I) W8 `1 F    (princ (strcat "\nError: " s))      ;while this command is active...
  b* n1 Z" H' x1 l/ @  )1 R# Z' Y( q- ?3 }6 a# O
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command8 g; \; V( `3 t& h5 Z) _* Q4 U% f
. n% R% ~$ d. }! u
  (if old_undoctl
4 |8 n: q$ M5 q# h1 D, W& F    (progn- M2 o" ~6 T; X5 G/ w6 ^( x/ o  r
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
! r3 c8 q( y/ g6 T  C0 c        (command "_.undo")              ; if it's in UNOD command& I& i5 |, }5 L" u
      )3 Z0 ]3 i$ f6 ~1 D
      (command "_end")
7 s7 `: z& X/ |3 Y( A) E1 \      (command "_.undo" "1")
+ x1 W2 B6 H$ i& f/ T# l      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
0 A! O( A4 Y9 E* f  ^$ A( J      (undo_restore)                    ; Restore the status of UNDO
  X) I+ d& S: L+ u: }; P8 g    )
- Y; B! |' F! ^8 Z/ h8 b' e  )
- g8 C/ Y) m' o+ q6 ?7 i
9 Z, W( o  B) n; N; P0 n8 B: [! ^  (var_restore)                         ; Restore the variables
+ e' u( B: N$ N4 a1 a  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
! M- G7 s1 R( G5 K) e3 s  (setq err_alive nil)* s- N# y  l2 {7 i
  (princ); B. b- L5 A" \
); defun err_main) s5 k2 v4 F" o5 _
3 V: L1 C9 S+ E# p& W' n1 m
;----------------------------------------------------------------------------, e( M  H% v+ @' {
; Restore error status2 C3 p! K( p1 a: G" g, d
;----------------------------------------------------------------------------
# f# h: w- H5 R' ]3 J" g& b8 L(defun err_restore()
0 z* ?  \/ e4 D& B7 `# O+ w  M5 S  j  (undo_restore)                        ; Restore the status of UNDO
3 p2 A7 d5 B% d- L: [+ n4 b  (var_restore)                         ; Restore the variables
1 [. N, ~9 E( M/ m# H  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
+ _  J* F6 Y# V  (setq err_alive nil)" z! v& l1 t% Q4 h  j
  (princ)
/ @2 [! L$ a. Z9 x- N); 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-2-26 04:40

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

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

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