CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:: U3 W* v$ O6 z4 [
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
8 r( {4 J: x! E3 `* s, D" G9 _+ e提示:加载成功) U' V6 _8 z! U) x
然后使用CLOUD命令,
, _6 h3 F  @0 z提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”+ }, a. g4 H/ E5 b" S6 t' e* o
请高手指点一下,这个是怎么回事?应该怎么改正?
! |. W% u9 F3 E3 C# L3 G$ c) q8 ?这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx
* t0 y7 ?7 I: F$ L) x1 k1 q;;;
! u  P: _4 L  A. L. e/ C;;;  DESCRIPTION
* E9 ^1 F: }- i# h5 e9 d;;;     Draw cloud and you can specify the globals variables listed below
' f* D$ [; G2 T8 G) ^4 I; l. H;;;     to decide the characters of cloud
& d7 O. |6 r5 I  A/ D- F# p;;;- N& H) j2 E# g4 P& e
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
6 |  j+ y: L) }$ [  C;;;+ k, q3 C0 M1 I+ m: B4 ?
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
) L8 \; P9 q2 s( u( u;;;           Change CLOUD.001 to use CLAYER to perform the same function
  I) f8 \0 a1 Y; o9 U' @;;;           Use the common error routine UNDO.LSP to optimize this program1 @& T8 T- Q  m- c
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE5 k; M" L* V" I* R% Y1 B
;----------------------------------------------------------------------------: a7 x- N0 Y) d: W4 s
;  GLOBALS:
& K+ P' g) J2 t7 B  W3 ?% ?;     cloud_layer -- layer of cloud+ I+ \( {* x1 O& e
;     cloud_scale -- scale of cloud
  z! F7 }; ]6 o0 K- J;     number_rev  -- revision number
1 ~- s  Z, |2 k7 l;----------------------------------------------------------------------------
' X: y6 W4 j8 W8 T5 @5 @(defun cloud (/ locked temp first_point next_point relative_point1 B, K  t7 k) A' }  Q
               last_point point_tri point_ref corner_1st corner_2nd length_tri
' R' s# I% d9 |               length_cloud angle_l_to_f dir_tri repeat_count 0 N6 e; I7 z- J9 u
               table_cloud )" H4 G# x1 P; Q: s/ _! y; t# K+ P8 n
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1))): e8 m# ~4 }% l& U6 }0 ]. k
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
# u: u7 U# T3 J4 @        );if8 `! R0 H# n! x+ J. f6 C. o. Z
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
+ D! h. t9 k2 G" C& I# o, X                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
4 `# |7 `1 L6 r) Q        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)) A' d. z. w0 h5 @6 v, Z
                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))# h2 Y8 F( D9 V, a6 x2 R. F

  c& x$ d$ c  ^9 r* O        (if (not (numberp cloud_scale))
; m8 c1 `7 e3 x/ m- f# n% U# f            (setq cloud_scale (getvar "LTSCALE"))
$ t* Z5 v! H  X  I1 p8 k  m        ); if
! H; v6 K- S: |' x: H& ?: [        (if (not cloud_layer)- S0 {: H$ V5 K0 |! p
            (setq cloud_layer (getvar "CLAYER"))% A1 f8 J& I" J- B" A2 V. S. B4 j! V
        ); if1 w7 k/ E3 C3 I2 u  K; d
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
' g/ O" h  A" L$ l; \$ E8 S        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))  o( Y% L1 I) K5 P( D, \  l
        (if (= (cdar (laychk cloud_layer)) "No")
1 {5 E, Z- {6 H5 L& ?          (progn/ j5 b- O) ~' ~( e: G( s# _0 \" L
            (laychk (setq cloud_layer (getvar "CLAYER")))7 R, a8 G! `, V! k' l" y
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
" v5 \6 ^2 q8 e          ); progn5 h1 v8 M( M4 X" S
        ); if- a: k4 J7 M; v4 P) D
2 t3 s: e7 N0 {
        (while (/= (type first_point) 'LIST)3 m. P! |4 x& O2 J# g9 V7 s
          (initget 1 "Layer Scale")( v. p. p7 q6 j' w7 @) y' o
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
& L' G) l+ {* ?5 Q: R5 j* `          (if (= "Scale" first_point)      
/ r: J. D# {& Z2 N. Y! ]! Z8 R            (progn1 R' X9 Y; B, j
              (setq temp cloud_scale)
' B/ J- n' ~4 O; P              (initget 6)
' a+ S- ^. [) Z              (cond! V1 y' j4 x8 o+ Z  B/ P
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<", D% a/ T( m5 p% j* h- f3 [" e3 d
                                                          (rtos cloud_scale 2 2)0 |3 e( y0 J& M4 u3 n8 ]
                                                          "> "))))
+ E& K9 m: m  L9 x                  (setq cloud_scale temp) )9 y1 S0 a& `5 }0 G
              ); cond4 @9 Z  z. O/ p. h% T2 S& p
            ); progn9 R: C- {# v: W% F* H; L
          ); if1 s* ~& f* ^6 Z
          (if (= "Layer" first_point)
. ]1 I  k/ p- l" [1 i            (progn6 a# W: a% d* [$ T7 x, O
              (setq temp cloud_layer), a. _' M1 z2 \  k1 ?5 \
              (cond
" E+ N" \1 P+ x& v) M, Q6 O3 I- P                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"; @. {& u; f+ ?, `1 z/ |# q: Q
                                                          cloud_layer "> ")))
: ^& a, ?$ P) y$ Q                     "")
2 r! _0 K) H. y3 L/ x9 {! W; ]                  (setq cloud_layer temp)5 ~" ^' N) j2 F
                )
7 y8 }3 k4 x) b' z1 d& Z, e              ); cond& r# H2 o4 B2 w  |
              (if (= (cdar (laychk cloud_layer )) "No")
0 ]1 e2 V" n. L" f$ ?# p, N                (progn
& {  T* Y8 _7 @! O% M) ~                  (setq cloud_layer temp)
5 J  f) K) J5 y- I" C7 B) j5 n  J: h                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
# X8 s2 }6 y+ h: A                ); progn
# C& d, ]5 x. {              ); if
; i9 g& ?+ X8 a' J! M; }& m% Z0 G            ); progn
' C1 Y9 w$ Q% W. g2 L          ); if
# L- c3 f' L* G        ); while- b! {, q; C* {! o# k4 @! A- Q( y0 r
        (setvar "CLAYER" cloud_layer)/ \, U' k" f) X
1 z! ~+ M/ E/ {/ Q
        (if (>= ( getvar "LUNITS") 3)2 L% x4 Q  [0 H, ~' v- o9 q3 O
          (setq length_cloud (* 0.25 cloud_scale)2 ~0 _4 L+ h* F. x
                length_tri (* 0.3125 (getvar "LTSCALE")))
7 y0 X1 j9 j; z% P/ {          (setq length_cloud (* 0.3406890 cloud_scale)
# @7 s5 z* v8 H9 B                length_tri (* 0.438366 (getvar "LTSCALE")))  X7 f0 ]: ]( n2 N% ]6 ]+ t
        )8 R3 n% G: I) V! N" {
        (command "_.PLINE" first_point "A")
4 a2 P- E1 b2 l/ a+ d& E, d        (while (not (equal next_point first_point 0.000001))
/ Q8 `$ i$ i" Y( P+ N4 i          (initget  "Close")
3 \3 H: R8 g# k$ X- G9 @          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
# N' u" ^+ K  [) B( ^" w) v        (while (and (not (listp next_point)) (/= next_point "Close"))
+ e* z# k" n6 z" X          (initget  "Close")4 Z: l# s# P# p: F
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
$ v' Y" }. F+ U0 n5 z3 X        )
. Q$ E( P2 v: ?! u/ G5 D9 }          (if (= "Close" next_point) (setq next_point first_point))
  T, L/ k. c% O2 Q8 R: h9 @6 `          (setq angle_l_to_f (angtos (angle last_point next_point))( S+ j1 Q# U+ }9 A- |" I" h6 }! O  p
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
* k; |9 Y4 ~, p# i5 ?1 h7 }" W$ T          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)  @" S' o% r# K6 t
             (setq repeat_count 0)
/ }! x, E, H1 f  m& E7 q2 Q2 R! c             (if (>= (- repeat_count (fix repeat_count)) 0.5)
# i4 c- `! p; r  x               (setq repeat_count (fix repeat_count))
! z' c0 D* Q# p* r" i7 n0 c+ D; X               (setq repeat_count (1- (fix repeat_count)))4 A. E* K! W: d
             ); if
5 t+ Y. k3 ~% e3 l" L          ); if
; ^9 n8 K( f/ S3 J          (repeat repeat_count (command "A" "-100" relative_point))+ k/ y7 i" u7 }
          (command "A" "-100" next_point)
- ]4 ~5 H7 m) j& x          (setq last_point next_point)
, w" w' e5 R" M        ), @+ ], n. a9 f* n
        (command "")# R3 \' k7 g! ~% s- Q) A
        (if (= (type number_rev) 'INT)
& B! m  `9 J3 ?& n/ m           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
9 Z4 {( q9 z! A: y/ i           (progn
# P5 C0 B5 h. y' f6 f             (initget 5), d2 G; u3 r$ G
             (setq number_rev (getint "\n请输入版本号:")); e  Y; ^8 `) k; S$ Q. O
           )
  ^/ t1 q6 F- e0 k3 Q        ); if2 O4 e. H1 E: f9 X: S& `! l
        (setvar "OSMODE" 512)
( a$ M, t; [" }  a1 o        (while (/= (type point_tri) 'LIST)
6 M. W  R$ w1 s. z; o          (initget "Number")8 P1 G( T, b% s( e$ |6 T
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
! b3 b& N2 i* X3 u4 S. Y! t3 ?          (if (= point_tri "Number")7 p) T. j- X. b' I, V1 R
              (progn
0 |6 J4 @4 C" p! |                (initget 4)
3 D- |3 r7 j2 P, q4 I                (cond
. F3 Y" _" c8 q7 Q! J3 v! L                  ( (not (setq temp number_rev % [& }; E0 `3 q8 c+ |
                               number_rev- f3 L1 Y/ D2 h2 F  k& ^
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))0 y5 o* s. h( h1 x) T
                    (setq number_rev temp)
, A/ F) S2 ~) B. h4 i                  )! o# |& ?$ e4 M6 k: [# z9 X
                ); cond
, ?1 |. F# X+ ~- a( A% ^6 a              ); progn
5 F6 ?% m5 C9 ]& C          ); if
3 H+ E  O' c( R        ); while
3 j. c* t# ^2 z        (setvar "OSMODE" 0)
1 v# G; f/ _- Y# N% h- z# q/ G1 E        (initget 1)
' @0 k1 a: p0 D        (setq point_ref (getpoint point_tri "\n请选择方向:"))
/ s* j" V9 E# s$ T5 l4 @$ q0 J        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))* l* U2 D. r: l8 e0 X
        (setq corner_1st (polar point_tri
/ ?* n5 T9 h- P% r' s) [. _) J                                (+ 1.570796327 (* -1.570796327 dir_tri))% W/ b2 l$ l( R+ D/ T8 Z
                                length_tri% w, i- W/ Y6 T4 ?
                         )
4 B/ H) N2 t9 q2 v& R        )
3 c( _- H: ^0 A        (setq corner_2nd (polar point_tri
! {7 a: h$ L: Z$ K; a. K# O: q1 ?                                (+ 1.570796327 (* -0.523598775 dir_tri))
" y5 `7 M; l4 i                                length_tri5 t" O- r) G. L  Q* X: u
                         ), B1 W7 T( h* z( Z$ u' B) Q
        )' H: W% ^, y8 v+ d* g+ x
        (setvar "CECOLOR" "2")4 u, X! O. ?$ F1 Y8 c3 ^( n
        (command "_.pline" point_tri corner_1st corner_2nd "c" )# ~2 I" I9 P2 t/ W, T* w0 p# Y
        (setq textstyle (getvar "TEXTSTYLE"))
. K# f8 |' q) i        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")* h* M6 }: Y1 F4 I
        (setvar "CECOLOR" "7")" X9 Z6 T: I; {# m3 f/ Y7 s
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
2 O1 \& K  y# S+ S  W& {" i2 O! d                  (* 0.4 length_tri) "0" (itoa number_rev))
+ f2 P; X1 N2 i! }" ^' u! }        (layres)
; h$ I% G; L! G8 f: `+ [        (err_restore)
. l: Y9 l! X9 \6 T1 |. s, j        (princ)
  [6 D# F! z. ^4 y); defun cloud
' r% E, j8 m) s9 X$ S; f# p2 n
/ {$ ?1 X. A! F! z(defun c:cloud () (cloud))
* @% d: P% ?2 F9 V(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy5 z) R5 l! s8 z: r5 T3 @* Z+ r
;;;
! O! p9 I3 J# k3 r;;;  DESCRIPTION
- U) P# A, H7 s: M;;;     These are general error routines which can be called by 7 J% u6 X& ^. Q1 y
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference% S) i0 K" o: `; [
;;;$ ?: N8 t6 d2 l; w# u
;;;  SUBROUTINE INCLUDED IN THIS FILE6 K. t, l' ]3 r  b7 B% k
;;;     UNDO_INIT: r$ j$ C" R% {4 ^0 B8 m
;;;     UNDO_RESTORE
5 m! ]- n0 m4 }$ b$ E+ @;;;     VAR_SAVE
$ ?' q( m8 e% g0 M. t;;;     VAR_SET  % ^, P0 u+ `8 ?  z& L6 G& ?
;;;     VAR_RESTORE' Q3 I" N7 r" Y  l& i
;;;     ERR_INIT
9 C) y$ \. A5 K;;;     ERR_MAIN
, J* u5 D5 a& f. q8 x;;;     ERR_RESTORE# z1 w4 m* I- |# H0 ]. `
;;;
4 l* `, s+ b  |: L7 h1 p5 N7 H;;;  DATE: 10/17/98; 03/31/99
# @0 a6 S4 a( t2 s- t% z2 d;;;3 ?# k+ j+ r/ L) [+ X" W) C
;;;  HISTORY:
+ ], u/ F7 H& T! i) O2 O;;;    Add routine of mod_att3 }, @$ U5 q% }3 Z+ `, `
;;;
& M' m2 t  L7 j# W6 @;;;  USING METHOD9 e  K0 F; j8 v7 g# U
;;;    ERR_INIT:# N! _5 w! e' c' r
;;;      This routine initialzes the error handler. It should be called as:
9 W9 k1 C8 o  l, A7 w. h% U8 @;;;
: K. O* S' I( q;;;      (if (and (not undo_init)0 w7 ^9 [1 o, e) W' W! T: `9 k
;;;               (equal -1 (load "undo.lsp"  -1))
3 Q, c8 J- r5 h9 o& C' v;;;          );and$ m2 K& y# B8 ?8 r) W
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))7 M. `0 O9 Q" |4 d3 R
;;;      ); if
! U# u9 ?) A. c% W+ W;;;
) D6 N' t4 G* N6 M- |' Z; H* k;;;     ARGUMENTS:
' r5 |7 q1 Z6 S1 {2 ]* F, o;;;       err_init Takes 3 arguments.
3 a- n3 o$ u+ z/ _0 z;;;     1. - The first element of the argument:
3 v8 i2 j  f, Q, [5 F- W;;;          This is a list of system variables paired with
1 U7 K1 y( U- E8 S;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
; }2 g! f8 F: g;;;     2. - The second element is a flag0 ], j6 Y" [6 k0 n1 Q
;;;          If it is true, then in the event of an error / G5 M/ i+ ]* r) ~, _
;;;          the custom *error* routine will utilize UNDO " [: X9 B8 X( ]3 D; H7 T9 w
;;;          as a cleanup mechanism.6 s! E3 t# w: R2 b1 s
;;;     3. - The third element is a quoted function call.* O1 F2 f" M: }" Q; p' z6 t/ B
;;;          You pass a quoted call to the function you& ?9 g& B& |+ Q5 ?
;;;          wish to execute at the end of nomal routine if an error occurs. : w" m" w2 e' c9 y
;;;          i.e. '(my_special_stuff arg1 arg2...)
5 ^' R, \7 T: }4 S;;;          Use this arg if you want to do some specialized clean up
+ Q( |' ]% Q& g: y3 L7 c;;;          things that are not already done by the standard bonus_error 8 ^$ }" g2 t3 @. D
;;;          function.* U5 M: F, m6 Q
;;;
7 F; Z+ d- {3 t;;;    ERR_MAIN: Body of error routine8 _& r2 h1 x4 t
;;;. ^. B$ _3 q0 y) ?/ P9 b, v% O
;;;    ERR_RESTORE: This routine should be called at the end of command to) ^- N9 x4 n2 n4 Z/ {3 z
;;;           restore the VARIABLES, UNDO & *error*.
3 T/ C& t; U% J* G1 W- R;;;1 n6 w- z! m, H  h
;;;    UNDO_INIT: Initialize the UNDO status
5 X0 b9 T0 d! j$ r; T4 X;;;
% `% v8 r: M8 s& S9 ]- N;;;    UNDO_RESTORE: Restore the UNDO status% q5 u4 ?1 s- e) H* W% ^+ w( A
;;;& I4 ^. n3 v, Y
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")# T! E4 W4 D  [; S0 X! P
;;;4 q: `. W9 X1 `' \, M
;;;    UNDO_set: Set the variables. the argument is like; U! r9 f5 f: M
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))- p8 O" z3 U& o6 W' {
;;;$ D% P3 O, c# G" Z+ V; X; i
;;;    UNDO_RESTORE: Restore the variables5 ?3 C" l' e8 u" S- }# W
;;;0 D7 W. I" ?7 j3 o5 a/ e4 N3 c! ~
;----------------------------------------------------------------------------
( V# ?, a6 Z. l2 ~) I2 G& ~7 i;  GLOBALS:# Z* B  \( Q: [7 R" n5 b3 W
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)# L+ z4 @" c4 U( B4 ~0 x4 \+ D& Z
;     m_lst       -- list of variables (voided by VAR_RESTORE)
; y. M9 j  E2 O/ y- t;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or' ]- H# ]* ]/ q
;                    ERR_OLD)
( m# z. I: n6 b8 T3 D;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
# J0 v8 X  k6 M0 R% e* }: ~;----------------------------------------------------------------------------# N* I' ^8 F/ D4 r7 `9 f( @

8 P/ l# W2 z, r) f;----------------------------------------------------------------------------
' Z2 G) P4 S' z  P( N; T1 t& e/ ~! l; Modify attributes according to entity name, attribute name, dxf_item
: L- }! r& n9 j;----------------------------------------------------------------------------0 r& z8 R5 ~" x7 i- \& _) S9 J
(defun mod_att(ent id dxf_item)        + x3 F9 ~* H+ d- K" Z, y/ i8 Z
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))) _2 [( Y3 q) \
    (setq ent (entnext ent))5 Q1 q1 O% m5 w+ p5 D
  ); while  
+ M, n1 {' `. I" T9 I6 C" V* g  ((lambda (x)
5 a+ ?1 q" h; D$ L0 ?$ y' v        (mapcar '(lambda (y)
- v" o* h1 j+ ]/ Y. \9 s2 i# y                   (setq x (subst y (assoc (car y) x) x))$ O( j( b/ H' B) x7 k5 \
                 ); lambda
, Y5 N3 Q6 S" M- i7 J$ v, q                 dxf_item) }3 o, ^: X& s4 r4 t; P/ _! p& Q
        ); mapcar2 x# H$ v) N- D# e2 W/ v/ J
     (entmod x)  P2 ~/ m! c) ~' m/ I* N$ |! [
     (entupd ent)) d9 N3 |5 A6 ~
   ); lambda& q+ e( |+ @! u: Q8 W# G+ Q! S
   (entget ent)' ^* Q* G2 q8 ]# I, Y
)4 ^  b' k; Q* k; U9 Q0 C  m6 G
); defun mod_att
2 f- q$ ~* q2 w. t- E' |
( ^7 i* t1 I8 |9 X/ o0 e" @;----------------------------------------------------------------------------
3 p/ k! y6 [- F# f: d; Check layer status, return a association list which contains layer information. n) t0 ^" \- N% j7 i/ r: d* V
;----------------------------------------------------------------------------- L. `' q5 t. G- Z- l0 ^
(defun laychk(lay / l_sta)
1 K( X/ d* ]; |7 F  D3 Z5 c5 k  ( (lambda (x)
5 c' C" c% }$ ~% [: U6 i      (if (not l_s)
3 D+ G, Z; S1 u0 L. g" o          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
, j7 T- g! R1 t' B      ); if3 e2 d) b! E3 P1 F
    ); lambda
6 n3 V' ^- H/ d5 @    (getvar "CLAYER"): K+ y4 E$ y+ W/ H, [5 H
  )% C! a$ u' N$ J" W5 @
  (if (not (tblsearch "LAYER" lay))( W+ y6 \  A! g  n0 P8 D2 W
    (progn  , Y+ }" v* T" @$ Z  ?
      (initget "Yes No")
# e5 d3 a6 H1 z, E      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
5 |6 Q$ g( {. V+ H$ {. C        (progn
3 _% E4 T3 v5 [, S          (command "_.layer" "n" lay "")( p- |# A8 y# ^/ J' i8 B! [
          (setq l_sta 0)
( O( v% C, l" `# A/ k        ); progn
2 K1 ^* j$ _3 ~      ); if- n2 D+ I5 }" w* f
    ); progn
2 D- Y4 f) p9 t, _; i4 ]' Z/ ~    (progn) w' s6 z" H/ r' k  }
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
% {( p' p& N* h$ e      (if (= 1 (logand 1 l_sta))' J7 S7 `- T  @+ j) \* r
          (progn: k/ I/ h0 P) E. ~
            (initget "Yes No")
" x. `7 h  P- @! ~: F            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")( K) K9 E+ r$ B) T% z4 a6 a
              (command "_.layer" "t" lay "")
' a/ j6 v' @7 Y$ J: n$ P              (setq l_sta "No")
/ n8 M: I( Y0 R2 d9 a- A1 N9 `1 [             ); if
. A* q! K* ^! f          ); progn' o- {0 }' ^9 m/ b7 c7 R, U* Z
      ); if6 `! n* i7 H6 ^4 J# s- F
      (if (numberp l_sta) 4 |- G# o1 w  c+ |) C
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if1 x& `- A# S* h) v
      ); if$ e, y! }5 I9 X; U
    ); progn
' s3 z0 `  D' n; I' |  ); if
7 k! H. t3 B6 r  H! J" k* ?) m  ( (lambda (x)
; \+ F$ _  U1 R3 `2 `6 j, [9 y- C' N      (cond 6 S" w+ A) X# F8 |) |- l
        ( (not x)
8 s2 X8 Z# w6 C$ \2 h          (setq l_s (cons (cons lay l_sta) l_s))
3 G/ H. j) f2 \/ G0 Z8 x9 s        ), `# l. o# m; q7 s/ t$ T& C  v
        ( (= "No" (cdr x)), G  A8 G' u" h) c& O
          (setq l_s (subst (cons lay l_sta) x l_s))
1 |# v9 u. O. j( N# d8 r        ). i; w, W( P6 j
        ( T l_s)2 o9 T! E+ i+ S) i# m0 ?& p9 s$ u0 F
      ); cond  w; C+ a5 M2 @8 h  I1 t6 V
     ); lambda
. B% u* L+ C( W# m     (assoc lay l_s)
; d3 `+ P, y1 S7 f# `  )% y/ O5 L! V$ Y3 i: s3 J, y

" A8 n7 X8 R7 K- f4 b); defun chklay
5 R' s! T6 T* X1 j
0 ~4 J) Y; c6 Y8 D. ~;----------------------------------------------------------------------------! p' S* g$ |, M/ K
; Restore layer status according to association list l_s
9 b1 k  w7 e5 N. p;----------------------------------------------------------------------------
) C) v- \0 A, |- K; S(defun layres()
4 u/ \* o5 P' q8 a- B+ z. ^  (setvar "CLAYER" (car (last l_s)))
5 T, P' ~0 \9 `) d( j( o  u( i3 @9 p  (repeat (length l_s)
( ^8 z7 ~. v# o$ n9 J    ( (lambda(x)  
9 X& x0 M% k; _0 Y! J" [8 _        (if (numberp (cdr x))
! j, }1 x/ B- O1 z% C          (progn
3 a' U  }) m# T            (if (= 4 (logand 4 (cdr x)))% \  o% J7 s; s
              (command "_.layer" "lo" (car x) "")
- H" I5 i0 z' h6 ?  F  \' ~            ); if
  _3 g& A$ @7 B, t            (if (= 1 (logand 1 (cdr x)))6 }+ ~% n+ H) @6 E
              (command "_.layer" "f" (car x) "")9 K; a! q3 \# Q- T( [$ c  M" A4 [
            ); if
) M% G) F4 c, k6 H1 ]4 b' b. j          ); progn/ G9 U$ K: T$ r! O' ~' T9 ?( d
       ); if  
$ f3 l/ `+ E  q( w3 V      ); lambda
" @: C# t7 Q- Q/ m" `% ^( U      (car l_s)$ a# C2 c, s$ W! E- j' y* c
    ), m" S- W' H0 h, z% C% u/ d/ q; L6 e0 p
    (setq l_s (cdr l_s))- Q+ I3 b! ?+ A( }
  ); repeat; e# h7 _9 j$ P5 d/ E
); layres
) _  a) g+ S8 ^) B: R/ @' D& X6 c# y7 K9 f5 I2 v6 B) h0 ~
;----------------------------------------------------------------------------7 W: {  F; J! `/ k% e
; Get DXF codes
6 A" Y9 ?- ~! B1 a;----------------------------------------------------------------------------
' Y" O, w7 L  X1 P(defun entgetf (index ent)! c& D) k7 d( H8 @
  ((lambda (e)3 W' {7 c2 f5 C/ w, d: F
      (mapcar '(lambda (x)
2 A/ c! |$ |0 D: k6 @7 x+ p                 (cdr (assoc x e))4 C9 R2 r) \) [& i$ O. q, F' s2 v
               ); lambda3 Z, U  _: J5 U5 P. v/ V
               index) ; internal lambda function" l: [# Q( _7 O! {% X  T, F) d
    ); lambda
9 k7 g5 _* ^  N" Z& P0 Y    (entget ent)
* ~  M; f+ \* u7 w  )2 E8 P% ]* x: g
); defun entgetf
. }! g9 @. K+ {9 b; X* X5 D' v" Y% m: V3 M, N; h7 x6 x4 n; N
;----------------------------------------------------------------------------5 |% h) a! ]$ x7 T
; Save UNDO status) F1 L. g# A5 |, K) H: P; v# a$ n
;----------------------------------------------------------------------------+ h& o: j; ~# g0 o
(defun undo_init (/ cmdecho undo_ctl)   
  C" q2 z0 `4 B3 U  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
* U$ ?, W6 L  m$ r5 [  (setvar "CMDECHO" 0)& q( H7 w# i- K1 t

4 m4 E; U! E  Y. _0 W$ W  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable/ \( g) R- ]! M7 u0 `
    (command "_.undo" "_all")
  d1 I. Z5 Y* ?    (command "_.undo" "_control" "_all")
: E- q9 o* |6 x: K  )/ E% n, `2 y, w

$ B1 c3 {" @" f" A8 H3 @. J4 L  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off' y7 e4 [5 `; f4 ?# q) r. @
    (command "_.undo" "_auto" "_off"), Z* U; x: j6 t; [
  )
. A, m8 Q1 ]* W) C4 ~0 I6 s0 S
, g! @9 H) i  X. Y* N# t7 F  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
0 b0 I% M5 T$ u: R" b$ \7 g    (command "_.undo" "_end")
( d2 c$ D4 t% D1 a5 K3 I: T0 Q  )9 u5 D6 j2 f9 k  @0 \& m; v
, ?; Z8 I) r4 ~
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
7 e8 l+ H- l$ D% M0 _    (command "_.undo" "_group")
( L5 V; ~0 R% L3 Y( M  )
" R+ p8 O& j6 J: v/ g7 U
9 i. E# [  Y7 D; C  (setvar "CMDECHO" cmdecho)
0 Y4 c. k" q& b! M' x  undo_ctl
" F4 @! s) S" m- E); defun undo_init
% m6 }( a1 _* j
6 S: q( i  K; n& L+ m6 P9 e7 g;----------------------------------------------------------------------------
6 P4 j  y! D1 g' h; Restore UNDO status
$ {0 x: m0 V! @  ~- \$ v;----------------------------------------------------------------------------
/ h. e; W& b! q6 b/ e/ z7 i" f(defun undo_restore (/ cmdecho)3 l& v( Y4 A8 o7 T$ P" X; Z
  (if old_undoctl
( _. o9 P/ Y! R- K    (progn# k' O; @4 t, j& P2 T
      (setq cmdecho (getvar "CMDECHO"))& Q: q' }$ E& I8 b& a( H
      (setvar "CMDECHO" 0)! o, P& p6 m8 k! W

: j3 a' j% L# g0 v  g8 b$ y      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
4 t$ G9 l& z3 x+ R- p      (while (equal 8 (logand 8 (getvar "UNDOCTL")))' k& q8 v$ ~5 P9 A
        (command "_.undo" "_end")0 y" o$ r, E5 m" ?- k
      ); while
6 T4 ^& \$ X  B/ Z5 Z! K5 B
( w5 [! W! a$ w3 f" u% V
( \% M5 M6 E. Q; K* {% ]      (if (not (equal old_undoctl (getvar "UNDOCTL")))
$ W9 b3 M, ~  \1 Q; t2 b0 ~4 J        (progn
, W2 R5 @. y8 j5 n          (cond
8 E  A8 F0 M) V( V7 p            ((equal 0 old_undoctl)6 ?& k; Q2 P( @5 ~9 R# m4 T8 B
              (command "_.undo" "_control" "_none")
, ^5 Z8 y: Y, T* p$ M            ); I5 L  |4 b1 B
            ((equal 2 (logand 2 old_undoctl))
5 c1 p; x) m! z7 j2 X              (command "_.undo" "_control" "_one")
  |% w9 a2 F! {. x: y9 `/ u            )3 A$ q2 k6 r( j8 a2 w
          )
5 S5 d/ E9 K/ `! a          (if (equal 4 (logand 4 old_undoctl))6 t9 l0 o2 N, U0 d- z6 B2 M7 i
              (command "_.undo" "_auto" "_on")
( t8 B' g% w& b              (command "_.undo" "_auto" "_off")9 {% W- S0 ~1 h# x9 R# s
          )
6 N3 i  |) G  T$ ?6 }- }        )+ n. n# q8 w" ?2 J4 E
      )
& k2 j0 B& }1 ]/ x; y& Y5 A      (setq old_undoctl nil)) t' \2 f3 O9 V6 `8 y2 {
      (setvar "CMDECHO" cmdecho)( y0 r1 A+ ^6 Y7 p  c, X
    )3 c, {5 L; u" {0 b- @; `5 k! w3 n6 ~1 B
  )
0 ?8 D3 V9 j2 Y) Q, \. {); defun undo_restore
& A5 W* Z  S/ R0 ]- j. y; t$ J3 n4 h5 b0 f* W1 R
;----------------------------------------------------------------------------
8 _1 u+ W4 ], n. e0 @4 o; Save variables
8 U$ t) F- {7 j+ f7 i. k;----------------------------------------------------------------------------
- f$ {. H0 X  p' n(defun var_save (a)0 }* D/ p) i- G! ~
  (setq m_lst '())* P6 Q- s, R5 G, f! F: ]4 Y
  (repeat (length a)
' E" F( s/ z: i& A2 c    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))9 }9 X4 m; }# {% e9 O* _) l  z
    (setq a (cdr a))
+ r7 |. t: ]$ N% @5 U$ j, ]7 f  )* Y+ ^- K/ M* j
); defun var_save
. C1 [+ d# s+ c# [$ N2 X0 k& `: |- l7 q0 ]
;----------------------------------------------------------------------------
6 x# B% G" D- |' q& A; Set variables$ X+ w8 i7 {" q- u1 S5 W; D
;----------------------------------------------------------------------------+ ?; e: a* z0 m. n
(defun var_set (m_lst)3 \7 x0 e  X) q* g; u
  (repeat (length m_lst)
" A6 j1 Y+ ]; n8 J, \" c2 g* d    (setvar (caar m_lst) (cadar m_lst))
8 J4 V! i0 R( q0 }* t7 {6 t/ F9 c, X* T    (setq m_lst (cdr m_lst)). d7 O$ V% e3 S/ m* \4 g- E
  )
9 ?. U9 |  t, r. q; x+ H$ `) w); defun var_set- |; Z; W; m' E4 v
3 K/ q  Q5 B4 e( u# e. I( \* A
;----------------------------------------------------------------------------" ]. C% f- F/ q0 \. I0 S  b
; Restore variables
  g1 x4 z7 }- m) j8 P/ `;----------------------------------------------------------------------------$ H0 l4 O* {0 r$ O' F& h& _% E
(defun var_restore ()8 N2 k0 U9 d1 ~0 [
  (repeat (length m_lst)& j6 V! {) P: y$ E
    (setvar (caar m_lst) (cadar m_lst))- ]6 u+ H% g/ s, d8 O
    (setq m_lst (cdr m_lst))  R- r6 x0 s" m% x" E6 t0 d! |
  )% z' H; ]0 v. b& {6 V4 E
); defun var_restore2 W# }$ {# q5 W6 n% C: s
9 g$ u& ~: H8 t4 w
;----------------------------------------------------------------------------$ D6 e: ~7 \0 W* a" C
; Initialize routine
' d$ _# B; {7 ~; C7 M9 m4 @( y;----------------------------------------------------------------------------8 U! o9 i3 p9 A5 m8 m
(defun err_init(e_lst u_enable add_fun)7 b4 j. `& b- \6 b
  (if err_alive (err_restore))          ; To avoid nested call
6 j3 n+ u2 [% `% {  (setq err_alive T)
7 X$ k( R+ V/ \7 M8 \  (var_save e_lst)                      ; Save the modes1 [! w8 S  G# {
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status
8 {2 i; J+ y( o! ~* ~3 f  (setq err_old *error* *error* err_main) ; Save the handle of *error*
7 y# M+ q2 I9 ^- r, u2 p: q  (if add_fun                           ; Add the user cleaner
0 e3 N2 p; E8 I, D    (setq *error* (append (reverse (cdr (reverse *error*)))* w/ D4 _! J0 W$ u$ q
                          (list add_fun (last *error*))
; Y" A6 ?9 v( ^3 T6 G* k                  ); append7 j" j8 [/ V: |* F. F# C9 B
    )! q  h" E. Z$ @0 ?1 p0 F& N: Y
  )
1 f2 u" Z, g6 Y* j' {# C0 W); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------% \5 w2 D5 q; G: B5 w
; Error routine body2 F; c3 V- H3 a9 Q1 M, Q
;----------------------------------------------------------------------------1 P4 O; y! Z9 {: U
(defun err_main( msg / )                ; Body of error routine  P: [9 G+ w0 R' `' U3 h
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs, `5 v0 m% z& w1 s8 y4 }: F7 i
    (princ (strcat "\nError: " s))      ;while this command is active...
' W# C' [' v/ _; S( R/ U5 w  )5 ?6 ?, [' n1 o* s( p% B9 [  h
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
( L5 B& a# |6 O; }9 c0 L+ q" n" I0 p' h! e
  (if old_undoctl* v5 l7 i$ v9 X8 G- x0 W
    (progn0 m1 r3 W4 u* t
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
: C* x! `* d# i. s        (command "_.undo")              ; if it's in UNOD command
1 I0 {( x. w0 J( B      )# H" K4 ^% K- c9 N5 `: E
      (command "_end")
% T3 z. ^$ G0 P  X" z. m7 w' }! X7 }      (command "_.undo" "1")
( d3 l3 I" e- h7 ^. l: B      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
$ y+ q8 ?4 J6 c9 p! O      (undo_restore)                    ; Restore the status of UNDO+ U: t9 s5 i  }2 R4 b
    )+ v( A' t  }9 a2 t- m$ i) u% {; ]
  )% a) _! S1 ~  @: }  v7 I

5 Y8 t5 |! W  x: s* p% f' `  (var_restore)                         ; Restore the variables
- u( Z7 b$ j5 L' W' F% J  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
. g8 j' y9 {, K& b  (setq err_alive nil)
, c6 |+ g0 ]4 J# |! y& U; `6 z  (princ)
7 \( z& F' H: J); defun err_main; s/ s% T& G- G0 ?. j8 C
' g+ t: ?# T/ u: y. D
;----------------------------------------------------------------------------. R4 @  T/ D3 h! P1 p& a: y) M$ P5 N
; Restore error status. {/ \3 J2 F0 B4 J' O
;----------------------------------------------------------------------------  t5 ^5 m4 M: o( r
(defun err_restore()0 y9 I0 ]) N4 h7 R" U- o  a
  (undo_restore)                        ; Restore the status of UNDO
4 o5 |/ O: D- b2 G4 ?* K  (var_restore)                         ; Restore the variables
, {( d+ s' j" ~2 n  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error3 r" ^- [1 E' c" v
  (setq err_alive nil)& m5 ~' Z0 _9 g; k
  (princ)% k( b' {8 E( r/ K9 U
); 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-10-17 13:21

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

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

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