CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:7 N$ ]! R9 Q1 ~' m# b
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”/ `7 ~- y- Q% X! ~5 Q
提示:加载成功
& j' I. f2 c2 g$ n. s* [然后使用CLOUD命令,
5 Z: u! ?* F9 d2 d提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”% \8 g3 i+ I0 Q% y9 d+ N2 e
请高手指点一下,这个是怎么回事?应该怎么改正?8 {) y) v# o- V. v4 O
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx
" T% V8 [, y/ A! D, G;;;
0 K( @7 O' w& \, };;;  DESCRIPTION2 u2 }( u7 e7 ^
;;;     Draw cloud and you can specify the globals variables listed below& B: r  B+ m3 E; Z) T
;;;     to decide the characters of cloud
2 K. j( \0 ~% f% h. Q# m8 k! N;;;0 L7 r8 `6 M- l: v! A: I
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
" c  t3 t$ U  c9 p- y;;;* o! }" y& I& e' p
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
0 O" L8 J" d) a3 G* r;;;           Change CLOUD.001 to use CLAYER to perform the same function+ \( M8 S  F# T& u& B" [5 x
;;;           Use the common error routine UNDO.LSP to optimize this program
, r8 n* Q0 O& D;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
5 `  g9 j' ?! E! f;----------------------------------------------------------------------------
! ^2 b$ E% H  R( c6 v) O2 f) y;  GLOBALS:. k; l9 t0 P' T* h5 o
;     cloud_layer -- layer of cloud
6 O% P* F4 q7 a& n2 u3 m/ x. X) B2 [;     cloud_scale -- scale of cloud
- N' t* Q! V5 m6 O% J) d, w( U4 D;     number_rev  -- revision number2 w: d- |3 F) F( \  B
;----------------------------------------------------------------------------
1 Y2 g  X; Y. S9 K; c$ J(defun cloud (/ locked temp first_point next_point relative_point
8 @3 F( o8 A: K1 E1 F. z( `               last_point point_tri point_ref corner_1st corner_2nd length_tri+ {1 A3 b% G3 V1 c! I: R& N& @
               length_cloud angle_l_to_f dir_tri repeat_count
/ J( V/ \8 S: k! s+ E' p  c) m, F               table_cloud )
1 q. ^8 e8 q/ L/ F, q+ N        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))# ^8 M! J+ Z4 M8 Q0 V
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
$ R# |9 D! K8 i5 R* E& y- f        );if
- i+ J  @4 @+ Q* O# W        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"5 w0 b, K  x' b" F4 c0 K% k
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
* K! b  G" z1 y        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
8 e% H6 p  r/ S' }' W' ]; q                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
* Y2 h; X" l; p
9 g6 G, R5 Z' U5 v. l        (if (not (numberp cloud_scale)); A1 z0 X3 k$ Z2 }' F0 O. W  l
            (setq cloud_scale (getvar "LTSCALE"))  t8 z. \' P4 E
        ); if
6 g1 \" G( k' x- l$ L% B5 \5 G  x7 h        (if (not cloud_layer)
: H2 c6 v- E" |            (setq cloud_layer (getvar "CLAYER"))
8 l- c  T4 n8 _0 E& T" Z        ); if
3 u2 e) X7 @# T" h- ^. [$ P        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
" |" P" N+ i# ^6 H* ~& S        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。")). f5 V+ E5 Z( U; E: r
        (if (= (cdar (laychk cloud_layer)) "No")! I9 G1 {- `0 O5 e" m0 H' l% K, |+ g
          (progn! n3 F: Y. O: t% m% |* {' J
            (laychk (setq cloud_layer (getvar "CLAYER")))6 D( z5 j( |$ k' {1 r9 o6 L9 I  U
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
, b. v3 X+ V/ s1 [  }  q% n. s          ); progn
. n' |, p  j9 }0 i  c        ); if
1 ?& L8 J6 N1 S
# m! u5 S! p2 ^% H        (while (/= (type first_point) 'LIST)
4 t5 ], ^$ ?/ E9 @4 I7 o, n          (initget 1 "Layer Scale")
- W1 a# Z% G& P  J/ J& |          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)+ w0 a, F; |/ p. a6 N7 z
          (if (= "Scale" first_point)      
  |2 h+ f: @( t/ N. _* j0 u, n            (progn
: j6 h. c" b) u0 X" o              (setq temp cloud_scale)
+ W4 M9 _3 c3 F6 V0 D) C              (initget 6)8 x: ?+ u1 w7 P7 Q
              (cond
) y+ ]( ]) ?' \0 Q8 j                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"8 ]# D+ A4 k4 Z2 f, P) |8 I
                                                          (rtos cloud_scale 2 2)
2 k- O& C& y6 y( Q( \                                                          "> "))))
* L) X2 n  F9 }) H$ l- e                  (setq cloud_scale temp) )
7 B( B' P+ F" ]6 E: l" ~              ); cond; K* w3 d( X5 o2 L* _3 a- H  W, c. S
            ); progn
4 B# L8 d/ E; t+ A( k' [          ); if
7 G( Y6 j( ^! A6 `* J& l          (if (= "Layer" first_point)# W3 t. d8 L: ?$ D, i
            (progn" U; f8 h4 {  `7 }+ V* h6 C2 B
              (setq temp cloud_layer). s! m6 a+ G% k' x6 F  t
              (cond
1 G- F0 V/ [: |' @6 V                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
6 `1 m0 g) A/ a  ^4 t                                                          cloud_layer "> ")))
; H+ u2 _% D+ C! W                     "")3 ~$ O& w; J9 \
                  (setq cloud_layer temp)
; c. r: Y* F3 M7 ]/ K                )( }1 c9 C5 Y, ^
              ); cond
& v+ j# d7 Z0 I2 L# U" y              (if (= (cdar (laychk cloud_layer )) "No")1 \) y: {' w: x) u2 R
                (progn
# W2 [- Z: E- T) b                  (setq cloud_layer temp)% @( S# I3 Y6 A+ ]! Q* Z
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))( M7 f0 o/ A& ^8 I0 s6 \
                ); progn& T1 Q) I+ x0 v  k  J  x
              ); if
. `! @9 u; H, K& d% b            ); progn: v8 x5 l2 u# ]% ]3 b* p- j& w
          ); if/ J; Q1 ~; }: {8 Q! i! q
        ); while
; t& a7 t2 H- Y6 r- a: r" G        (setvar "CLAYER" cloud_layer)% s: q6 _4 w8 t! M

- b% \; \7 Q; m* }        (if (>= ( getvar "LUNITS") 3). g: J& ^5 q! k7 Q  C
          (setq length_cloud (* 0.25 cloud_scale)
& {( l1 I' Z0 V/ C4 l                length_tri (* 0.3125 (getvar "LTSCALE")))
/ D( t$ Q  D4 f6 W# z$ y1 H          (setq length_cloud (* 0.3406890 cloud_scale)
" v3 x- A3 _  e                length_tri (* 0.438366 (getvar "LTSCALE")))4 i, x. C* l0 h7 L: {! o
        )4 G) ?0 Y: B4 O7 A8 Z2 Z# X: v
        (command "_.PLINE" first_point "A")
) S0 I- Z* g; W/ [$ X8 ~        (while (not (equal next_point first_point 0.000001))$ H& D& y5 H4 O- A* K) X' @) o" d: l! B
          (initget  "Close")% @0 }/ E0 |/ k* n7 t
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
, r* f. _, o0 r        (while (and (not (listp next_point)) (/= next_point "Close"))$ s- ]0 T! K- ?9 \, e7 S! A
          (initget  "Close")
- ~, f+ u4 \: m4 V7 V" {6 f          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))  \) p+ b* l( N; n
        )
* x1 Q4 S, e1 o; Y) w2 |          (if (= "Close" next_point) (setq next_point first_point))
  L7 ^3 p/ V( e          (setq angle_l_to_f (angtos (angle last_point next_point))
9 y' @. K4 ], c  ?/ w# z$ ?                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))8 V- A! N: e2 g* X
          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
7 l$ @4 C6 n  A, o3 z             (setq repeat_count 0)
7 Z; B/ p, w6 F1 f             (if (>= (- repeat_count (fix repeat_count)) 0.5)# [, s& V- V; u  r: |
               (setq repeat_count (fix repeat_count))3 C& z* Q4 Q: o
               (setq repeat_count (1- (fix repeat_count)))5 u+ Q# m5 q+ C
             ); if
( u8 n2 a  y0 \: v0 `          ); if
4 N- ~: h& n7 \, m  n          (repeat repeat_count (command "A" "-100" relative_point))
) m- y+ n; D/ @" R( W( y          (command "A" "-100" next_point), L; e! Y4 G5 z" Y9 G$ \6 l
          (setq last_point next_point)* V/ s" A7 L% [3 ~9 J
        )- A7 j- E0 i0 D3 O
        (command "")
' b( O. x: y2 E3 g4 o: Z5 A        (if (= (type number_rev) 'INT)9 ?' z) T$ @  T
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
/ ^# b; {2 _5 @% p6 w- c* e2 t2 v           (progn
7 ]! B( c# M$ R& ~: R7 ^             (initget 5)" L. `2 s. {, U+ \+ I- k( X
             (setq number_rev (getint "\n请输入版本号:"))
8 Z' `# X$ U: d$ F' a* q           )
. \: h/ M  h* f9 X" w. c        ); if
3 `$ T: A; q. K  X+ a: y        (setvar "OSMODE" 512)3 ^: C0 e  ^7 q$ L$ L$ S: P% f2 ^
        (while (/= (type point_tri) 'LIST)! I" r, [. s# I( [2 H. k7 K' f
          (initget "Number")
' w% |2 Q" d( p9 h* k2 ]          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
) |1 r3 o5 u9 j8 A          (if (= point_tri "Number")
1 \# ?  @" q8 Q              (progn+ J0 _+ u7 O9 \5 s0 `( p# t
                (initget 4)
7 P4 [. V% E. e, }$ L1 h                (cond- g1 H2 }! U& U. V
                  ( (not (setq temp number_rev
/ k) ~( |& [5 T# q/ n: u7 K                               number_rev5 _7 f. L" Q5 X; |# d( N+ Z
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))2 G  u. X! N- {% j. j$ H
                    (setq number_rev temp)4 Q1 k) @7 }* }- U- I! m9 Y
                  )
$ P( f, E( y( t+ f) r* k/ H# q; y4 U                ); cond
( a- f' T' _5 O7 A7 x; B              ); progn
7 X7 k6 [% o1 S) B          ); if% }9 ]  I2 T; c* ?3 L
        ); while
6 p. I) a6 t: _        (setvar "OSMODE" 0)
6 k8 U4 j9 F. S        (initget 1)
. I! V9 ?- k$ t6 r5 X        (setq point_ref (getpoint point_tri "\n请选择方向:"))1 h$ \* l1 t5 z- i; F
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))9 o+ V6 B# z% P; ^" N
        (setq corner_1st (polar point_tri) `) d% [- C% R$ _+ y  }
                                (+ 1.570796327 (* -1.570796327 dir_tri))
7 `, N  K+ I' s% Z; k) ~8 o. m& T                                length_tri
. g' I) F1 t, i! }1 c# `/ m                         ), B. G( H( h- r7 _
        )
# P; h  d* [( c        (setq corner_2nd (polar point_tri7 A. W- o% x0 a7 E7 m
                                (+ 1.570796327 (* -0.523598775 dir_tri))
  L% g8 _1 s" e/ m                                length_tri
6 w+ D5 o. g! K' u5 D) `1 V& ?                         )
! T- Z( w( O0 ^/ _6 Y/ J/ b        )6 d& l- O7 P  M* }6 a
        (setvar "CECOLOR" "2"). X2 \" {$ K9 G3 W. C9 I' N
        (command "_.pline" point_tri corner_1st corner_2nd "c" )
& ?! B5 J  t& f0 z6 t        (setq textstyle (getvar "TEXTSTYLE"))
! @, x+ Q0 L% V& M: Y4 G        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
" S+ N& ^: I8 m# R/ }" }' l- o        (setvar "CECOLOR" "7")- j& q- D! \5 L6 x1 Y
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
" I5 G  e; Y* {& W- D3 x! I! s                  (* 0.4 length_tri) "0" (itoa number_rev))
7 C2 W- u, r1 {. m9 z  O5 J. j( v        (layres)# x: E  p8 B5 [+ v1 ^2 c
        (err_restore)
6 R8 s( D( @6 O" R        (princ)
7 s6 r2 V9 H) Z" ]); defun cloud! m1 [$ d8 \' j" M
. L1 x% r' r# R# v
(defun c:cloud () (cloud))
0 M* N. f, [) z! ?) k+ t6 \8 ~7 V/ K(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy3 Q( e4 y& y2 B3 D6 ~; |' X8 @) p
;;;. z& c- V; l8 @% c
;;;  DESCRIPTION9 F2 ^3 x2 o& g& k! |: n3 V1 _
;;;     These are general error routines which can be called by
$ {0 C& J& Z2 q& u;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference2 g2 g6 F# F' G. x, h
;;;& {- q: P( f4 x. h
;;;  SUBROUTINE INCLUDED IN THIS FILE! x3 [* C% E: K) `# w* t! f
;;;     UNDO_INIT
' i. G- r/ E6 U# O8 E9 ~;;;     UNDO_RESTORE
* V$ j" R: K5 \1 l# z! z5 m;;;     VAR_SAVE
( W& D6 a3 f$ J0 h  ]8 Q: L6 H) C) o;;;     VAR_SET  
( V* l0 n- u% s- Y  u;;;     VAR_RESTORE( A0 d3 C3 M& I  l
;;;     ERR_INIT 5 C& S0 k7 Y2 N1 Q
;;;     ERR_MAIN
/ F) ~: K8 A0 _7 C# H$ |, E;;;     ERR_RESTORE
5 ?. o3 D; p: V) F  {# h0 W  n;;;1 i/ ?6 s, B+ }* }$ A
;;;  DATE: 10/17/98; 03/31/99- _3 c+ m* J9 v/ v, O( m
;;;
$ s, W1 o4 }" ?2 C2 \;;;  HISTORY: 3 c5 @0 C$ A% o- n8 s+ O
;;;    Add routine of mod_att
3 Z( z( E2 o8 v* _6 _0 u;;;
. c, `7 K* L) h# w" f;;;  USING METHOD  x" ~) _0 o5 D
;;;    ERR_INIT:5 l- X$ ]+ _1 \& e9 E- f
;;;      This routine initialzes the error handler. It should be called as:
' Q+ ^' ^/ V9 l& w: _;;;
4 q9 g- w  f4 [5 X, M/ Z* |4 N' F;;;      (if (and (not undo_init)
: F+ j; e$ x4 c# X! l+ \- I8 J( };;;               (equal -1 (load "undo.lsp"  -1))
/ `7 O! |7 w$ ?8 Q: B;;;          );and* E& M  _% u1 F9 W1 m
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
* l% |: M# M$ ~- B;;;      ); if
# p& Q" e& B' ^9 P/ n: H! m4 N! };;;3 b* r1 d" q8 D; F4 E
;;;     ARGUMENTS:4 {$ A9 c* w4 ?. d  @) K
;;;       err_init Takes 3 arguments. + }2 q; A# U+ [+ `1 |, G
;;;     1. - The first element of the argument:
8 @; Q9 J% v; K. q0 {;;;          This is a list of system variables paired with  s. N4 s2 b3 R" [, ^2 ]% o7 R# z
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE"), O0 Y# i0 k! _% w, ^. p$ H7 X
;;;     2. - The second element is a flag
0 W6 l7 O/ f- \0 Y& ];;;          If it is true, then in the event of an error + e9 M7 c4 t, W* O5 s
;;;          the custom *error* routine will utilize UNDO
% O; M) F( R: z; u7 N;;;          as a cleanup mechanism.; n; e( `) I* M$ @" H; z) b
;;;     3. - The third element is a quoted function call.( Z) K$ K) O# v
;;;          You pass a quoted call to the function you0 ~- L& A( O2 j, {0 v- [
;;;          wish to execute at the end of nomal routine if an error occurs.
2 U8 P0 {2 m! o8 ~;;;          i.e. '(my_special_stuff arg1 arg2...)
4 a. z1 {) o# T4 y;;;          Use this arg if you want to do some specialized clean up
% o# y, \  Q4 D  J$ o% v;;;          things that are not already done by the standard bonus_error 1 n( O" z- @! i( L8 C
;;;          function.
4 Z+ F1 Y. _' W;;;
" v  W" }4 n- g# V;;;    ERR_MAIN: Body of error routine/ f1 v4 ]+ U' v8 Q
;;;
5 v: B; d. ^7 K$ U" m& \: S; Q;;;    ERR_RESTORE: This routine should be called at the end of command to2 Y: N( q+ f) L# p; C, u
;;;           restore the VARIABLES, UNDO & *error*.% V" C) P5 ]* q
;;;4 x7 K, |+ ~$ x; R
;;;    UNDO_INIT: Initialize the UNDO status
5 T' U! ~) J8 B7 w* j3 i! U( \  ^;;;
, A' O# X+ G8 k, c;;;    UNDO_RESTORE: Restore the UNDO status
) n1 Y( u, y1 n$ K;;;3 y! l6 u% X' U" O! H" U$ ~
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
: ^) g; @6 E7 }/ u% P3 r  K- ];;;
" G9 t4 }& ?7 A1 b. K;;;    UNDO_set: Set the variables. the argument is like& O3 E( p, a& o
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
) }( P7 X* Y' O: a1 B; _% t;;;# f: W7 H0 z5 a) @' \; L1 |
;;;    UNDO_RESTORE: Restore the variables
" J- W- c1 {0 [7 `) C4 G;;;
/ T  A9 j' b: k4 B; D1 a  d;----------------------------------------------------------------------------& Z, M7 S% [8 }" C
;  GLOBALS:, g3 ?/ h; m9 C" X% N  y' S' V7 i
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
9 o* Q. G- L* G2 f! I9 l. T. m6 g;     m_lst       -- list of variables (voided by VAR_RESTORE)) k+ v( {1 y& Y9 o/ E
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or5 W5 \: s  J, w2 i
;                    ERR_OLD)/ C( b& O6 }1 @9 F
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD), t0 E7 z' M( [
;----------------------------------------------------------------------------
# }" k% p2 \. [' F, _' U- J
) z; p3 Y9 x7 l* R& K" o, k;----------------------------------------------------------------------------
$ x' ^8 E, [. {& A  ]; Modify attributes according to entity name, attribute name, dxf_item
, P3 J& v3 T$ E+ z& N6 {;----------------------------------------------------------------------------, r" `, r! P- E. c+ h  G
(defun mod_att(ent id dxf_item)        % e; G3 e& C$ e8 {# k
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
6 k: W5 q$ n, h# F$ R    (setq ent (entnext ent)): k8 l' e) y$ B- k) }
  ); while  
' K' h3 ~. U( z' X  p/ _  ((lambda (x)
, H* m0 e) q5 m* O3 b. s        (mapcar '(lambda (y)! [8 R; }4 i9 a& ?+ j, V
                   (setq x (subst y (assoc (car y) x) x))
4 x: e  c* u: f                 ); lambda! |: q* T4 L8 J7 U- K% Z; x: w
                 dxf_item
% L' A, V0 O  k1 w! s# l        ); mapcar
2 A/ [" c* A8 X: H3 X: w  j" V     (entmod x)
8 p$ S) h2 a8 X0 w# r1 }     (entupd ent)5 ~, E& j7 q1 n& f2 Q+ d
   ); lambda
8 N' A* g. A% {1 L  A1 y& @   (entget ent)/ j3 v& [1 H2 t
)
$ e  M8 B8 }6 t9 |, C); defun mod_att
) Z# _. y" w; Q- I: F3 B, ]% R" _. B$ @1 O% V
;----------------------------------------------------------------------------
5 e) u4 F/ T: h7 m; Check layer status, return a association list which contains layer information& v- L6 a0 G( c) v; L* |
;----------------------------------------------------------------------------2 Z9 s/ V6 Q& ?  E( J3 Q: p
(defun laychk(lay / l_sta)8 E2 c* z2 e. F+ ?& k3 ~( G
  ( (lambda (x)
$ W2 o( J$ R4 q, x      (if (not l_s)
- C) C, C7 [4 N) U( a  t          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x))))))). u7 r0 |/ Y: k: `+ z! d- V
      ); if" K3 T8 W1 S4 [" ?& \
    ); lambda % u- H  z6 s7 t4 U6 i
    (getvar "CLAYER")
) x/ H7 T% }8 J- u  j- {5 x- P  )
9 Q8 Z% e# ]3 r! w- e. ^  (if (not (tblsearch "LAYER" lay))
6 p% Z, X* L  C! o& F2 M    (progn  
  o7 K& e+ p: a* A      (initget "Yes No")
3 e3 s' v$ _5 N' F/ G/ |; ]& l# A9 w      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
1 I" a$ I( p0 M6 {        (progn
# @$ X/ _, U+ \- a; [$ ?' e          (command "_.layer" "n" lay "")
& y$ H# u1 [) M' O: [          (setq l_sta 0)
/ i4 d( O) g1 J$ S: q! A& {* Z        ); progn5 f) I0 {" ?  o' e7 `; k
      ); if. A3 O) i0 D9 i0 b1 }$ h' M6 h5 s* y
    ); progn
* O6 n( R+ u5 i+ H3 N8 ?    (progn( ~( X4 i9 T% F; B
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
4 Q5 j9 n% W3 n! T: k6 ^      (if (= 1 (logand 1 l_sta))# u4 F% ?, F0 F& q9 _' W* x
          (progn
2 J% ^5 i3 C; m% m            (initget "Yes No"); Q! Q3 z. G% F' c- H8 V4 Z
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")8 ?6 w5 z2 @$ Q# e! R& z0 o. T+ e/ G
              (command "_.layer" "t" lay "")
/ E/ }$ l; C7 B              (setq l_sta "No")7 S+ x/ V7 Y- ?0 h4 K
             ); if
  v$ L: B' Y. V: O1 u* g% U) p          ); progn+ z' e  B; H6 a5 i1 B
      ); if" H9 |; n9 J, d# U$ l- ?
      (if (numberp l_sta) ; d% A$ e. i8 h! w1 K3 m3 ^  p
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
4 _- g$ Z* K9 \. N5 C      ); if
/ P& U% U" k$ c  k3 s3 y4 e    ); progn
9 k5 \3 m/ x+ _6 m' K/ P6 o; \; l  ); if0 [! T9 ~' I' @  X7 ]# v/ d
  ( (lambda (x)
0 x6 g  d4 j6 R+ o# i: X6 \      (cond + F9 P7 ]4 ~0 x0 g8 y2 o
        ( (not x)
% J) L. P9 B! p$ M/ ?; y, _5 X          (setq l_s (cons (cons lay l_sta) l_s))
8 `, \. E2 o# k- X  Z7 \6 D% k' H        )
2 v3 Y" v- g; X1 L* \: q        ( (= "No" (cdr x))! _7 v6 }( A0 u1 k2 v& G
          (setq l_s (subst (cons lay l_sta) x l_s))
8 T9 x( N, }# Z+ J& ]. l        )
. O. Q. O- n0 E: [        ( T l_s)9 k4 M! L* x  s9 F- p* [. \* m+ J- ~
      ); cond# }4 ?$ P. r2 u- \# C
     ); lambda
7 h7 n8 C) X, D2 u3 d+ e9 Q# c     (assoc lay l_s)
# R' z: W: h3 `. T; R  )
7 {( v6 J- R7 ?9 G! L/ l$ \* C) D" @! l, Z8 J
); defun chklay9 L4 }( ~& A  a# a& R* c6 ^8 Z  ~
- |" M& M0 }, t) F' a- O
;----------------------------------------------------------------------------
7 Q9 J# {" ?4 u1 ~* O5 C; Restore layer status according to association list l_s
6 L$ L& f8 T; N;----------------------------------------------------------------------------
2 z. t8 a( h1 G6 C9 w7 s# \(defun layres()
. J  x" ~, _& N0 f- g9 P" x  (setvar "CLAYER" (car (last l_s)))/ W  s* z& N8 v$ X" @
  (repeat (length l_s)+ A  n7 {6 V7 q- j4 _
    ( (lambda(x)  
9 n/ y* @# A. c" ~4 w        (if (numberp (cdr x)); O5 L( `1 |$ Q5 ~
          (progn : M% M0 p, d( d2 V2 _* P) R! Y9 c, P; e
            (if (= 4 (logand 4 (cdr x)))
% B. f; B' F  Y" q3 w. x; N9 g              (command "_.layer" "lo" (car x) "")# l1 m4 n9 h3 I! x0 z" t1 x) m2 G
            ); if9 r2 M2 m! s) X) P" u  Z& f0 z
            (if (= 1 (logand 1 (cdr x)))
& H3 Z/ C0 Z) [% q. r              (command "_.layer" "f" (car x) "")8 A% F; R' J$ h
            ); if/ K% j5 {) D. n2 s5 v9 I
          ); progn
" V6 n# o4 n" O4 K) l, z( K) b: @       ); if  : n* Z5 [+ G! y, `+ Y
      ); lambda0 X9 \$ b- T! y3 J8 y
      (car l_s)4 z8 @: C! `: N
    )
  s, R* m% e) |4 [8 k$ s& F1 O    (setq l_s (cdr l_s))
# }5 u+ z6 \& e- F  ); repeat
3 u3 i, m, Z- y8 d); layres* X2 H, A/ a' K
% D: ]9 @) U0 z- l
;----------------------------------------------------------------------------
8 r5 l% W& [( @5 p; Get DXF codes6 r( ]. t! ?/ d% {! M/ D3 z
;----------------------------------------------------------------------------
% r1 f1 L+ u, ~3 q(defun entgetf (index ent)* v/ T+ ^  n" s6 I! }6 T1 ]* `
  ((lambda (e)
8 D* o+ |/ c+ l/ r: Z      (mapcar '(lambda (x)2 Z' A; ~% W/ _: P+ m
                 (cdr (assoc x e))  @. E$ Q1 x9 ?4 [
               ); lambda
& H: R+ C0 g) z8 i               index) ; internal lambda function4 d- J  G% T. W# E
    ); lambda7 K- q/ @. l+ l$ v- k3 f  U, a
    (entget ent)
+ b: G* \$ X0 J* f  )4 T* O* h, ^. L* U+ |% N& _
); defun entgetf
5 ]' b) g& U, r1 H" i+ @& P) i+ o3 Y3 ^0 h) A4 a. W, h9 w
;----------------------------------------------------------------------------
* J3 n- D( D! d  z/ D$ y/ U0 p* w/ q; Save UNDO status
% @; }& a! ?4 @" |/ Y/ i% V6 Q;----------------------------------------------------------------------------
0 r# {" x+ g9 O. T(defun undo_init (/ cmdecho undo_ctl)   
- S$ S2 ^, b' u% t4 F0 ?  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
0 `+ X3 [* Q) w/ w$ l1 |7 J" G% g  (setvar "CMDECHO" 0)
+ Y7 f* Z. `+ j4 Q# ~, c' O% u5 h9 l4 O4 I
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable: ]4 R' T  b. u  L
    (command "_.undo" "_all")& {0 q8 _) v  ?" v+ @! ~( r0 n  w
    (command "_.undo" "_control" "_all")* M6 i. d$ ^! w3 z/ V' ?* K8 ~0 A
  )+ Z8 V& X7 V: S/ v1 w) R

& s: |# v! l3 R- o( n5 W9 o; X  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off& f* @$ S3 P4 W$ i6 X) x1 |9 ^
    (command "_.undo" "_auto" "_off")7 ]( F) X2 T3 {, S
  )
  x! f  B( d. ~, o$ G. a1 \
: h1 F" J. w4 G+ C+ M, T3 D  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
! ]8 z# ]7 ~) B/ S    (command "_.undo" "_end"), V2 P7 E* @* S8 c: u- r& b
  )  N5 x3 J5 S: p; v- F& b+ w

2 {7 {4 }. l7 K6 z+ F  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
- D9 k, i4 G; [- |& v    (command "_.undo" "_group")( B) m5 X/ c6 `
  )6 A/ j! R9 P# z4 L) I

8 c, m; ?* I3 w  S2 I) ]  (setvar "CMDECHO" cmdecho)' \& ?; i1 O; ~8 ~
  undo_ctl
* h: d% a" {; I' E  t$ e); defun undo_init, g; d8 c8 q- j+ f/ D

5 O# O5 w  F$ F* e; ^4 Y" E;----------------------------------------------------------------------------6 f) m7 Y+ F5 `( ~
; Restore UNDO status
. p0 z9 k/ o8 }2 R. p4 g;----------------------------------------------------------------------------
# I* p  R) C9 m: w. B4 B9 P* O! U(defun undo_restore (/ cmdecho)4 f2 I: v5 y7 t
  (if old_undoctl
8 U" S9 y5 |2 c' K    (progn9 Y7 F/ I* p- F2 i" w* z
      (setq cmdecho (getvar "CMDECHO"))
. g% B/ k( x5 ]& F, b4 j7 V      (setvar "CMDECHO" 0)
% n8 a3 b7 k1 Y9 l5 Q# z
5 `% l6 C7 z9 _% H& P8 B3 i4 e      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) ; \0 _( W0 n  C+ x9 h) C* _. E
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
. h  x8 t5 u/ L9 R0 _9 G        (command "_.undo" "_end")
! Y5 r0 g' Y; E& r! i1 a      ); while
1 ]$ r; h3 S; M3 [# u, [/ t9 _4 v' }8 F& V7 Y
; @( K8 N1 T/ `: Z
      (if (not (equal old_undoctl (getvar "UNDOCTL")))7 Z6 R) B- K0 c7 j$ ^
        (progn6 a" S: G8 `' ^$ U% ]
          (cond% e! H8 ^0 P, p) B2 O: @3 k
            ((equal 0 old_undoctl)/ i$ h( `7 O& ?; h* P+ |9 R
              (command "_.undo" "_control" "_none")
+ q+ f" N1 ?( [- R            )4 f  ~; j2 C$ N4 P3 F& q3 l$ s8 i
            ((equal 2 (logand 2 old_undoctl))
( t; H# R' T9 V, C0 S              (command "_.undo" "_control" "_one")
( k: i* _3 e7 i5 x% k6 O            )4 A6 M. k) m5 k3 D9 k* B* v; P. d: M
          )8 y: ]. s" V3 M  B* b! F
          (if (equal 4 (logand 4 old_undoctl))
% N: U8 u3 H4 J              (command "_.undo" "_auto" "_on")
$ Q! M% k* |7 Q1 `% Y2 q              (command "_.undo" "_auto" "_off")% C6 H) R7 L: e. X$ c* [
          )* s: k5 f5 N# B9 B* ^: v
        )
3 L: V( |/ o; o5 H. M      )  T) W' s, i) ?* ~
      (setq old_undoctl nil)2 r* c  x. l' [/ z& K
      (setvar "CMDECHO" cmdecho)
" `  n; i1 t1 o7 l& t9 E* o+ Q/ h' a    )# Z( e. e, Z( h
  )
3 L: s7 N& `/ c, ?); defun undo_restore
9 X# ?8 q8 P& p; d# c" ?  M7 h  @* R+ w, E1 {1 C
;----------------------------------------------------------------------------
& O4 u. @' m0 w+ x4 S; Save variables0 U* t; l! A! F  w, m
;----------------------------------------------------------------------------
% }% ?; z6 f! q4 y(defun var_save (a)# R* p* g! i: a, t0 v9 {; n0 V! B. S
  (setq m_lst '())
- x' C& {- _- z7 ~" |0 l+ Z' R4 n  (repeat (length a)
% |/ D0 U* ?, ^* ?9 V    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))* U3 p* j3 W' l- _# c
    (setq a (cdr a))' h7 Y5 M* w& [5 M$ h  z' \( H- O2 a( ?
  )$ w, s6 Y# ^8 h7 E" B; ?
); defun var_save/ g5 K% R9 c/ t. `' B: A
# f0 E: A, O& z
;----------------------------------------------------------------------------
* [. s/ K( g2 ^; Set variables  D7 L6 i: D0 Q
;----------------------------------------------------------------------------
" d; i, g6 M2 C- {2 }( W(defun var_set (m_lst)( f6 e$ K+ }, y# j5 p; S
  (repeat (length m_lst)
" O+ q* J5 F3 k2 `. P    (setvar (caar m_lst) (cadar m_lst))
" U1 h% Y; y+ U3 O- t% A7 Z* P8 _& w    (setq m_lst (cdr m_lst))# j' v& k+ C+ G  b
  )" }& ^, R( G' x% T
); defun var_set
+ h) E  K7 l9 g7 J8 s& m; N7 L1 {1 e
;----------------------------------------------------------------------------) r& k- Z. K' @9 y
; Restore variables5 g3 R( |& x5 l2 l$ a
;----------------------------------------------------------------------------
4 @9 I: {! S( k1 n1 c(defun var_restore ()! ^5 H2 H8 D) _* d5 g
  (repeat (length m_lst)
  k0 n$ r4 S' r9 B+ I    (setvar (caar m_lst) (cadar m_lst)): v: T) f" v7 u" }7 p9 {3 [. T
    (setq m_lst (cdr m_lst))( u5 a. |' ]- Z: I9 A
  )  H6 ?* m4 W0 I0 g' T& c% k8 I2 _
); defun var_restore. B6 A' E6 |* l8 g: E
6 v0 R3 o2 L- c8 A2 ]: X: M6 Z; l1 A
;----------------------------------------------------------------------------; @$ O# g9 K2 M: @" j
; Initialize routine   H: T. I* Z/ K$ {: [' w7 G# d! U
;----------------------------------------------------------------------------% ^% U! j' X) B: O, U/ q
(defun err_init(e_lst u_enable add_fun)
: P8 \5 j9 Y0 I  (if err_alive (err_restore))          ; To avoid nested call* H* r/ h3 i- J# c. x
  (setq err_alive T)  F7 Q: B9 U. ]0 w
  (var_save e_lst)                      ; Save the modes$ a! g# A+ I2 I0 @( D8 K' ~
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status' y$ h" q. W0 S3 K
  (setq err_old *error* *error* err_main) ; Save the handle of *error*8 J' C8 w  S0 l! X
  (if add_fun                           ; Add the user cleaner
+ H  x1 V+ T, |1 f% B    (setq *error* (append (reverse (cdr (reverse *error*)))
: R8 l- c0 e& z; h( [  o                          (list add_fun (last *error*))5 w6 ~" F1 }7 a- d  k
                  ); append2 ~& H1 h" \: Q
    )
5 I6 C/ l0 ~, B) s0 x  )
/ `% M$ V9 m4 V+ c2 k0 H; Z); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
. u9 p9 Z$ o% C# Q; Error routine body
! P* H0 j7 J9 p: h;----------------------------------------------------------------------------
9 I4 H4 n  L7 P: i6 @0 k8 O4 }(defun err_main( msg / )                ; Body of error routine
  M( T3 b/ |( p0 z, U' A  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs6 m6 Y3 \  u1 Q
    (princ (strcat "\nError: " s))      ;while this command is active...
* f( _! z, ^3 \/ C  )/ @4 t' z. k( D4 f  B7 v6 R
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command( }* M1 M3 P6 O2 I' K
# L+ t  Q9 k% m5 t1 ]" G% D
  (if old_undoctl  I0 m8 }% M: R
    (progn" h+ r9 p8 q4 f6 ~1 p  k) J/ l  Z) e
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See' ?1 R" r- C. |( d  ?; z# g
        (command "_.undo")              ; if it's in UNOD command
4 w) d# ~3 s3 o5 Q8 k8 D* j      )  a1 R3 z; n1 {* S: }) d( W
      (command "_end")" B4 a* Z; p! H
      (command "_.undo" "1")
" s4 H) t3 ]0 }# f3 d      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
% n4 B- H2 m  S1 o% U9 R; J" i      (undo_restore)                    ; Restore the status of UNDO
: T, E  T$ n! K% c  v    )% S7 p3 G$ ~! O9 E* l, X
  ): ^0 `0 W, b' E4 \

" M/ \. v+ J& g( c+ ~; r  (var_restore)                         ; Restore the variables
4 Y! q6 U6 W( }6 `7 g* b$ G& a" M  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error- N6 t. ?0 A) I4 U' J
  (setq err_alive nil)  K/ O( v' g9 g6 f  `8 r
  (princ)
# E* G  M8 c- r# `7 V0 M); defun err_main" \/ r" ~5 l/ [( W- N7 G

, M' e, h+ n. l, a! J( y  O;----------------------------------------------------------------------------
. N* P6 H  M9 ?* V1 Z2 y  `: \; Restore error status6 T' h/ O/ M$ I/ q' d# ?$ p
;----------------------------------------------------------------------------: T+ y% E1 ]5 p, U3 I
(defun err_restore()
  L7 ?  k4 N* s$ c& @/ ^- d+ I- U6 F  (undo_restore)                        ; Restore the status of UNDO
2 u" m6 I5 ^, c* d4 b7 e  (var_restore)                         ; Restore the variables7 {% s  Y' P5 B& I1 w
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
# u$ I! _7 a' Y; F+ G  (setq err_alive nil)8 e5 ~! s. _8 Q8 G* d) O
  (princ)
! p. b! T2 |) g( t); 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-11-14 15:02

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

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

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