CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:" r& t9 H4 B* c! H: z7 V
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”! D6 H* u+ u# l1 A$ w- ^4 h! H
提示:加载成功
7 i" i- T# q, O( [然后使用CLOUD命令,7 Q1 _" |% O" a, P  c
提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
& t9 }) M+ [% Z) w$ ?# _请高手指点一下,这个是怎么回事?应该怎么改正?
4 C& F# c' f4 u% u! t这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx8 S" G9 _9 o$ k$ }
;;;
0 y7 e/ |% c" Q- Y;;;  DESCRIPTION
; [! D0 _' m% b1 ]3 O6 p8 V. I;;;     Draw cloud and you can specify the globals variables listed below
0 n" F* O  I6 U' a9 l! C;;;     to decide the characters of cloud: n$ F1 j6 n3 V+ \7 o9 b1 s) e
;;;
5 I2 F3 c# H" S# k;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98( K$ D9 n% U! Z4 K4 h5 q1 e
;;;
/ d0 e  n) ^& |6 l$ g8 F;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
6 |$ P) w- G' f# t9 ~* ?2 t;;;           Change CLOUD.001 to use CLAYER to perform the same function7 [* D- ]  h* J) H9 r! N/ o
;;;           Use the common error routine UNDO.LSP to optimize this program
$ a7 k" f$ |! P1 i8 u' `: S;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE/ u* j7 {1 \$ Z  h
;----------------------------------------------------------------------------
0 A, C& C+ P5 E, n$ p0 H;  GLOBALS:
5 n7 c$ y" M3 O5 ~4 e;     cloud_layer -- layer of cloud
. j1 r* _9 |& f6 b' q: V8 ~+ V;     cloud_scale -- scale of cloud
5 K' _2 k# v% O, A7 K: _;     number_rev  -- revision number  G" I% I9 v7 l. `5 T# D9 @
;----------------------------------------------------------------------------
" A# V, C& ~  {8 T' v5 B- e(defun cloud (/ locked temp first_point next_point relative_point' S# f# {) b# o  n3 r7 t
               last_point point_tri point_ref corner_1st corner_2nd length_tri9 J# N1 q! H  b( ~
               length_cloud angle_l_to_f dir_tri repeat_count
6 B8 m0 r$ e7 i: J               table_cloud )
; u6 a4 b7 ^9 Y( x        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))# e* g* w3 W. C0 Z3 ~3 K" `$ `
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
: t1 Z2 D* x5 X! L        );if
; @$ f) ], i5 Q; A3 R2 Y        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"5 ^$ P4 d1 B- F
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
7 G  B" z+ G* V( d" \% L! R        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
) X6 ?5 T! [  @6 Z5 x% K                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
4 `8 \' |2 I: R" @/ L5 ]
, A" z1 _2 x' O        (if (not (numberp cloud_scale))
- {: ~6 K" ?  Q' l, e! l' X            (setq cloud_scale (getvar "LTSCALE"))
( K. s9 p/ Y8 p7 S; D; U) ?        ); if8 B3 \, @/ Z3 O8 r. c( r2 `
        (if (not cloud_layer), M" c( K# [1 x1 Y- J+ {
            (setq cloud_layer (getvar "CLAYER"))
& f8 b+ o4 t6 T. {( r4 G  p* |        ); if* e1 n7 ^/ A# l+ O- W1 K8 R
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
& T0 ~) V% U: E$ \* l* \        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))& u6 q6 _: o6 I+ A
        (if (= (cdar (laychk cloud_layer)) "No")
7 _- _/ R( Q' Q          (progn
/ b) b4 v, w$ \            (laychk (setq cloud_layer (getvar "CLAYER"))), O; F9 {$ [7 m9 E& Z0 y) t/ l9 T) Q- F
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
- [7 b3 M  ?# p. Y          ); progn! x; A1 T5 w2 Z$ c
        ); if
6 C- F/ {7 G& J9 g5 ~& @2 H! B: i& N6 |2 ]5 T+ L- f0 l# ?+ P
        (while (/= (type first_point) 'LIST)
0 X/ s* {* E/ X7 P- @          (initget 1 "Layer Scale")
8 L& O5 I5 o4 Q          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
6 W* x3 w  P3 O: Z# }5 x          (if (= "Scale" first_point)      $ `0 f6 F/ m  h" b* W% l* b3 q9 z
            (progn1 ]6 }4 c' Z% s* O) a% v; r
              (setq temp cloud_scale); E! S* @. G; ^( m
              (initget 6)& n0 g9 ?  R. P# B, S( Y5 ]
              (cond/ t2 x+ u' C* B; C7 K
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<") }7 K* ^! Q% Y1 q7 O8 b- R; j
                                                          (rtos cloud_scale 2 2)4 ?* t9 l" e1 o; J0 k
                                                          "> "))))3 j+ l+ ^3 I$ ?) _* g7 z' e/ r
                  (setq cloud_scale temp) )/ ~9 z* \9 [) ]6 J
              ); cond' a9 ^3 h: [( r7 c" ~" e1 R! }2 x
            ); progn
  K$ m: ?/ j7 O; s; B& O          ); if  C- ^3 ]! v9 @4 s) ~. B& Z. Z
          (if (= "Layer" first_point)! k& J3 t7 ?: V9 P; {3 R  |/ |( F% k" B
            (progn. Q$ ^' Y6 a: m  A( F+ K
              (setq temp cloud_layer)
; i5 s9 |  F+ E8 t/ I              (cond# {* W) j: q. `4 [' `
                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
+ `5 |: t# F; m3 q% ~1 }- w# ?                                                          cloud_layer "> ")))
0 E: q' d& r  N2 K5 Y: l                     "")
+ M$ I# m" G$ F2 a' C                  (setq cloud_layer temp)
: ^  s- w: ]5 {% a9 D( G                )
4 T- o: s5 F$ l9 \$ F' {( G              ); cond& I" n8 h2 J3 L, ^/ n8 t0 |1 w/ d
              (if (= (cdar (laychk cloud_layer )) "No")* u1 y8 r% H, q8 e1 k; s/ o
                (progn
" \# s, M0 ~9 |  ?  b& S                  (setq cloud_layer temp). y6 d. x. z; F
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
" z! d0 R* v. j% M+ p: h9 D- v                ); progn& c8 v6 p+ F. v9 N/ j
              ); if9 J7 J% l; h2 l, Q1 o
            ); progn
1 ~5 ~% B0 H' U7 I) u+ }; P! i          ); if0 s; _8 \9 \/ C; K0 J
        ); while0 P! U% [) m# d" l
        (setvar "CLAYER" cloud_layer)
2 r4 h( C( |1 t! L
! d2 x: r3 _& `  {5 z1 U        (if (>= ( getvar "LUNITS") 3)
% A9 K  e5 W/ g1 }8 V- h& G) q          (setq length_cloud (* 0.25 cloud_scale)7 k5 \9 y: g0 a  L7 S
                length_tri (* 0.3125 (getvar "LTSCALE"))). Y( b+ e, W8 [+ s1 t
          (setq length_cloud (* 0.3406890 cloud_scale)4 j9 s) B3 r; A' g/ B: G: x
                length_tri (* 0.438366 (getvar "LTSCALE")))2 @# Q: q( z9 z6 r+ z
        )& O4 z8 E; D0 p0 W
        (command "_.PLINE" first_point "A")) m# s3 n' G; F- v6 X+ @% S
        (while (not (equal next_point first_point 0.000001))
5 F! i/ A0 l. V3 c          (initget  "Close")$ l: V5 {9 g# T' U
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
7 B# Q& Y: n7 q, D3 O: X        (while (and (not (listp next_point)) (/= next_point "Close"))
, b# G' G5 Q+ Y& L: b          (initget  "Close")
/ J5 x) `9 M0 P9 ~6 o0 v. f          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
& k, {9 Y) S: g& g" q: I$ z2 a  _        )
' E5 }8 ]* |1 M6 h7 f          (if (= "Close" next_point) (setq next_point first_point))
' E/ Q$ |$ R7 X( A8 Q          (setq angle_l_to_f (angtos (angle last_point next_point))( q9 i0 V5 Q8 r# r5 V* |" P$ x* G. z) C
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
; C6 [6 [4 }0 s2 y, `# T( J" R4 d- U          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)+ i9 J" Y1 ?8 ~5 b; d
             (setq repeat_count 0)% j1 Z- U; R6 z$ d1 t3 w- K
             (if (>= (- repeat_count (fix repeat_count)) 0.5)9 u' V1 h; s4 j( z3 `% `5 j
               (setq repeat_count (fix repeat_count))
5 W( r5 t. b+ ~/ o5 X% b               (setq repeat_count (1- (fix repeat_count)))
7 c+ M( b$ C! l             ); if 7 i' t! K& ]8 d9 f
          ); if% }0 P* [, R  t" J1 X/ B
          (repeat repeat_count (command "A" "-100" relative_point))
8 u6 `% D7 T3 E, e+ o- u          (command "A" "-100" next_point)) P- G5 r( X) v' _4 v4 [
          (setq last_point next_point)
; C. y/ \& [9 ~        )
' `$ z: |0 e/ ~3 d; f  ^% ?, ~        (command "")& P: Q4 n# ?' ^3 N5 u
        (if (= (type number_rev) 'INT)9 T! f. t* O: Y+ S8 n& z
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
& {& e4 O' N8 ~' S; J) K           (progn9 O1 s. c+ l+ w  c* j% X* o' [
             (initget 5)6 z$ k* o, x' d$ k0 F. `* e. \
             (setq number_rev (getint "\n请输入版本号:"))
+ t9 d- d3 p2 j! `           )
" n! O7 K* S6 R9 l- p        ); if
) b9 R  N/ s2 l        (setvar "OSMODE" 512); v. C2 j; f7 _
        (while (/= (type point_tri) 'LIST)& Y2 @' G8 S6 i2 Z0 @
          (initget "Number")
- ?! A8 U! L* S" h2 Z2 I, n          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
9 L! Q4 y$ O9 j+ L- j# _, ?' ]          (if (= point_tri "Number")
# E/ h. Q  y5 [% i              (progn
9 Q; V) U+ i! X0 E2 X! X                (initget 4). u9 I% a- w: M+ j# Q8 T
                (cond9 P  x! v( t# t: `. ]
                  ( (not (setq temp number_rev ! M) L# l" a! g2 n+ L/ p, E6 o
                               number_rev
1 o/ M2 T( h1 j                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))9 r. R) N8 v: Z
                    (setq number_rev temp)
8 n( G  D& n& b. C* w6 o                  )
( N' c4 y& I4 [                ); cond
& A) ?8 l9 n# n( W' k* N              ); progn0 C  u  P0 i+ `  N) a; X
          ); if2 X5 r% j8 N, S! q& Q: k2 t2 S
        ); while
' e' X  x% |0 B+ Y5 ~: [        (setvar "OSMODE" 0)
+ b: R% }9 I, A* h7 \        (initget 1)
% v! T  J# v% ~" l3 H        (setq point_ref (getpoint point_tri "\n请选择方向:"))+ I; m7 A1 {# i' v# b% C# {
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1)); i: Z, i4 B2 Y  t
        (setq corner_1st (polar point_tri
, `( P" M8 z( M1 f                                (+ 1.570796327 (* -1.570796327 dir_tri))2 N' G  E! \/ X) o$ n+ ?* Y4 N
                                length_tri
9 i7 d3 g0 v) _0 u* |& V8 A+ n7 x" Y                         )& F: v' \1 I6 w  c% Z. z% n
        )
. s$ \0 P1 y) Z. b3 K$ @' @1 T. p" W        (setq corner_2nd (polar point_tri
( n7 d: n$ k# ?                                (+ 1.570796327 (* -0.523598775 dir_tri))& g7 ]( ]: B, Q
                                length_tri, c& c" T4 }+ j' O& p1 k9 V
                         )
" _. w0 h: i: k1 ~8 ]& M6 E        )& U/ x" a2 N9 E4 f) D/ p% I
        (setvar "CECOLOR" "2")4 z$ t6 W1 a& n% i3 A4 _
        (command "_.pline" point_tri corner_1st corner_2nd "c" )9 r+ D/ E9 f$ l
        (setq textstyle (getvar "TEXTSTYLE"))
  I! {8 \" x3 L2 v: u. M% N        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
% `- i' C: _, r- h. S        (setvar "CECOLOR" "7"), v& d+ c: C, J, V; f* I; p
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
5 U1 v9 ^+ X# }4 i4 f/ @                  (* 0.4 length_tri) "0" (itoa number_rev))' S, _; {- W: Q" G8 Y, v
        (layres)
- K2 c1 k. L- L( s5 E        (err_restore)& b/ H/ u+ \: W  u9 ]
        (princ)
9 a- _  s9 }+ `9 w. b2 @); defun cloud
; o4 R' s  c. y5 N7 L: `' T3 h
1 K6 x+ e# b* y9 [( N/ O% b(defun c:cloud () (cloud))
  Z$ e  Y% R* x$ o6 A(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
8 N9 v$ m" X* I0 a; M1 j;;;
# \7 a' G- ^/ N( R# q;;;  DESCRIPTION
( p7 l+ f+ M% c, \;;;     These are general error routines which can be called by
* v. P$ X+ v& q;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference& Q1 r" h+ C* A1 Y% z
;;;' U- Y5 E9 w" c# Z2 z6 [6 `
;;;  SUBROUTINE INCLUDED IN THIS FILE
' {8 [# {& M4 w& n: E" r;;;     UNDO_INIT) N+ q6 J% d+ E& P) b3 r3 _! P
;;;     UNDO_RESTORE# `. _0 s9 E- Z: z6 V4 N% A
;;;     VAR_SAVE
' K5 b& D! ~8 r1 Z$ ~6 f;;;     VAR_SET  4 x  R3 B: r2 N: Z
;;;     VAR_RESTORE9 g( i9 T9 j7 }3 u
;;;     ERR_INIT
$ e+ C, E0 ]  h' |) D& A7 v;;;     ERR_MAIN " J) f& U" d5 F+ z+ r+ c
;;;     ERR_RESTORE1 z  `. h/ h+ }: |
;;;
' z# X! J/ m1 `- x' Z0 @4 ?  b;;;  DATE: 10/17/98; 03/31/99
2 e( v% j4 E: K, Q5 X;;;" `1 d1 E, u0 }0 @
;;;  HISTORY:
0 h$ }. _7 ]) z4 g2 W# @;;;    Add routine of mod_att% ]7 \3 e9 M6 m2 K1 q
;;;
# l5 m% ~& Q/ Q3 R- j8 ^6 Y;;;  USING METHOD# ?6 U$ V: A8 i
;;;    ERR_INIT:, T* ?# \1 [, [. e" k, d. I& ^' z
;;;      This routine initialzes the error handler. It should be called as:9 _3 ~" I8 j- j5 l/ p% V  E) E3 p
;;;; n0 |( m1 s$ r9 X8 L# u! e* s
;;;      (if (and (not undo_init)9 ^: S: j' @" [7 r. {
;;;               (equal -1 (load "undo.lsp"  -1)) ( N9 P/ y/ {+ Q; I) }; _7 l
;;;          );and
4 t- w& M4 a) \+ x1 P" I;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
6 q" \# n2 P0 I' Z. Q;;;      ); if
4 Y! K8 s' i0 U* e, |( h5 };;;
3 t' C3 d! Q2 _;;;     ARGUMENTS:1 G8 y* F/ L; {* [3 }
;;;       err_init Takes 3 arguments.
; q* K# Q$ k$ s, y; };;;     1. - The first element of the argument:
7 Z& |- G( i3 j) t- z: ]. X( i;;;          This is a list of system variables paired with
9 o6 i) ~; q. [3 l;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
% u( Y2 ?9 F; U. w, S9 M;;;     2. - The second element is a flag
+ u- \/ Z, O1 x;;;          If it is true, then in the event of an error & Y# D& \  m% q3 O7 t
;;;          the custom *error* routine will utilize UNDO - ?7 V) b' y% U6 ?
;;;          as a cleanup mechanism.
& M( J- u+ n6 I+ t% H, O0 L" T;;;     3. - The third element is a quoted function call.
: T, E) ]  C5 f) u;;;          You pass a quoted call to the function you0 L4 G3 z+ J! h! ^
;;;          wish to execute at the end of nomal routine if an error occurs.
- }! k2 ?/ ]3 M& ], A;;;          i.e. '(my_special_stuff arg1 arg2...)
3 `' ~# G# ~# t+ d, _$ z;;;          Use this arg if you want to do some specialized clean up + }8 p/ n  r: w
;;;          things that are not already done by the standard bonus_error 1 Y4 H; z5 }, E0 G3 n9 b; s& R3 P
;;;          function.
9 M; ]9 s& k0 Q;;;' u  V; k6 w9 `+ i# H% a3 L
;;;    ERR_MAIN: Body of error routine
: ]/ J4 `( m. d7 K6 Q* K5 a5 R1 d;;;$ R/ R5 o' s5 L4 C8 p, O9 {6 p6 N
;;;    ERR_RESTORE: This routine should be called at the end of command to
1 y! k. D: W8 g* @2 c$ q;;;           restore the VARIABLES, UNDO & *error*.
) X3 F/ h- N( v# a# y) s+ x2 L# V;;;
' f. I8 x! z1 O8 `7 t;;;    UNDO_INIT: Initialize the UNDO status
+ C$ m5 `- k! y& b7 a;;;- J/ c' D$ t" w  @: T
;;;    UNDO_RESTORE: Restore the UNDO status
1 }3 y4 J4 d) e;;;2 p" R" [' ]+ _
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
$ {; a! B- c& R1 Y1 J;;;
7 I' U# }  e! `, \" ^;;;    UNDO_set: Set the variables. the argument is like
' m$ q2 ?: X, v9 v' b1 ~" l;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))6 y( y/ H5 `! t; ^0 \
;;;8 ]% k2 d5 e; Q& t
;;;    UNDO_RESTORE: Restore the variables0 `8 B/ _( Z2 H7 p
;;;
6 ~: n3 B* a6 |; Y0 i! U;----------------------------------------------------------------------------9 @' C7 k! v" |( o' m
;  GLOBALS:' B# ^: d$ z+ T( q8 w
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)2 t7 f. s! @9 C
;     m_lst       -- list of variables (voided by VAR_RESTORE)$ x$ ]# a; K" u" U# ~. y
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or- z. q3 \3 L0 ^7 `& i9 z
;                    ERR_OLD)& e( j2 k2 _0 h5 p4 ^
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
7 E# Z! \4 E' };----------------------------------------------------------------------------6 }7 G1 G" z  V) C4 w2 ~* j7 I

8 U5 S8 g7 z: C- x9 O;----------------------------------------------------------------------------% T% o6 ^- `. i' R9 F
; Modify attributes according to entity name, attribute name, dxf_item
' u2 d/ K' U' w/ M  Y( a; B2 K;----------------------------------------------------------------------------
; y7 O1 n/ t* i(defun mod_att(ent id dxf_item)        
0 q9 t+ e! e" t' M  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent)))). Y7 e0 x0 I' R" `
    (setq ent (entnext ent))
9 U: c8 s/ [# D* x. n. Z  ); while  
0 j  P6 L( t- M$ C: q# Y. _  ((lambda (x)
3 o8 P9 L  j% F0 W: w* i# z        (mapcar '(lambda (y)
: F% B0 E/ t0 f* W                   (setq x (subst y (assoc (car y) x) x))  I! D. {) V9 x( }
                 ); lambda" g+ F; j4 c+ }+ I
                 dxf_item6 o) z- {; U) }* c/ u, w3 p2 l3 P
        ); mapcar
/ i! M5 E! n4 s! i. P) V7 l     (entmod x)
2 Q- S$ }$ t; h% z% ?     (entupd ent)
# v. P2 {% q; O   ); lambda
: J: b( o/ l; g   (entget ent)' j9 v, U: f$ X' \: S1 l
)
' [; o/ [: A% [  F); defun mod_att4 A" [  U. f+ n0 h' W$ g

& o, |+ k1 v0 A# ]5 D3 };----------------------------------------------------------------------------3 l1 w5 y  _7 h( ^8 V9 F7 G
; Check layer status, return a association list which contains layer information6 C2 J/ v; X- T9 L) ^. h0 I$ L
;----------------------------------------------------------------------------
3 i, \8 {- q6 t' W. O2 t" v8 u(defun laychk(lay / l_sta)
8 G  }( A, h8 q  ( (lambda (x)& t- t6 g3 X# O2 r& ^8 X$ V2 V
      (if (not l_s)
' x% t* j3 ?( a+ M" Q5 K% ~          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))1 {. ]: j& t4 o7 A
      ); if
0 @: x9 K) u# l2 Y5 k* y    ); lambda
$ I& r* i& Z/ }  S' `9 f    (getvar "CLAYER")+ V7 m+ }1 x2 b: b- {; V* D
  )1 t- X% P( t, d+ e, B* b
  (if (not (tblsearch "LAYER" lay))# i/ J5 L! I) S# y+ V6 v/ `
    (progn  8 N1 y+ h4 R+ Q' Z; y
      (initget "Yes No"); |4 {% ?: b$ c& W% |! B& b
      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")* ~8 E, M9 O6 G
        (progn2 g6 W$ D" b( w7 e' Z
          (command "_.layer" "n" lay "")' e6 l6 Y# H. z
          (setq l_sta 0)" V: [- t% L6 O6 I4 v! D, w
        ); progn
. M; [% A( P) i0 m9 v      ); if& O7 X/ L9 s1 ]4 H
    ); progn! B/ h# {( x! {# Y# O
    (progn& k' h' e4 f. ?- l6 J5 e5 J- Z* p
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
8 f7 s; ~' W$ N& @8 F- X      (if (= 1 (logand 1 l_sta))( A% C4 g* `( h8 D$ S
          (progn# t: @* _( B, {( v' `
            (initget "Yes No")3 i! y9 B7 t* v% X% T$ o/ x
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")
0 H8 P& C+ N3 e0 R              (command "_.layer" "t" lay "")
9 ]+ |4 N- D- E/ T              (setq l_sta "No")- p# o6 S  c9 ^* a5 H  V
             ); if
# x. r& i4 d% Q2 n1 a          ); progn
/ {3 n3 X, q& `/ R      ); if
2 X0 ~9 Y0 ~# R/ W8 I# |% t+ e      (if (numberp l_sta) 4 h5 h0 h: ^8 f7 x# l0 h4 l
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
, B7 R  m- y$ ?- j5 F# d, g% K      ); if
$ l9 ]# q3 L% r+ ?, Y+ i    ); progn
6 R, w7 _0 p- t& ?  ); if
( Y1 B% L3 s& f; h) W/ h; _; b  ( (lambda (x)
3 q% a2 a- g1 J      (cond
, ]2 E; s% H" |1 B6 y. `        ( (not x)8 |( q/ {" [1 T0 Q
          (setq l_s (cons (cons lay l_sta) l_s))
5 c8 k3 ]! N4 C: ^9 j        )9 Z8 k9 B  X  g6 `6 x: S: o
        ( (= "No" (cdr x))
# ]  K+ ^5 X- y* X          (setq l_s (subst (cons lay l_sta) x l_s))
) G' h6 [' h" Y; S        )
/ _3 J( w% H# \# D3 ~        ( T l_s)$ ?8 h  x8 p7 K. F
      ); cond
3 ~! ?' S) _2 d/ u2 F" {" p     ); lambda
5 O/ ~* J" J! W& S* f  T% m     (assoc lay l_s)
% A0 ~( @, C! M# z  )
4 k1 H4 Z" o# o% U. f: {& M1 W4 V: G! M8 I0 w. I$ ~
); defun chklay
  F. V6 Q7 G- h5 ?$ i/ Y  E9 N+ x
$ V2 A. |; Z2 G: D;----------------------------------------------------------------------------
) o6 v& D& \6 t9 ?6 u' s$ b; Restore layer status according to association list l_s
& p+ n9 w3 }6 K;----------------------------------------------------------------------------5 `* `$ s; D2 g% B1 ~
(defun layres()
. U+ p7 p) p- S; P5 ?5 s9 a0 y& o6 r& _  (setvar "CLAYER" (car (last l_s)))
) U: V8 E! ?$ R8 F9 c; h  (repeat (length l_s)# ], r8 Z/ ?' B% i+ l' I- L
    ( (lambda(x)  ' D: A' P6 L& @: d& q' Z8 ~
        (if (numberp (cdr x))7 D$ c6 N$ V9 S
          (progn : `$ H5 ~. Y& U7 `# m+ B# y# U* {
            (if (= 4 (logand 4 (cdr x)))  L  R: v, j% e& I7 Q/ ~
              (command "_.layer" "lo" (car x) "")
) ]! h7 p! x- m! l6 p- r            ); if, H. H" N( a  W" L' ^" x
            (if (= 1 (logand 1 (cdr x)))
+ t( g+ q, K2 R$ M; Q  @8 h              (command "_.layer" "f" (car x) "")
' J2 {: ?$ b/ _9 w+ P, T            ); if" Q' b6 U7 h; e
          ); progn3 c/ N5 d% `3 N8 j# b" {7 s
       ); if    N- x# F( |" i4 r5 M
      ); lambda6 P0 |; j( z; R  e
      (car l_s)  ^( ~8 D5 a& l8 k
    )
) P5 c1 W' ?4 v# X1 T4 n" m/ p: t5 H    (setq l_s (cdr l_s))2 G" p6 A1 Q" m1 X
  ); repeat. M8 O/ f3 D0 W  A  i' G. P
); layres
/ e' h3 z! B0 p  l4 l* _- I7 U' `8 ?
6 w% }0 {6 X& h1 m  b0 H;----------------------------------------------------------------------------  j- P7 T7 Q( Q& `: g% k6 ?
; Get DXF codes5 n6 J. P8 |7 L3 q% m
;----------------------------------------------------------------------------
6 ?6 v0 Y$ X, b) D6 `) q(defun entgetf (index ent), _4 B: b7 J0 e7 k. _
  ((lambda (e)
2 v9 j/ w: v' s/ v8 G      (mapcar '(lambda (x)
; S2 q6 c/ J* E  U8 @; M  t                 (cdr (assoc x e))9 H  t) H. o/ a3 j( q
               ); lambda
: |! ~- v  n, a4 G               index) ; internal lambda function) D2 l# K7 p9 e3 P
    ); lambda
% @" ?7 C7 u$ V( O9 ?- M4 O* A/ i    (entget ent)
4 u) m% {* M0 r3 S  )
  I  f( d( N8 S# U0 ?7 @2 R" z2 y, r); defun entgetf+ |* ^2 ?3 `  F2 c7 P! }  d
  c0 Y7 s0 c/ R  m
;----------------------------------------------------------------------------- x" a& L/ f3 d5 h  f! a
; Save UNDO status
- U4 R% Y5 H1 S2 |5 i;----------------------------------------------------------------------------: E: k" T; p1 Q
(defun undo_init (/ cmdecho undo_ctl)   4 x: [  j9 {# I! N. P* m$ R7 Z" ]
  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
. _1 F% t% Z- O4 F2 U7 b# ]  (setvar "CMDECHO" 0)
, B  J0 @/ G7 G$ x2 b2 g2 F& N4 y( t7 w( w
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable+ P' f: W" [/ S. M
    (command "_.undo" "_all")/ G7 F1 g/ S* |  x! [
    (command "_.undo" "_control" "_all")
: p0 m6 ^) Q' V& k% c  )
- w) a' E! ^; n2 R! X( b
& V  K3 E8 Z& S% p+ Y; R1 V  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off
, C6 G8 D7 Z1 P9 J0 u    (command "_.undo" "_auto" "_off")
% t/ i$ a+ j+ M- @( x- R  )
2 F3 u! C- p( A6 q. P
! U5 ]- v5 [" R3 u6 A  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
3 k/ C; f6 ^& H. v8 T    (command "_.undo" "_end"); ~1 p0 ?/ I# W, X2 o& i! ~
  )
. Z# H5 o+ x, [. J; s/ O
" d  l: W$ {0 \3 Q% i5 y" R& p% ?  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))+ @( b0 v8 C" n5 Z; D
    (command "_.undo" "_group")
& F7 K/ @, {2 v: r# a6 E  )
: l6 v% i8 x+ t# L' S) {8 ?: k6 Y& }: }; b. q4 M6 g
  (setvar "CMDECHO" cmdecho)
# ]9 Q% _6 K7 |% F9 |3 J  undo_ctl
6 U: y- m1 [% `: ?); defun undo_init
5 w7 S* @$ I) j/ |
* ^+ S/ Q1 Z: U* n7 [1 k$ y;----------------------------------------------------------------------------6 q" k; Y5 s& Q
; Restore UNDO status
3 x6 X, w, F6 T5 K( Z; O3 `;----------------------------------------------------------------------------
4 n8 j) L* U- p; `(defun undo_restore (/ cmdecho)0 ^! A( q  W' ?
  (if old_undoctl0 x$ f; l4 O* ~; V2 K* V+ f; S
    (progn7 E8 b: @: B/ L7 ?4 [
      (setq cmdecho (getvar "CMDECHO"))
) h1 c" r  l/ n) t3 ]* Q" n      (setvar "CMDECHO" 0)" `5 K( |- Z0 h+ {

) f8 r: O+ y8 B' U      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) " a! Y2 Y, j5 a% m+ e
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
6 O0 k8 N3 I2 H% q' o* _& N7 _        (command "_.undo" "_end")" {4 y8 @, ~9 ?
      ); while0 L7 r0 z# }8 F* c% N
: b$ X" @* k- o
& ]- c, ?' C0 _
      (if (not (equal old_undoctl (getvar "UNDOCTL"))). \* q$ s# {0 ?' e
        (progn
7 `; }2 P( i  A3 w( p3 D          (cond5 ?1 w; C4 j3 {( }- c
            ((equal 0 old_undoctl)7 x2 l. _$ i8 U# \
              (command "_.undo" "_control" "_none")
: B5 @' @- x) ~) J            ); U# \) i  M9 L" w
            ((equal 2 (logand 2 old_undoctl))1 ^+ W& a3 h' Y) l: D- N& B7 [
              (command "_.undo" "_control" "_one")2 K9 H: ~' e/ Q- ?
            )
7 ^9 P! F& M" ^" s, ~2 x* a          )
5 ?# |% _5 k' U6 G4 ^4 x          (if (equal 4 (logand 4 old_undoctl))
8 T  I- e9 R# k3 ]7 X$ [4 h              (command "_.undo" "_auto" "_on")! m4 D! A& n% v; F. _5 h
              (command "_.undo" "_auto" "_off")
% i8 O& f: O" _7 Y% h4 _          ), @& T# _2 t. Z+ Q4 Z
        )
3 D* h: Y' d& `0 S8 {% N& o; Y( K      )
5 N# H" W9 J' G' }# s      (setq old_undoctl nil)1 z% M/ a2 I7 A: k' ?
      (setvar "CMDECHO" cmdecho)$ N, m5 i5 X0 c9 j$ l& }
    )
4 |* I4 X7 C8 b3 t0 q# g6 t; J0 L; d, j  )
0 H2 x8 p  U& j$ q); defun undo_restore) o+ x6 A& {2 H

( f; v! Y3 U' v& J& h6 P) L;----------------------------------------------------------------------------) f4 q9 q- w% B1 V$ ]) g$ m5 U( ]
; Save variables/ S( V+ t: N: Z; p6 u
;----------------------------------------------------------------------------
0 a( q$ m! X: N% S! M3 N; j  n(defun var_save (a)# E+ e% u9 |7 H% M/ K) V" t! |
  (setq m_lst '())' r- j$ A; s* e: e
  (repeat (length a)
4 o/ X$ x" z# E- d+ V    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
7 F) _$ U2 R' l4 ~. L: o( t    (setq a (cdr a))- c3 o4 |: d) \
  )5 k/ X5 h( G0 p* i
); defun var_save
- G- w2 I- ]# N* q0 a( p
! a6 G' U* w* c, x;----------------------------------------------------------------------------
. t4 @) }8 i; l, B) _5 L5 O5 E; Set variables
& ?: S9 C* {! y1 h+ q5 {1 U% X;----------------------------------------------------------------------------& r* o' K, a6 q/ O, Q5 F8 ~4 N" P0 d
(defun var_set (m_lst)" n# D; C, A0 r2 R
  (repeat (length m_lst)6 r' o! i5 X! K1 @/ p3 Y  l
    (setvar (caar m_lst) (cadar m_lst))
8 I9 R: a" W2 a. ~/ a* y% W    (setq m_lst (cdr m_lst))
& Y$ n$ l, n; B  )8 [! Q% U' J- b$ e) a4 u1 P5 @( e# Q
); defun var_set, T9 U5 f7 \8 K' {6 k' q
$ g$ F- W6 \5 n1 P; T
;----------------------------------------------------------------------------3 T# J; F* g9 s( z- B! n
; Restore variables6 K1 U: U( |- |/ o' T% t
;----------------------------------------------------------------------------
! T( o; O0 h( r$ ](defun var_restore ()
7 e* J) E6 f; G$ c& j/ Y  (repeat (length m_lst)
# B/ c8 X& E. L3 M7 X) H- f    (setvar (caar m_lst) (cadar m_lst))
% M" k  f- `2 X4 R6 `0 R# ~    (setq m_lst (cdr m_lst))
3 H8 H# ~) |' j! e# |  ); {+ t7 h6 E% r" g- C' v0 i# @
); defun var_restore9 F0 g% x0 h6 g( ^  r" v2 u( t

1 l4 @' |1 e0 K* r8 |3 B5 M;----------------------------------------------------------------------------' p, F/ j5 L- [1 x  M
; Initialize routine
" g8 V& i$ U" }( T/ a;----------------------------------------------------------------------------
& ^# t, M" z. @9 u1 i/ P8 e" E(defun err_init(e_lst u_enable add_fun)
' r9 X% f. n& I( Y  (if err_alive (err_restore))          ; To avoid nested call
/ ~: ^  x( k6 Y+ G6 t. L  (setq err_alive T)
2 V" ?& t% g% j# B( a% M4 r  (var_save e_lst)                      ; Save the modes. b- s- V- }( ^- _
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status/ [' h1 z9 }* _1 f
  (setq err_old *error* *error* err_main) ; Save the handle of *error*
# m8 ~* i, d; A: b3 E9 `# w  (if add_fun                           ; Add the user cleaner
6 T6 K1 ~. S( S3 b    (setq *error* (append (reverse (cdr (reverse *error*)))
( n+ X$ @+ W4 J  l' d: W; a                          (list add_fun (last *error*)), f4 t1 l3 E8 p/ g7 b1 y
                  ); append
8 `- p. b" ~) z) {  ?1 t    )0 M; g# l8 w1 N/ y  [+ p" y: Y
  )" \, z, w: A* ?$ \4 Z7 n( q
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
. G7 ]& f6 P2 o& c7 I( ~; Error routine body0 @# r; G1 G- ]
;----------------------------------------------------------------------------
. D$ S" p( X6 K(defun err_main( msg / )                ; Body of error routine' i0 ~% s+ y$ S* T, S% Y( @
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs7 v* l1 X/ W# r& ]6 ?4 C
    (princ (strcat "\nError: " s))      ;while this command is active...6 F4 j* E6 k5 @$ [5 {
  )
; N& r2 h* I; p8 B3 q; o8 p  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command6 b$ k, u$ }' ~6 `0 y
7 R8 K: e! t  j/ W* m& Q6 y; q
  (if old_undoctl  z+ w9 S& N* S# g; i2 s* A
    (progn( x; w/ K8 d& |
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
2 ]$ N6 X+ @+ C        (command "_.undo")              ; if it's in UNOD command# I! E/ x. o2 Q4 M2 ]1 x
      )$ L9 d; u7 j# b5 F8 U. `
      (command "_end")2 e; u6 o; h( Q5 W# b1 J6 U' v
      (command "_.undo" "1")/ {! m0 Q3 O& M
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
; w$ u: Z- ^2 B      (undo_restore)                    ; Restore the status of UNDO
; ^, [( u  t+ R* ?% b2 T    )
- S# w+ Z4 d1 }$ m  )5 i5 I6 K" R; b) a) S
$ t/ R5 O' T7 d) v) X( G' m3 c
  (var_restore)                         ; Restore the variables6 v$ F1 j8 k$ a! {
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error7 R1 _& M: w2 Y8 \( s  t
  (setq err_alive nil)
; [: K4 j) W$ _8 y  (princ)9 r! \, X/ t! K1 `: d9 ?
); defun err_main3 J' D; c% E3 N5 L; ?8 G

8 G2 \9 [+ O6 n2 m; O5 z;----------------------------------------------------------------------------9 E- f1 v" H: Z7 p. K1 S
; Restore error status) Q& A2 _) y: J& w: O! i5 `
;----------------------------------------------------------------------------
/ ]$ \- q1 N" ~9 d( L+ X4 V(defun err_restore()4 v8 K. d% e- W9 t0 C; R
  (undo_restore)                        ; Restore the status of UNDO
3 @# z7 k# H$ y% l/ `" @: w  (var_restore)                         ; Restore the variables* ^1 p! @. f; `4 o  O
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
6 ~9 B4 x9 W( W  (setq err_alive nil)
9 `- W' n1 S" @/ T; i0 M  (princ)
" l8 k: A  C% U5 p' k9 c); defun err_restore
 楼主| 发表于 2007-3-13 08:40 | 显示全部楼层
以上两个程序同时加载,在R14版本下面是可以使用的,这点我确定;但是在07是否可以使用,我现在也不确定了,因为这个命令在我用07的时候用的不多,请问版主怎么修改一下可以在07里面使用呢?谢谢指点!
发表于 2007-3-13 08:49 | 显示全部楼层
敢问楼主是否懂得CAD外挂小程序的编程?日常工作中确实有些不太方便的烦琐的操作,我想学习一下,请楼主赐教~~
 楼主| 发表于 2007-3-13 12:23 | 显示全部楼层
楼上的朋友,不好意思哈,我也是菜鸟,不然我就可以自己修改程序了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于|免责|隐私|版权|广告|联系|手机版|CAD设计论坛

GMT+8, 2026-7-25 08:23

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

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

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