CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
2 u+ O8 \! q% Z( Z# |  e “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”5 Q! C5 o3 S# T2 \8 n
提示:加载成功
( }6 z# |% p/ D/ Q然后使用CLOUD命令,
: L; B1 T  ]& h; {# r提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”2 O+ j! B% I; o; L6 q) [6 p
请高手指点一下,这个是怎么回事?应该怎么改正?& N. x6 X+ g5 [7 C, z; S
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx1 T$ e5 m9 \3 M
;;;  j' K6 U0 z5 Q- y) \- B) Y
;;;  DESCRIPTION
5 X4 R" E7 c* Q" M4 g) s;;;     Draw cloud and you can specify the globals variables listed below
* ]  t3 T: ]8 }% Z;;;     to decide the characters of cloud
3 ^* J9 a/ K3 O1 S4 G' I8 H;;;
% w. Y$ L9 v& Q; d( e1 g;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
1 o0 v  R, b0 S5 v: D$ x" };;;
- N' {- s  S/ h! c* J- W3 M5 @;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
# `* \) I* ?$ F;;;           Change CLOUD.001 to use CLAYER to perform the same function
, k# M; p( T( v- ^- c" ]2 `;;;           Use the common error routine UNDO.LSP to optimize this program9 I% Q# k: a6 ^7 Q0 D4 `
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
1 q& z' p7 H# k: o; K8 I+ _;----------------------------------------------------------------------------
8 g5 C: P" D3 D" B;  GLOBALS:
! z3 W6 ?( Z% ?: u;     cloud_layer -- layer of cloud
% _' ]( ^6 S. X( u- H! W;     cloud_scale -- scale of cloud. N' m! ^7 u" M0 ~
;     number_rev  -- revision number
- L6 A6 W0 {& K8 X;----------------------------------------------------------------------------# e: @/ s+ q, P9 z+ H
(defun cloud (/ locked temp first_point next_point relative_point, l5 z# l% @  g' U6 r+ d: t* Z; P6 B
               last_point point_tri point_ref corner_1st corner_2nd length_tri, d5 c# S* f% Y/ m( ~
               length_cloud angle_l_to_f dir_tri repeat_count 9 y: R% Z9 ~) P4 x+ _6 Z. M
               table_cloud )
+ b9 x, D* q3 ?: H3 |8 Q9 t        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))4 F' q0 }7 h4 `0 |
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))- `+ n/ R1 }/ q) |  `5 W
        );if; O1 R' C$ B9 s1 k) S6 T
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
6 Y: E+ l. J; p9 }                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
4 `5 T* @3 r7 ]6 z" D        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
0 X, m6 K/ q: V4 z$ b& p                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
% \$ @4 \3 a6 X( W4 i
# [* P5 S2 o" }# q        (if (not (numberp cloud_scale))- f1 `) Y( t' m; l- \
            (setq cloud_scale (getvar "LTSCALE"))
+ S% m$ F7 r3 n8 M  g6 Q        ); if
: _5 F$ B9 m7 Q        (if (not cloud_layer)! v0 }- S$ H$ N6 K  Y0 d
            (setq cloud_layer (getvar "CLAYER"))  o6 S& X: f: T
        ); if
$ |+ V1 |/ @& D5 Y% {9 s9 N* m        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))7 R  L( p: u# I: F- I) u
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
; S2 D" ^/ A5 a% G+ J. j2 X        (if (= (cdar (laychk cloud_layer)) "No")4 u6 E% T' T, `3 i$ g& C  S
          (progn- D0 ]* @( L6 D0 E: K6 \
            (laychk (setq cloud_layer (getvar "CLAYER")))5 c% Z% U# k; m7 @5 U7 w' V1 B
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))1 i) P2 m( z6 @! T: e; T" Z
          ); progn
3 e! x/ r0 @/ p& e        ); if0 L/ ?; ~/ W  @
3 `# R: k- p: p. }! V
        (while (/= (type first_point) 'LIST)6 Y5 d* D4 g2 }1 Q
          (initget 1 "Layer Scale")
' Y# _$ u& b: v* H* f          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point), j4 f* H6 d' N: N) c; _5 d
          (if (= "Scale" first_point)      
8 Z- |3 B/ G1 P* b' q% @& f8 H            (progn! M/ E& M" {4 Y/ Y, S1 J
              (setq temp cloud_scale)+ \/ w, i9 f, B* b. m" k, I
              (initget 6)# m3 o+ B/ R3 ]4 G+ V
              (cond
9 |) {+ g" M. s5 u+ H* A' r9 y                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
- Y8 e6 z0 ^! m8 T* W3 f9 J                                                          (rtos cloud_scale 2 2)) Y% |- z: A1 p* i( }. f% W9 M  {
                                                          "> "))))+ F" {7 G1 c7 V2 X# h2 R$ w2 X
                  (setq cloud_scale temp) )
( n. J6 Z( w3 [) L. H              ); cond7 Y; T, m! Y- Y
            ); progn9 D( y$ M# Y+ K4 m+ Y  Z8 L2 P. h
          ); if, {! m; H0 T  k0 s3 q8 `3 a
          (if (= "Layer" first_point)
9 F' i) ?# x- T$ A- R( N            (progn$ @9 l! W5 |! i
              (setq temp cloud_layer)/ l# d1 u5 l' F' k6 O- {# P
              (cond
/ c- J, M9 h% e                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"( l7 U; Z$ g, N/ Z) d0 P/ \, P% g
                                                          cloud_layer "> ")))
! X% j* j0 [4 x- H( G) Q; u  E                     "")2 q2 x7 w0 g0 S
                  (setq cloud_layer temp)6 ?+ a0 n/ N7 m
                )" v# v) w/ J0 \9 ^+ L! g- r
              ); cond
- ?/ _# h8 H, v. w$ Y              (if (= (cdar (laychk cloud_layer )) "No"); C* I3 E* V$ w& S: `3 P+ a
                (progn
$ z; g% X+ V  C6 e                  (setq cloud_layer temp)
* s! b- H: D5 G9 S                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))5 _1 a# Y$ E9 z1 {; n' W1 P
                ); progn
- m* {& U" _; O1 T/ c0 k# {! A              ); if  \7 N! O" b0 M+ X0 W$ t, c
            ); progn- H1 Y( D7 r( ?; f) w+ A! u* W
          ); if, {. K! k# S. v3 k0 T; D+ {
        ); while
' S& z( a' }2 q# W% E6 k8 E        (setvar "CLAYER" cloud_layer)
% M* r" c3 C9 z1 w. _% _) h. A- m  h' O$ m9 S
        (if (>= ( getvar "LUNITS") 3)0 v, q5 h. H$ V5 w/ ^
          (setq length_cloud (* 0.25 cloud_scale)" V: J; Q2 X/ F. z
                length_tri (* 0.3125 (getvar "LTSCALE")))- w4 H% }/ k$ p1 G: O6 U# {2 N
          (setq length_cloud (* 0.3406890 cloud_scale)
. k$ u8 I% q) H6 }, M4 b4 G  v                length_tri (* 0.438366 (getvar "LTSCALE")))
) c) b* i2 n9 F; C        )
( @( g* S, q! c/ N        (command "_.PLINE" first_point "A")
/ _9 U6 |6 f" R8 s! y+ C- G$ t2 a        (while (not (equal next_point first_point 0.000001))% q. w# b3 P) l" I$ I# i4 k
          (initget  "Close")
/ ]* D5 u* x7 N          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
6 Z$ C5 v- `2 F) k$ x# D- T        (while (and (not (listp next_point)) (/= next_point "Close"))
% ?" V6 r$ x) r          (initget  "Close")7 ]$ S- L3 p; \7 H: Z3 a# B
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
" T: N; U: s: _3 P  D        )
! p" p$ G. n) Q" [( ~( Q# j$ w          (if (= "Close" next_point) (setq next_point first_point))
3 [7 ^) z$ D$ h. J: X          (setq angle_l_to_f (angtos (angle last_point next_point))
7 Q" l* N6 i+ n/ `% f2 f3 h                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
5 D  N% z! m: J) p5 K) L2 b* t          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)9 a" i+ u5 ^# D3 @9 a1 q" h- s1 k
             (setq repeat_count 0)" ~- j- o6 \1 p$ P$ O4 _( F
             (if (>= (- repeat_count (fix repeat_count)) 0.5)% l1 Q6 h+ _( f+ A
               (setq repeat_count (fix repeat_count))4 @" q, K  I+ f$ l  x
               (setq repeat_count (1- (fix repeat_count)))
! H- }* H6 k" }6 l             ); if
6 h$ W- H$ Q7 M* h          ); if3 L( x- G% Y- o  f- e. f
          (repeat repeat_count (command "A" "-100" relative_point))' I  H! B! T& ]! h
          (command "A" "-100" next_point)2 u( u1 ^8 i) H! |$ _1 F
          (setq last_point next_point)
# |4 K; Y- K% v% |+ z        )3 D5 h2 U/ [7 I' q. Q% M
        (command "")1 L! f  l2 o2 c" J  v
        (if (= (type number_rev) 'INT)
& K  k$ b* I' U0 Z0 D           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
# I" C6 T4 w. ^. H& H* E; ^9 `           (progn
3 ?3 g- b4 j8 {2 G& D             (initget 5)
( e6 A0 ?1 F# e0 M& L8 W: H             (setq number_rev (getint "\n请输入版本号:")); z5 k- t3 t; C* W# w6 C7 [
           )- N: h, l: l9 K3 Y
        ); if$ N  ^8 o9 U% s5 A
        (setvar "OSMODE" 512)
" X/ o' d3 f- h3 N1 `# Y" ?        (while (/= (type point_tri) 'LIST)
5 }/ F5 t1 o. a( }- H- a( o          (initget "Number"): T! {8 b- r" Q+ G* }8 j  I' \" n- S
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
9 M! k, r2 H. ~+ c/ C) R( E1 E          (if (= point_tri "Number")
3 |+ e/ A- c9 d4 E              (progn
6 K- k% F+ G2 @/ U                (initget 4)
, t2 {. @4 ~9 q1 {9 Z0 d9 O                (cond* I0 o& c% g$ T
                  ( (not (setq temp number_rev + ^) I  f; ]  l& D3 j) m/ B% b
                               number_rev
- }5 M* _1 S8 v9 ?. V                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
# r9 ]  z2 b& o, B2 V6 h+ \! H                    (setq number_rev temp)2 _0 u8 l; @6 Q$ y
                  ), M, H. u! d# X7 v' ~
                ); cond
3 J( x7 G; E5 l$ j( c9 @$ T              ); progn
! t( u) q0 R' f9 b3 m: z          ); if
) M: t" t3 Y. ?' V* m        ); while
1 X- h/ w* f" r, d        (setvar "OSMODE" 0)
% }+ [5 \  }* l- \        (initget 1)
3 L2 k$ H& i. ^; D2 c        (setq point_ref (getpoint point_tri "\n请选择方向:"))
( b' ^  Y' n& J4 z  f" w8 f        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))
6 B3 t) F: Y; t0 ?  x7 x        (setq corner_1st (polar point_tri
+ Y/ b: r' d7 }                                (+ 1.570796327 (* -1.570796327 dir_tri))
: A" U6 s% G6 D' V% e2 _+ G! T                                length_tri# Z1 L0 K2 S( D' w! g$ ~8 u: X
                         )) K0 h4 e  u- l5 c( `# ~
        )) f4 o- ^' c, J5 [
        (setq corner_2nd (polar point_tri
- s* C; A; ?$ D2 K3 F+ q, N: v! Z                                (+ 1.570796327 (* -0.523598775 dir_tri))
% `- c) F; W: Q9 I                                length_tri1 \1 l& l( v. g
                         )' ^5 y! J" f: Q
        )& X8 S% j/ h- u- `: e
        (setvar "CECOLOR" "2")
$ h) y* e% x/ `        (command "_.pline" point_tri corner_1st corner_2nd "c" )2 [: x' p5 {4 ~9 H6 A* Z- _' R
        (setq textstyle (getvar "TEXTSTYLE"))
. o8 l: K4 b1 x        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
6 O7 A* V& {6 C8 H        (setvar "CECOLOR" "7")+ N  X! R; O: j; {; X% |
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
4 o, n6 v( U5 I$ [9 a                  (* 0.4 length_tri) "0" (itoa number_rev))# B- Q$ E! u0 f
        (layres)9 i# \5 Z, C& U7 A* F$ N
        (err_restore)2 L- {- H' O( }, P6 E
        (princ)/ e! j7 W& T! h0 ~1 U  q! T
); defun cloud" b5 ]/ f9 ?6 e8 |
5 ~5 O( B5 K+ b5 A
(defun c:cloud () (cloud)), s3 @& c& P. y$ [+ a
(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
' I5 f6 @) H; ^! _;;;
: [, A5 A0 C; ~- |" G8 |;;;  DESCRIPTION
1 u1 e: c4 v  L. Z8 l' f" Q& A;;;     These are general error routines which can be called by
$ W+ v6 U/ m7 D! j- q( U: B;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference1 t& e, I; C& A9 F
;;;2 j* l. N$ z. M9 o6 a
;;;  SUBROUTINE INCLUDED IN THIS FILE
: j$ R" O6 B  P  r;;;     UNDO_INIT
) n3 ]- G8 Y$ M;;;     UNDO_RESTORE
) S$ G% w5 V$ ]# l. O/ j6 J4 G# j;;;     VAR_SAVE ! m$ J2 M4 j* y4 ^1 ^4 o
;;;     VAR_SET  
3 l6 D3 Z6 Q+ @2 O+ N;;;     VAR_RESTORE+ ?1 Q' [: n/ Y8 _, s
;;;     ERR_INIT " U( c+ Y; @3 V  U* b
;;;     ERR_MAIN
, `. \& t) b4 ^4 g;;;     ERR_RESTORE
: B7 ]# ~8 b5 P* @4 {; [0 N;;;
1 W1 G7 i  |2 o/ m;;;  DATE: 10/17/98; 03/31/99
( Q5 m5 {9 u  Z2 c; b! M;;;5 o& d$ Q/ @( n; l+ C
;;;  HISTORY:
3 X% g# V, L7 |* t& _;;;    Add routine of mod_att
2 [, u+ m# c6 v2 a;;;
/ ^) Y" B: A9 `/ s# @6 L;;;  USING METHOD
, J1 G" g! [% y% a4 ?0 ];;;    ERR_INIT:
9 G" u0 D1 C1 Y4 C3 Q;;;      This routine initialzes the error handler. It should be called as:0 F1 C' L( g/ L* S1 a; t
;;;
. `, J( `; e. w( E* [2 a0 Y: \;;;      (if (and (not undo_init)# u) [5 R" Y$ Z3 n! v
;;;               (equal -1 (load "undo.lsp"  -1))
& W) R' n2 n6 W. ];;;          );and
, H/ _. }: M  b8 X( I0 W: k;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))/ A) ]0 i7 Y- j8 ^6 }
;;;      ); if
' f& [! P! z+ P- ^; t( i' T& j% {2 U;;;
6 r* |% v7 U+ O5 K1 b0 H3 O;;;     ARGUMENTS:
! n7 p& i+ L/ f; ^1 x9 T6 I/ O;;;       err_init Takes 3 arguments. / Y6 s" m' ~; m) ~/ `9 S: ~
;;;     1. - The first element of the argument:
- }9 ~4 q& L; R& [;;;          This is a list of system variables paired with9 _, B# H& W' T
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
6 X# O; o/ D) _6 I; K;;;     2. - The second element is a flag0 C- l  G7 S8 |5 l5 l( N
;;;          If it is true, then in the event of an error ' p# v5 }7 B2 d" h9 P; K" t; d. @
;;;          the custom *error* routine will utilize UNDO ! w1 H9 v7 r9 l& a
;;;          as a cleanup mechanism.
* ]' F$ b  ~% A8 H* t" U! F5 Y;;;     3. - The third element is a quoted function call.) v2 G6 z; [2 ]( V# T
;;;          You pass a quoted call to the function you
( F. t3 u* ~' Q, r: D;;;          wish to execute at the end of nomal routine if an error occurs.
% r4 r2 m' E* t1 x8 O* l% x;;;          i.e. '(my_special_stuff arg1 arg2...)3 C" m! y2 p. ^9 G. G7 L) |/ S
;;;          Use this arg if you want to do some specialized clean up
5 B! w, Y; c: ~% Z3 _4 s6 F8 X( f;;;          things that are not already done by the standard bonus_error ' }" E& ]. [4 k/ c
;;;          function.9 X! R. m; }" K6 c
;;;( F# T# \& v5 }
;;;    ERR_MAIN: Body of error routine, i2 |! q3 H5 \$ h7 h; b% g
;;;7 e  C0 O+ k6 S* Y; L+ C
;;;    ERR_RESTORE: This routine should be called at the end of command to
, [% ~, P6 }: c* I' Q;;;           restore the VARIABLES, UNDO & *error*.
3 V+ U  B: ~1 ?3 Z;;;$ E  n3 S( o7 W- J
;;;    UNDO_INIT: Initialize the UNDO status  S# E+ I* g+ X: U
;;;* v, C- G! b$ l: {6 [3 [- A
;;;    UNDO_RESTORE: Restore the UNDO status
2 G! l8 X$ n. H8 [" [! }' o8 o;;;5 b% U* n0 a1 s7 E
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
8 v  d$ x. ^# v;;;5 S' V3 {. e: h& S( a. y
;;;    UNDO_set: Set the variables. the argument is like( m. e. F1 E# H" o. C) w0 n
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
1 v) }( B, s3 d9 v7 V;;;& q' [, }" v0 }2 x
;;;    UNDO_RESTORE: Restore the variables3 x, E; G, r$ F! [7 x9 }8 k
;;;' ~5 h* w- Z0 v. T$ I7 g
;----------------------------------------------------------------------------
) ?5 s3 ]; K! r. S7 W;  GLOBALS:9 q0 c, I8 D5 w0 ^1 z
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
3 ^( W4 I5 w" a9 R9 U3 C# w;     m_lst       -- list of variables (voided by VAR_RESTORE). q0 ?$ n0 G5 G/ A
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or
. ^" |5 |7 f2 m& H9 N0 K9 [% m; c;                    ERR_OLD)
5 L2 T; E" i, \8 K9 Z' j9 s;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)8 y: ]. t) ^! H
;----------------------------------------------------------------------------5 E9 }; k+ X+ B5 _

4 u6 P6 {5 h$ J+ N! f9 t7 M" I: E;----------------------------------------------------------------------------
7 L0 R$ y6 Y" B% a( ?& ]& q9 ?* h; Modify attributes according to entity name, attribute name, dxf_item5 x) E9 P- Z/ E$ @
;----------------------------------------------------------------------------1 x* {9 y. [. V4 g# {! `
(defun mod_att(ent id dxf_item)        - R. W% y3 G# k% V+ H
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
" a% r6 t8 z9 o2 i: N    (setq ent (entnext ent))
) n+ H4 X; ]! B/ w4 i$ y" M  ); while  
2 e# _' n: ~+ c0 j9 C  ((lambda (x)
1 W' F# N% d6 {$ t- d; P/ z& L; ~. j        (mapcar '(lambda (y)+ |' O; j3 i( }
                   (setq x (subst y (assoc (car y) x) x))
$ @0 E& ^6 m! f# l, W' N$ k( L' N4 B                 ); lambda% [1 X9 c, n2 x) ~0 T% q
                 dxf_item
" c( [$ C0 t6 m7 x( S# N0 m        ); mapcar( s0 ?9 o3 }1 h
     (entmod x)$ J  h' ]/ Q0 f/ m( ~4 V
     (entupd ent)  |: F! o  W7 p3 ~5 X& z
   ); lambda
) N% @% W8 U3 [, S6 ]* v) ^2 `. U   (entget ent)
% t6 {5 a& U, P6 @- o! |1 }! q )
5 h7 M4 _% F5 J, q, t3 j3 F); defun mod_att, P) d* I. w% u/ p4 S$ R* h
$ R' G' b( F9 U7 v; W# J  A
;----------------------------------------------------------------------------# o7 [6 J0 u, J8 L# k4 Z' m' D
; Check layer status, return a association list which contains layer information
* U" j: E* J9 t! ]. W; O0 o% i" E;----------------------------------------------------------------------------
0 o+ {0 H6 W+ U& F9 S$ Q6 {( t(defun laychk(lay / l_sta), z% ^3 p5 U- G/ r" a
  ( (lambda (x)
% X2 N) t. i5 \2 ~5 h! i2 r: H      (if (not l_s)( L! \) ]1 a1 o, m. @- k0 o) D
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
* t: J3 c+ m$ v2 ~2 P$ S+ t! o2 J      ); if" R8 z% j5 Y5 k2 D! K# R+ K
    ); lambda ( K. m; A2 q- `
    (getvar "CLAYER")1 L% J& w6 ?  K8 i+ U9 A0 w
  )
- V' m: L7 `# t1 t  S: g3 G  (if (not (tblsearch "LAYER" lay))
: i0 Y# X: l  [4 P: R    (progn  % h% Y' }, P. O9 Z9 P
      (initget "Yes No")
- O: E+ f! Q! B6 ?      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
( e+ E6 u0 x$ H; C' z, s* u        (progn9 |5 v& d% m9 S6 f* m. o1 B
          (command "_.layer" "n" lay "")
1 K% q: W% }/ }  m          (setq l_sta 0)
# C& g: T5 V$ {! D+ b        ); progn
$ e/ ?. X- T& D      ); if
1 a( U& ~6 \% m9 S0 A    ); progn) C, s. |4 V) G, d1 C
    (progn
) s" i- @7 l" m4 f( C2 T( w8 ~8 p8 c      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
5 T: {( h( I, O- [: W  i# I  F      (if (= 1 (logand 1 l_sta))
  |1 t* X* ]! J- r          (progn+ y# G) ~4 S) u- M, `$ N
            (initget "Yes No")
, G( Z& c: b" r- l1 m1 j" T            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")  K- A) g/ d( S2 y8 [# M
              (command "_.layer" "t" lay "")1 {" F4 r1 C* o: |- n" F' }
              (setq l_sta "No")( h9 ^& U5 ]7 K4 }! _
             ); if
. z& o8 \( C3 w9 V# M          ); progn
* W4 Z$ _% }6 k4 e4 b: G  \      ); if
# W2 E$ D+ d# G' e: M; T6 H/ m      (if (numberp l_sta)
( j; ~2 i* r. T; q/ M# a        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if3 O) @1 s; p0 p, i# c* r0 ^; H
      ); if1 P1 F' N3 G$ s' T5 ], g/ S
    ); progn7 q- t! Z, Q; ^$ D- z" h# ^+ R1 T
  ); if# [: L$ ~: q9 [
  ( (lambda (x)
  e: z% R+ g& G0 D7 B$ F      (cond
; I8 j* M6 a  M/ ^0 {5 I# Y        ( (not x)
7 s2 @/ h2 s1 Y6 L+ [* {: x          (setq l_s (cons (cons lay l_sta) l_s))0 ]! ~- F3 n+ i& s
        )+ [: X; X5 H" W5 t4 Q
        ( (= "No" (cdr x))" K& K( N7 t9 A4 ?  K
          (setq l_s (subst (cons lay l_sta) x l_s))
0 V3 G% c+ z: Y+ i9 ]9 y        )! X9 c* [$ A- a  H
        ( T l_s)! r% r  T6 P' |2 B+ a0 s
      ); cond+ p6 n, q5 p. A% P- v& D
     ); lambda" T' L# e( g! f3 a
     (assoc lay l_s)6 Y3 s; y! a9 G& V
  )
1 ?  g& M: Q+ u' V, {. {
  N% b/ N- Q7 [); defun chklay
4 J1 Q/ g5 O, l6 ^# K2 \3 y2 ]5 ?+ O
;----------------------------------------------------------------------------9 v2 l) n% N. D# k
; Restore layer status according to association list l_s* j$ a2 M7 u+ _! E* I
;----------------------------------------------------------------------------
* T" u  D* C1 W8 d$ \(defun layres()+ j+ g1 I8 r/ e' |
  (setvar "CLAYER" (car (last l_s)))* f% D: A- \' M& c* g  G
  (repeat (length l_s), u% W8 @4 m% E* f5 I1 c
    ( (lambda(x)  
) b5 O9 S% s% j! @% v! f        (if (numberp (cdr x))
+ V1 Y% {  z' o5 g          (progn
' i4 @& X% g8 t6 |            (if (= 4 (logand 4 (cdr x)))& P' d! ^4 V, `8 m
              (command "_.layer" "lo" (car x) "")& G! s& m4 m9 ]8 N- I2 v
            ); if
# I+ a4 E6 W7 O: a8 k            (if (= 1 (logand 1 (cdr x)))
2 V+ `* ?; y3 }: ^# G6 Y              (command "_.layer" "f" (car x) "")( F$ O9 `) J, `8 \5 G6 u* G; L
            ); if3 f3 n  q* l( Y+ g3 n
          ); progn: R- j# _2 W  g
       ); if  % M% i: F$ b: G. w: m5 \5 b( G
      ); lambda! V/ z+ M. c4 W7 x* b' s, B0 C
      (car l_s)8 x7 ^0 W& e: q  Q8 u9 M! |
    )
( T' A4 O# Z1 u4 P    (setq l_s (cdr l_s))
! V! `3 J0 v" r9 }  ); repeat$ ~2 U2 O% [& e' X' ?
); layres
4 Y' C7 H7 _# p4 Z& v. W+ u% T/ ^6 S, c+ C4 E  w
;----------------------------------------------------------------------------
4 b6 y  y# x) }- J; Get DXF codes  Q1 Z3 L% ^0 [  P
;----------------------------------------------------------------------------1 n; t5 Y2 ?5 t. F
(defun entgetf (index ent)* ~. `- d& a# S' ?6 F
  ((lambda (e)0 J1 Z& w& J) W9 {7 Z5 v% p) D
      (mapcar '(lambda (x)# c9 @( S  ]8 D4 W1 M* O
                 (cdr (assoc x e))
4 q2 h5 f. y1 `9 ?2 @7 A               ); lambda
  C2 x: u4 M1 `/ X) D3 k               index) ; internal lambda function
3 L/ D$ z6 Q6 Z4 w7 }; |    ); lambda
+ y, B1 _. h3 L4 M5 v    (entget ent) & p  n* Z1 @/ A3 t+ C4 P& X
  )
) s# K+ G+ r  i); defun entgetf
' F2 d* |( |5 |+ s5 Q
8 c9 T, R% G1 @* a+ J;----------------------------------------------------------------------------' Y1 h" w! h" D: g
; Save UNDO status
  b1 f4 p# q/ [  q( V  q;----------------------------------------------------------------------------  [$ b5 g, b3 O4 v* J, g9 A
(defun undo_init (/ cmdecho undo_ctl)   
$ a% W, Z; |3 X, B) E, h& l  T  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value: p+ E" u" P$ y$ Q0 I
  (setvar "CMDECHO" 0)
8 p- `, r+ w3 d. ]- u) }; w3 R0 l8 Y2 V3 Y' e
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable  L' o, m7 u$ p
    (command "_.undo" "_all")7 U3 z+ P1 r! B- U" i& M; F
    (command "_.undo" "_control" "_all")
# o$ d$ u7 E" D6 k6 u: K) i  )6 U! J5 ^- U% O" t+ d% D; f
/ x; V9 o) S: J' N* N
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off' D' }) r2 }# x* Q
    (command "_.undo" "_auto" "_off")
- Y$ z4 I- O1 \  W9 K% Y3 W1 Q  )
4 r4 O9 v- U% t4 }* L- v" @7 h: ?; z+ p) |% ]/ Q
  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here; A' E( n1 a& x7 A) f" K! u. k3 M
    (command "_.undo" "_end")
# j: f# i/ G# F: J  )6 K# {5 j' @/ s9 x5 Y( L# B8 }# n

# q; G$ T: f& a& V. |5 I! \, b7 i  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
- Q! o% B  R. o7 m- [6 `$ G    (command "_.undo" "_group")- b9 |9 Q: w' m; I
  )0 V3 B. Q9 Q8 J* a
. R+ l/ {% H! ]' V& E) n
  (setvar "CMDECHO" cmdecho)$ h: G( G" O! H
  undo_ctl
& L2 `( |3 v- O); defun undo_init
. z& n) ^' r" d3 m2 ^2 E6 a' {- e, W" ?) K. x- i
;----------------------------------------------------------------------------
1 \" n1 i9 `6 c+ F$ }; Restore UNDO status- G/ `' S; m- k8 p  ^8 |9 k
;----------------------------------------------------------------------------
  q5 m5 Z4 c& S* A/ ~- y) \(defun undo_restore (/ cmdecho)9 Z: ?9 m8 u- Y
  (if old_undoctl
& s/ U: m6 Q" v    (progn
( Q" @6 E8 w$ \      (setq cmdecho (getvar "CMDECHO"))6 J* t" [/ L: c/ c; L' {5 @1 {
      (setvar "CMDECHO" 0)# k& T5 Q7 q" R) I' R" Z( h
% B3 y; z9 H/ d- ]; Z2 |" l+ P
      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) ) I. T# N1 a! H) X" E* g, h
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
8 s5 K. M) y5 T        (command "_.undo" "_end")- C- T; J. p* q% M* v( G
      ); while5 p& t3 x2 a7 r5 l/ @! ^
. ?% j! v/ X4 {4 s) a# r2 ?) F
' l. a1 o$ I1 u0 ^1 E7 S+ m
      (if (not (equal old_undoctl (getvar "UNDOCTL")))
! @# O1 a" z1 z9 K/ K: w- ?8 q        (progn$ }  \- A1 T; p. X, j9 }1 n* Q
          (cond1 i4 ~2 B$ L$ B! j1 }/ o
            ((equal 0 old_undoctl)
1 ^  s6 u& m' U. h4 A              (command "_.undo" "_control" "_none")& u# ?2 K7 z/ E: @; n' v
            )- v* B. K# y' Q" \
            ((equal 2 (logand 2 old_undoctl))) j" h8 Z4 Q6 h3 G5 O% r
              (command "_.undo" "_control" "_one")( _7 p: c# b0 A+ b3 L
            ), E( C' o1 S* _9 U! q& a
          )/ B" d  X" |' g6 g* e* U0 A, ?: @
          (if (equal 4 (logand 4 old_undoctl))
  S% T7 f- N" j1 _              (command "_.undo" "_auto" "_on")
; K, m5 W; c% T              (command "_.undo" "_auto" "_off")
/ T) [, h* |1 V1 Y. ?          )8 M5 N0 l! n6 F
        ); R$ G2 D( t  ?- `* o* U0 ^# U, S8 h
      )  l% d, K9 ]% o4 g2 T8 B+ M8 u5 a- O
      (setq old_undoctl nil)
$ ^0 A. Z/ g, w4 e! r! N1 s      (setvar "CMDECHO" cmdecho)* i6 A, l( d' n5 }1 @9 X7 x
    )
$ a# h, i3 \8 U- l2 P7 w7 ]! V: k  )
% Q3 K0 N" p* ^. E- `); defun undo_restore4 P" ~) D$ `9 c% W
2 r& ?2 u* W# M8 n2 V
;----------------------------------------------------------------------------6 q( |+ @* B( n2 o; b" X1 p- Q
; Save variables
7 H1 B  g5 @" A# v* w" t- p8 V;----------------------------------------------------------------------------  S9 Y/ e# ], h, c
(defun var_save (a)- ~9 O! f* I% f8 w! Z/ Q9 h0 T
  (setq m_lst '())& h7 I3 N" A3 D& L6 B3 C' l8 r
  (repeat (length a)- ^0 v3 P: @& I" u& k
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
) V# q: ~3 Y& l+ N    (setq a (cdr a))
7 x$ k; z7 Y/ R1 Z7 R9 n4 y* Z" b  )
4 F5 w" X3 s' U/ L5 _# |); defun var_save0 w  O# J& [) u+ x% F: P6 c

1 o* u/ ]# P6 L1 y+ F8 u) k;----------------------------------------------------------------------------
& O' |. R( p0 o( ]' {! n4 Q7 ~/ h4 x; Set variables! O0 @' b5 c6 ^8 A* W( C
;----------------------------------------------------------------------------
0 ?" a8 O! U3 f! \(defun var_set (m_lst)# p. U0 @1 c& N8 a
  (repeat (length m_lst)+ A/ n) r2 l+ @: b
    (setvar (caar m_lst) (cadar m_lst))
$ G" r+ S/ X5 g9 ~    (setq m_lst (cdr m_lst))
2 c# F" s2 ?) z9 V  ); q, \# _: R; L- l0 D
); defun var_set
4 y+ F, V8 h, ]0 k& S' S! \- M7 X: t9 Y6 Z
;----------------------------------------------------------------------------
- e2 t2 Z+ P6 J" K4 t* ^! s: ~2 y$ U& ?; Restore variables
; C6 O3 |4 A4 p;----------------------------------------------------------------------------
& P# u# l5 C9 s- z0 m/ l" ^/ o(defun var_restore ()
3 b8 T8 d# S! W% j  (repeat (length m_lst)! I; v1 j4 M5 Y0 U: }7 r' k
    (setvar (caar m_lst) (cadar m_lst))
7 C+ w0 {: Z0 i    (setq m_lst (cdr m_lst))+ Y) }1 a: Q) d8 r  b
  ). C2 G; M8 k) q4 x9 M: I
); defun var_restore
" c/ T# h9 T5 c3 W6 g- c6 o+ H  y2 n* a% s. i/ C+ y& O
;----------------------------------------------------------------------------
+ l( |6 O  q& r  r; i6 s( M; Initialize routine
0 f; w- f7 D3 M! o1 x7 J;----------------------------------------------------------------------------* n: E* A; B& _9 s* f
(defun err_init(e_lst u_enable add_fun)) X2 k/ z& A% X7 e* t
  (if err_alive (err_restore))          ; To avoid nested call5 n9 s- _9 G+ Q' c
  (setq err_alive T)  i/ B) _/ d, I8 ?
  (var_save e_lst)                      ; Save the modes
/ [6 E. {2 l& r9 O7 x5 y  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status7 r6 z% K2 ^- {1 {4 a6 R, k- L
  (setq err_old *error* *error* err_main) ; Save the handle of *error*
6 `& A3 A! F% p$ P1 |  (if add_fun                           ; Add the user cleaner
& p, H" d9 B' q! `, d. @- R    (setq *error* (append (reverse (cdr (reverse *error*)))# t, x8 T# N% {; ]" u% Q; t& Q
                          (list add_fun (last *error*))
0 n: V9 }* ^  l                  ); append% \- q. B+ q; y2 V8 Q$ W& R! @- y
    )
. \; L- @  y. b( f  )
5 x$ h( j! m  H9 L/ i. v0 K); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------6 t( X$ C) z2 K6 @
; Error routine body$ Y. u* s: _2 Y: i
;----------------------------------------------------------------------------& c. w2 z6 |0 H# M
(defun err_main( msg / )                ; Body of error routine
: f7 J9 f8 j+ R4 ~- c; K. n7 ^) |  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs; `! u9 X9 }( T. r6 c2 p2 C8 z4 @; x
    (princ (strcat "\nError: " s))      ;while this command is active...
) ?! {0 N: H, `, b  )
/ o8 A& ?) I& l9 L4 M( R* z/ I$ @" o  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
, n+ `$ C5 B3 x1 `; f$ c- u0 ?' r# P7 v# d0 W& Z: N) f
  (if old_undoctl
( T2 V) c4 K0 ^# }- a    (progn* C! b! f" W. T) T7 K3 _" R
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See4 b+ _0 @* \, [3 n5 T% H
        (command "_.undo")              ; if it's in UNOD command
" c+ ^+ [# \) y3 g0 X* d      )7 V) L0 |. F2 Q5 P- Z7 e
      (command "_end")
' b+ r4 A5 B% E" h      (command "_.undo" "1")( ]7 Z$ P6 Z2 [% d
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))3 S# ?# |! i3 Q  @( y
      (undo_restore)                    ; Restore the status of UNDO# `9 I1 l0 U, }3 x/ k9 j. C
    )
3 F! j8 ?0 Z" z8 K1 g1 d  )2 `1 @3 I( c  Q% W- {5 J/ E$ s1 A+ n

' t* \9 ~  r/ L: K  (var_restore)                         ; Restore the variables# T' q  g( g9 s" j3 z( e7 O; f5 C/ o
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error; A1 Q) d; B2 g
  (setq err_alive nil)
  X% R$ Z) O. a2 ^5 U$ y) k, R  (princ)
  G5 ]7 p) |& y. Q. @! G+ Z0 l); defun err_main/ `% k( g" S2 ~- q) S. W: _

, ~% p9 u* X4 @6 I;----------------------------------------------------------------------------8 U) i2 z7 w6 a# r* r: C
; Restore error status
  e+ S) x) V, h0 I;----------------------------------------------------------------------------) S7 z& X& k! N
(defun err_restore()5 Z' X  \$ j2 r- ]2 s, f* D
  (undo_restore)                        ; Restore the status of UNDO1 r+ V" V7 X# x! \' `4 d
  (var_restore)                         ; Restore the variables
) L" ^# Q6 a1 \( O/ {$ h  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
1 }  s8 d6 B: I/ ~; }  (setq err_alive nil)
  ^0 j% I5 ^4 X! s. H5 q5 n) B  (princ)1 m) p& B6 m) @+ }6 J# \2 @$ \
); 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-9-19 13:01

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

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

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