CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
. B4 x- X9 C2 B) a! F. g5 E “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”6 N+ K9 F3 q6 @5 L5 P4 X( R
提示:加载成功2 y, S& r( o0 B7 y0 ?! g
然后使用CLOUD命令,
( w6 k( a% u$ i4 R- S6 |; u提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”( E7 m+ X4 [# X! Y9 B
请高手指点一下,这个是怎么回事?应该怎么改正?
4 e' T/ @  ?. X* C这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx+ B' `; U  k% o- y9 K
;;;
# P  g, q* H, B, N: q9 a: c;;;  DESCRIPTION! K1 p4 l0 t1 m! q+ l9 [
;;;     Draw cloud and you can specify the globals variables listed below
. W/ U" u; U) @4 E# r$ };;;     to decide the characters of cloud9 H  s" w+ W, B0 `0 W% b
;;;
8 @: A5 K/ N6 C. [' y/ V2 `' @;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
/ L* e! X5 t+ U: E0 c6 E;;;; n. \, `" B; T$ E
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
& |' C* B" X3 p+ n;;;           Change CLOUD.001 to use CLAYER to perform the same function
( v8 l  _6 j' k( l7 f;;;           Use the common error routine UNDO.LSP to optimize this program, Q5 z0 @& R! O( ~
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
5 f7 _) I, N: I$ P8 \9 A9 B;----------------------------------------------------------------------------3 G( ^- o  B% I2 w4 B$ @
;  GLOBALS:
+ Y3 _1 ~" y' g3 ]) H2 }! j$ K;     cloud_layer -- layer of cloud% M- S* `( z, Q2 v' o  s( A
;     cloud_scale -- scale of cloud
$ n- z5 r; Z# v$ h3 n;     number_rev  -- revision number. \; {% ^; ]2 ^
;----------------------------------------------------------------------------
7 J/ N# V9 b8 @* u1 m7 ](defun cloud (/ locked temp first_point next_point relative_point( g8 F5 {" t8 b  }2 P  r
               last_point point_tri point_ref corner_1st corner_2nd length_tri
! F& ?, P8 {! x. R- b               length_cloud angle_l_to_f dir_tri repeat_count
: i1 y  T7 @1 ^. Z3 `5 Z/ F$ R" X( A/ U               table_cloud )9 J8 L; p4 Q4 M
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))& D) I+ T" S7 @, u* y
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
. S& e, s0 E. N7 h' V  {8 S        );if
; T' h) S9 j) Y5 r        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"2 T/ x  y+ g' q) ~! K6 B- e1 i
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))1 W2 V& N4 d& N) ~) V5 F
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0), Z, r: ]4 @: C
                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
# r0 t; m; C$ g& v( X* G1 `; m) c$ |+ \7 o( Q! A( q! U. N9 `, f
        (if (not (numberp cloud_scale))
3 {( [* j, g: a. l1 F/ H* Z9 z! F            (setq cloud_scale (getvar "LTSCALE"))' o7 a4 _+ m  ~- E/ s
        ); if
) m% Q0 c) S# b! G. z        (if (not cloud_layer)" C9 o+ {- J: I$ l2 t: m
            (setq cloud_layer (getvar "CLAYER"))
; ]7 r6 b* r, a7 z' ]3 O; V        ); if
( F. ~9 l3 g3 t5 ~* c        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))* ~0 |; {& _0 n# p$ H
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))1 h0 O4 ~+ t, G+ v* ~
        (if (= (cdar (laychk cloud_layer)) "No")
5 }+ b+ T; y2 H6 }* W          (progn3 ]& n5 K; L2 X5 Z) k
            (laychk (setq cloud_layer (getvar "CLAYER")))
/ w2 H) R: B) j7 h8 e" I* t            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" )), r0 z. w' s7 U1 ~0 S% c
          ); progn
- {* X% B: r7 `+ r: v! K* g0 i        ); if5 q1 }' H9 B5 U& {

& D7 l7 [# |# \4 Q% ]2 z        (while (/= (type first_point) 'LIST)
9 V" ~+ A( ~- g4 o8 k0 L% X0 u          (initget 1 "Layer Scale")
5 t% H# l8 [0 R! F; C3 ]          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
8 X4 Y: d& Y1 B& U+ x; q; K          (if (= "Scale" first_point)      
+ |" w, T. {3 Y; E! q! K2 Y, v  ?            (progn
' A$ y: {0 P6 s' N+ t: A0 S' m              (setq temp cloud_scale)* }* J, a- O2 R3 K+ v; ]9 X: d0 A
              (initget 6)
8 {4 `0 Z9 o  e+ [) @, l              (cond+ W( z6 [) L. q) ^. _- [: Y5 B
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
& O! `# k5 T& C, l) M' d9 X                                                          (rtos cloud_scale 2 2)
. s" K5 p: M" M- M6 M: S- y  [                                                          "> "))))
) F% K% s) c7 B: N8 x* R7 ]& M                  (setq cloud_scale temp) )  z: w8 i# G7 O2 L4 ?/ Y3 p. W
              ); cond* S5 y! g, u  m& J8 X3 u/ v. ~3 [2 C
            ); progn
8 R1 G+ t9 }. T, x9 `- X          ); if
9 G; K! Q# L& Q/ `8 x) l, ?* s          (if (= "Layer" first_point)
% R& W2 S( O. z0 q/ ~! g            (progn+ `. b: b+ ?$ H6 g; A$ P
              (setq temp cloud_layer)
. m8 E, K# |3 L& r! V' O              (cond: l% t  S: h( ~7 ~
                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"' ^- _2 p5 ?: B- [; M  T2 p
                                                          cloud_layer "> ")))* ^+ X# x* S8 c7 Q3 D
                     ""): N- N+ l, m, S7 W4 m5 e
                  (setq cloud_layer temp)
+ w' G: E; b7 t1 v                )% [) Z( T. b7 c& V6 p
              ); cond9 y2 U5 ]5 f6 k- r4 G
              (if (= (cdar (laychk cloud_layer )) "No"); H( |9 s; f  W, G  P, y
                (progn
9 U1 v5 T; A! _, p; B                  (setq cloud_layer temp)
* N4 e( O# x/ Y; s/ h                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
8 D0 ^$ L* o& w( O- R2 D, Z                ); progn" [: K2 k" a4 ^. F
              ); if* L6 r; v2 K/ D9 I
            ); progn
2 w4 \: Q4 ~) y6 u( d, L          ); if; G7 k' Q% z7 L$ }0 F9 J
        ); while
2 U! D0 [) S  H- ~' p* q( a, o! D        (setvar "CLAYER" cloud_layer)
5 y4 K9 V8 y0 y0 R; L+ z9 g8 w( H$ B6 ]; F
        (if (>= ( getvar "LUNITS") 3)' r- W8 }6 O1 m. R9 d
          (setq length_cloud (* 0.25 cloud_scale)
; z7 E5 N% D4 r                length_tri (* 0.3125 (getvar "LTSCALE")))0 d: Q4 X% w! u
          (setq length_cloud (* 0.3406890 cloud_scale). U8 T4 b2 ~5 {: T
                length_tri (* 0.438366 (getvar "LTSCALE")))
$ `' ^+ _, i2 Y( p6 d4 b2 Q        )
+ `+ ]+ q2 B" m& P# s, p        (command "_.PLINE" first_point "A")
/ y1 V  M7 z% R5 {: |' P# Q        (while (not (equal next_point first_point 0.000001))
8 G# g1 ~( d* S+ O) Y          (initget  "Close")
. G7 f2 N6 t* N- z          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
/ A: M* y6 d! z6 Y8 i- A        (while (and (not (listp next_point)) (/= next_point "Close"))
, T6 h1 x0 h' s* T# ]/ |" A          (initget  "Close")/ |+ t6 p3 }+ H/ }! _
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
$ z# A. L5 C8 [' b        )) L4 C/ U, E1 G) O
          (if (= "Close" next_point) (setq next_point first_point)); H0 z% I7 M: X  `9 f" y
          (setq angle_l_to_f (angtos (angle last_point next_point))
8 c$ s) F( D" }% F  t( k; X                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
! G( n5 }+ v6 I* z          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)" S% l, D/ f$ C# |3 M, V& j4 a1 d
             (setq repeat_count 0)2 L$ O7 R' S' V& e1 b8 Q' {
             (if (>= (- repeat_count (fix repeat_count)) 0.5)' x8 l  X! d; H* y% x  T# z8 z$ M
               (setq repeat_count (fix repeat_count))
( B- A7 X; D- V, e- x6 j" U               (setq repeat_count (1- (fix repeat_count)))# o% n9 ~' M2 a) x
             ); if 4 H/ u' a7 e8 t" S; ~) c
          ); if
  r0 b/ D9 y& j- ~% m* t          (repeat repeat_count (command "A" "-100" relative_point))
+ g# z8 a; F$ t: o          (command "A" "-100" next_point)
! \; J" s6 L3 R' C- S1 ^- ?. o          (setq last_point next_point)
' i$ W7 Z$ u5 k2 l& }& ?  l        )
9 R1 \3 x8 Y- @! }: _        (command "")+ q/ D$ z) V( v7 F
        (if (= (type number_rev) 'INT)
  E. m2 n7 f, ]9 P: k6 A1 v9 e) Z           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
7 ]- r- S8 u" c! E- ~8 F           (progn* f! }2 P/ |8 ?; ^
             (initget 5)5 A& C& @( d6 x  J) ]
             (setq number_rev (getint "\n请输入版本号:")); y" n6 v3 f9 @
           )" B' `2 d5 P  v, @4 d
        ); if5 }3 E) l. ]2 S
        (setvar "OSMODE" 512)
! ]" p: J# T6 w% F# l        (while (/= (type point_tri) 'LIST), Y& k9 K7 l* j) H- f6 u  i$ B( k
          (initget "Number")
0 ]6 a1 I0 f8 t0 F          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))3 I6 z8 a) ^# b- `: G0 u
          (if (= point_tri "Number"). v: K  S3 H3 f/ p# r
              (progn' N4 \" V& W, M% Q6 Z) A
                (initget 4)# I9 O7 U# f/ C( d; H  e3 h' H
                (cond- V# z1 [6 t5 O% ?1 h
                  ( (not (setq temp number_rev 6 N2 F/ e8 F8 H) c1 ^& ?
                               number_rev
3 P' s! Z9 |1 n* k( u5 h0 Z, t                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))! J* `  t' d' b7 v1 n) U7 B% |  q
                    (setq number_rev temp), w, v- k- P2 N7 S) |
                  )
1 T3 f+ s# M! w7 M: x0 B3 r6 B                ); cond& `/ }6 g) Z0 ]/ p. h* l, g7 W
              ); progn
/ d0 S% w. o9 e) B( Z9 e1 H2 I0 K          ); if
# @6 J& o: @( t$ d, k& k' G0 V, N        ); while$ o: U  C% T0 B+ g3 F4 `$ V. L. c
        (setvar "OSMODE" 0)" e4 ^$ \% t2 q4 u% b( i8 y
        (initget 1)# x. ~3 c1 |9 M  e  f
        (setq point_ref (getpoint point_tri "\n请选择方向:"))0 F! D$ R& j/ z5 s# I
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))8 v5 J: _3 P/ {% F% ?
        (setq corner_1st (polar point_tri
3 {) u# ?% H4 H2 c* Y3 c                                (+ 1.570796327 (* -1.570796327 dir_tri))  S) y. X  l+ R# e' p5 P. M6 ]& k
                                length_tri- R  t9 J/ t9 ]: O
                         )
- `# z- \' C* B        )
3 X9 |* d# S6 b  a+ x+ Q, A5 z        (setq corner_2nd (polar point_tri3 S; i' K% _6 j7 G
                                (+ 1.570796327 (* -0.523598775 dir_tri))
, S: P6 S1 S3 s, i( S0 Q5 K                                length_tri
/ {9 Y: W  J8 r& z                         )
/ A: A7 m6 T, d4 q        )$ P9 ~8 c. F5 {9 t& W* p6 E
        (setvar "CECOLOR" "2")0 t0 b( r: Y; S8 Y( g% P$ d
        (command "_.pline" point_tri corner_1st corner_2nd "c" )
4 c9 ^' _; b& T! x        (setq textstyle (getvar "TEXTSTYLE"))
  d7 P) |# W' P8 r5 a        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")) I' B9 s! t6 D" P* A5 U
        (setvar "CECOLOR" "7")& y! \% H; m" h+ }
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))( E7 z  E9 y3 i# r) ]
                  (* 0.4 length_tri) "0" (itoa number_rev))# \* G( n) q3 @' ~) p. q( i
        (layres)
- O/ U0 U6 e, ?5 K        (err_restore)
, c# h- B+ F% O# d, [1 l' f$ B! m        (princ)
! B4 J+ B+ Q# M4 T2 m/ d$ Y2 M); defun cloud
! ^4 j3 N; F4 d) ~( U  f( o6 R+ c2 ~+ b
(defun c:cloud () (cloud))
6 g2 |: H/ ~; w4 j2 b; n6 s& c(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
- k0 `7 V% n0 k;;;7 I& n6 e) u' f
;;;  DESCRIPTION9 n- p4 q0 C- N* w+ i1 G
;;;     These are general error routines which can be called by * g+ a' C+ ^# N6 O/ x* X! m
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference
( H% F0 B* w6 q& m2 ?;;;
, A, y' o2 s" q. B;;;  SUBROUTINE INCLUDED IN THIS FILE5 H( C% \3 \( O  P) E6 }& x
;;;     UNDO_INIT
. N. m% |" l% W6 O/ C7 F;;;     UNDO_RESTORE7 `, k5 a( J% F* J
;;;     VAR_SAVE
2 I: z- I, ^( b+ P3 W' I;;;     VAR_SET  
, L5 N- Y1 d# I* w3 ?0 f;;;     VAR_RESTORE
$ U- o" D% l+ `$ _1 K7 [8 ^; t;;;     ERR_INIT
/ v* y4 A  e4 @8 q) D6 M;;;     ERR_MAIN
' _0 q: g) l; e6 I$ I5 |; t% P;;;     ERR_RESTORE* |/ Z; S9 `5 B8 x
;;;$ n1 }! k* A6 L" Q$ Z
;;;  DATE: 10/17/98; 03/31/99
6 N  m+ U! Y' ^8 {" d;;;7 I% A: U* @# O0 ^) U6 y6 b
;;;  HISTORY:
  B# Z# |1 Y: a6 M;;;    Add routine of mod_att& z6 i6 }2 S7 m: t+ v+ A
;;;
( V* x  W! ~' R9 ^; W% r8 X;;;  USING METHOD
' ^6 n( u, c& }/ N* `;;;    ERR_INIT:
* A& n- V5 R9 H8 Q;;;      This routine initialzes the error handler. It should be called as:0 M; D% Y5 x* y8 E% b
;;;
6 o) w! a& |# N# l; C( S;;;      (if (and (not undo_init)" v9 s$ u* T- i+ J0 f9 |( K
;;;               (equal -1 (load "undo.lsp"  -1)) . v% L0 Q+ x- V0 u' K( e5 @5 L
;;;          );and
8 _2 c, M; a4 E( P) r# Q! `;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
, D* }; @7 `/ h8 t- @# q;;;      ); if) z! E( M, p% W3 z- N6 |
;;;1 @0 o. C2 q6 V! j; O5 Z% R- j
;;;     ARGUMENTS:+ I4 f! G: T4 s( Q* a; ]) e
;;;       err_init Takes 3 arguments. 7 q+ l6 {0 ^" F
;;;     1. - The first element of the argument:
3 a, W; j: @/ l* j, m;;;          This is a list of system variables paired with: p$ D" d6 j4 O) ?! \; N2 y
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")/ E' f& O8 C$ @2 \8 K+ |; v9 a
;;;     2. - The second element is a flag
# s4 O' B7 W; w+ p6 r  u;;;          If it is true, then in the event of an error
/ q. l2 D. @: x6 P5 E;;;          the custom *error* routine will utilize UNDO $ L3 k! k8 d& m% j" P; i4 o  w
;;;          as a cleanup mechanism.9 h+ D  v8 f/ H: f- p- F( u9 w
;;;     3. - The third element is a quoted function call.: F0 D/ r! R2 h5 q, Q$ ~) w
;;;          You pass a quoted call to the function you7 M! e1 e+ f4 H2 w: s  b% v
;;;          wish to execute at the end of nomal routine if an error occurs.
' E$ l- e( l4 n;;;          i.e. '(my_special_stuff arg1 arg2...)6 h3 L2 c0 F& X( f0 u
;;;          Use this arg if you want to do some specialized clean up
1 o: I2 A" q) r7 d;;;          things that are not already done by the standard bonus_error ) w8 @1 |6 B: ]3 E6 A+ X
;;;          function./ c1 x9 `) g. T  y
;;;5 W4 U9 i( e& Y% a' U5 e0 }5 p
;;;    ERR_MAIN: Body of error routine
5 F$ P! e. Q. e9 s4 M# {# L;;;
0 D4 K/ o7 r) Z8 @& h;;;    ERR_RESTORE: This routine should be called at the end of command to
, e' Y& z+ Q9 e/ n+ G4 O;;;           restore the VARIABLES, UNDO & *error*.
- |9 {& k# B7 g% |2 L;;;
4 S5 l5 k- G9 G- q% _! A; a;;;    UNDO_INIT: Initialize the UNDO status
4 ?: v' u# N) o1 k4 {9 j;;;' `8 J8 u/ I1 o9 `
;;;    UNDO_RESTORE: Restore the UNDO status
. I. g( }4 S; b, G, }" }# e* V;;;: G; ?( Y; ?9 [, [4 F4 ]
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
, S1 n$ J' d* v$ [6 k6 l) Q% B0 D;;;
  L# s& n1 j8 c9 H;;;    UNDO_set: Set the variables. the argument is like3 F- `$ F( o" o. `- o
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))7 |9 s3 o5 n7 Q' ]3 Y( W1 w
;;;
) I0 M+ b. D7 K;;;    UNDO_RESTORE: Restore the variables
: E+ {5 c* H1 x6 @3 k;;;2 z$ D3 q6 T7 V# p
;----------------------------------------------------------------------------% b  D$ ^! U: R6 A
;  GLOBALS:
4 S2 Y5 f: t8 |8 I$ Q8 l;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)
) X+ O& K1 s& o, y+ y6 \  L;     m_lst       -- list of variables (voided by VAR_RESTORE)( o; p) m1 x8 _! ~6 k9 o
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or4 j( ^0 l9 e! B/ w( C5 B
;                    ERR_OLD): Q, e7 H" m2 q* \# I% Y* E" {+ X& Q
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)/ W3 D$ s" b4 M1 e% b; S8 z
;----------------------------------------------------------------------------# k0 o) S+ O% o! Z! f6 u% j

( x' i( L, g4 e, O1 U8 A2 m;----------------------------------------------------------------------------" e  `9 C) x+ U- T; i2 R3 p
; Modify attributes according to entity name, attribute name, dxf_item
2 U/ ]8 B/ E9 I! |;----------------------------------------------------------------------------# M. \2 t# E# _/ A. A' V
(defun mod_att(ent id dxf_item)        
. [3 {$ T. S- \) a5 j$ Z  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))6 C$ N9 n* Y: |
    (setq ent (entnext ent))
  R9 A2 y( P7 e# G- s6 r  T# G  ); while  ) L2 A$ c/ V1 Q! Q$ J4 l% H
  ((lambda (x)
( {; |' a3 \0 j" N        (mapcar '(lambda (y)
6 }( @& g) W4 p# W. `  {3 ~                   (setq x (subst y (assoc (car y) x) x))9 h' V& ?) Y* S4 {  h; v
                 ); lambda
) S4 y! O" F/ |- S                 dxf_item
8 B9 H; Y1 }5 ~5 w4 g1 X        ); mapcar
. W: o5 q. O) U+ C3 g5 H     (entmod x)! ]& ?0 j, y" S
     (entupd ent)
6 ]6 Z* L2 O3 ?  I) c+ _) |   ); lambda
  G6 i9 |" A1 ~6 E$ Q1 p   (entget ent)( ~* o  p# D/ T' Z% v
)
2 y& ^  b4 A- h( r  L! O% u  e8 @); defun mod_att
3 m" @+ _, n) S0 `# s
0 ?- ~6 e5 }) u9 U5 \! P;----------------------------------------------------------------------------
+ @6 Y* A, F! s; Check layer status, return a association list which contains layer information0 u( x. F: K, w; Q$ g
;----------------------------------------------------------------------------
. F+ q6 d6 B/ N(defun laychk(lay / l_sta)4 `( A1 l$ ]8 L7 P. F$ m& y
  ( (lambda (x)
7 h' _% e+ u3 D6 _- P- T, ^      (if (not l_s)
) @* @! b' T' G6 p& p2 \7 }          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))% _5 _5 j5 `% B. a: ~+ R, Y
      ); if
0 H+ B7 t! X# D5 |: D& p# h    ); lambda ; V- k7 A# z" l
    (getvar "CLAYER")( _# i# R' F; L  \0 F
  )
# t$ Q( V4 B. i  (if (not (tblsearch "LAYER" lay))* t9 \, V; z# q- b6 D* b
    (progn    a1 u7 S& s: Q, m
      (initget "Yes No")
$ z2 z" O) b! g" M/ j5 G      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
9 j3 ?1 U/ m8 S        (progn. z! G1 ?' I& L, i2 a. P, ]" @7 G. i. b) d
          (command "_.layer" "n" lay "")
9 e7 S( @; F$ t* Y4 n$ f7 d8 _, a4 g) {          (setq l_sta 0)3 [* k$ {! Z2 o. ~& `/ @/ V) Z
        ); progn7 h3 W+ @8 I! Y7 B
      ); if
- I9 O: P- O* C" p( d7 C    ); progn2 h  h5 N2 C) v$ t4 w0 Q2 A
    (progn
' b0 G8 g+ Z  C( X      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
: E5 b; @. h9 R  s' x      (if (= 1 (logand 1 l_sta))
  z( s) Z% b3 U- q( q& S          (progn- \- p7 }) D; s3 ?) `0 d* x
            (initget "Yes No")
, D0 i' O: `* i8 q+ v            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")
9 d6 h$ @! [. _              (command "_.layer" "t" lay ""); w2 @* u! v& v/ l5 [2 s
              (setq l_sta "No")# i! M2 l- g/ D, _( h5 u2 D
             ); if
; i* E1 g8 @( T- c          ); progn0 j& E7 W9 I" z' @0 H$ S
      ); if
0 p( W3 E5 M  J6 L# J9 f4 E      (if (numberp l_sta)
+ w# l! N8 m2 O$ f0 h        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
& R- K3 ^: {% c7 f      ); if5 Q$ {5 Q. H  Y) f
    ); progn
. ]/ N8 s0 G& l2 ]$ W5 m# g* R  ); if% M9 B, C) b: M! P) A
  ( (lambda (x)
! h' p( m2 d4 q6 x      (cond
% z1 Y7 n& F; ]0 y& P2 P        ( (not x)5 J, I' V( i( S8 v- r% a
          (setq l_s (cons (cons lay l_sta) l_s))# a+ T, K& Z. }: o9 E+ s; p
        )
; [6 Q; E" n* _        ( (= "No" (cdr x)). Q$ v# }- k1 V9 ^
          (setq l_s (subst (cons lay l_sta) x l_s)), p2 \( Z) r- }6 |& `/ y0 s
        )) O2 G2 N; d% _" m
        ( T l_s)
) a5 l0 B9 E! ?! l1 Y      ); cond
6 n0 O  W- p) i; F& j" F2 u: @( w     ); lambda
# I5 N4 W6 L" G     (assoc lay l_s)
! T6 f% N3 Q: H! `  )
" s! r" X! B; p: E0 }7 Z* b- d( N. b) m. e( Y/ c% E, H  d1 U
); defun chklay
0 \* z" O$ o# O6 O( o  e  {: R. D7 D7 U& E4 ~8 i' [7 m
;----------------------------------------------------------------------------$ G/ v2 [5 R  V" S. i$ x" R
; Restore layer status according to association list l_s
- F0 @4 o" `4 i" \6 B& J4 ]9 e;----------------------------------------------------------------------------& H: n* U% S% L4 h$ N
(defun layres()  F4 A" h/ g. j5 ~" P" I6 s! V* f
  (setvar "CLAYER" (car (last l_s)))
; x: j1 K' c9 K/ G. \( `  (repeat (length l_s)
+ t; b7 T1 K7 U) l    ( (lambda(x)  
. e. p/ {5 v. x) K7 G% ]9 i        (if (numberp (cdr x))
# p, z* _9 l; M% V6 X" m          (progn
6 }& @$ [" R5 x4 D- U! }0 W. M            (if (= 4 (logand 4 (cdr x))), k8 A; D3 z, R1 A
              (command "_.layer" "lo" (car x) "")
8 [2 \  |; n# W* L" }, a) J            ); if
" Z( w9 T" J: d$ M' ^            (if (= 1 (logand 1 (cdr x)))
, {* d: ^/ n5 A. e              (command "_.layer" "f" (car x) "")
, g" D( ]; f7 [5 s0 ^            ); if
" x- e+ |; v9 s: ^          ); progn
" G5 @/ r7 w" j+ @. v! |" \/ m' \       ); if  ( a; F& v2 Q# O; e9 e3 H9 _
      ); lambda: s, e* Y: i9 j1 O4 c( U# ]
      (car l_s)
$ l9 z8 I: g! e6 k, [; d$ X& W0 J    )
. B" o! W, r3 a7 M    (setq l_s (cdr l_s))
7 X2 b" Z6 k# w+ O. k3 j% j  ); repeat
  p! J% n* i$ g); layres6 O: m% N1 I. q' m5 u4 M

9 V: f  O; m2 ^) z; U- O& v: ~8 I0 Y8 u;----------------------------------------------------------------------------
) ?- P, e6 }: G# ^6 T; Get DXF codes( y, t  U4 X" e1 a4 H
;----------------------------------------------------------------------------
7 ]1 v* Q! ]" F2 Z9 e(defun entgetf (index ent)6 s4 k. ~4 j! i& a5 t
  ((lambda (e)
" f8 r! v' d5 J9 [) F      (mapcar '(lambda (x)" x1 W) k$ z' X) g$ k* ~
                 (cdr (assoc x e))9 L  P+ O7 y0 e
               ); lambda
: Z- i6 a5 k9 l" G4 ?: u% A               index) ; internal lambda function$ `. T# U$ T8 R7 i6 O( v3 J0 A4 c% n: R
    ); lambda- ^3 U( t1 V! ^2 ?
    (entget ent) , M. _  Z$ y, V
  )
. ^% x3 J& V  ~- Z2 p); defun entgetf) G- x, e& M* i
* [+ N% S; ]' j1 O: v4 F
;----------------------------------------------------------------------------
' Z5 J" d1 D1 g6 i; Save UNDO status
& O* u) k6 ]7 _$ V: M6 w;----------------------------------------------------------------------------; |6 Y6 @' m8 X; g/ v
(defun undo_init (/ cmdecho undo_ctl)   
, k+ @% r; d+ S  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
" R) Q7 U7 i1 [' P* f- k2 ^  (setvar "CMDECHO" 0)! C2 I1 U+ a( U) c$ }3 I

7 r# ]0 c% h1 C3 t: y7 |  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
  P2 H: q8 J  ^% s. g    (command "_.undo" "_all")1 V- t0 ?4 G  D/ z
    (command "_.undo" "_control" "_all")
3 q' Y: K: h' U  K# S  ]" ^  )
3 _; C7 Q% P* n2 [: O
9 e; y2 D& i/ i( {5 Q: F  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off
6 I% k. m( j9 R    (command "_.undo" "_auto" "_off")" {" J0 |( p) m) R
  )
+ t6 z0 H% y0 @- M; S9 f$ X, d8 U
  p5 \1 ], Q  ]5 d- R. e- H' ^, G  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here3 B- R. S" L, h! [1 e$ W
    (command "_.undo" "_end")
$ U" v  v5 L+ d) h) W- i  )
* Z# l# |- ~# I7 [& C; {4 f3 F
6 l' g! u; \; d  C  c8 @* P5 e  (while (not (equal 8 (logand 8 (getvar "UNDOCTL")))). N. l, n# _. C/ _
    (command "_.undo" "_group"): U+ A. X/ t  G
  )$ @$ t4 n& e; a
3 o5 d; V0 E1 M% v' n
  (setvar "CMDECHO" cmdecho)
2 U( O% w- s: Y* n# Z  undo_ctl; H& L: Z. r* {$ U  }
); defun undo_init' ~3 n' y; I* m% V" y" O# n; B

" J  n# p7 K, W/ Y/ j: K4 x2 a7 i# x;----------------------------------------------------------------------------
, A8 A, o$ W3 b; h9 L: r; Restore UNDO status
$ K1 m' ~% ?0 e5 L$ b1 Q;----------------------------------------------------------------------------
0 W( y7 K( b. _5 d" Q(defun undo_restore (/ cmdecho)
7 u5 d2 G" i9 _  (if old_undoctl8 u/ V2 _: f: z- n; p; T
    (progn
* V' A2 L" t9 ]+ Y% P8 p7 i3 H      (setq cmdecho (getvar "CMDECHO"))
7 m) z2 W' o% u6 D$ M      (setvar "CMDECHO" 0)0 a6 |  X! g" t, d* t$ ]
# I2 q9 z2 C, h& t+ C' e
      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) ) p6 T' E1 U: m8 J- T# w
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
5 @5 X: Z( J; K        (command "_.undo" "_end")' }. _% G5 k$ Y. Q: b" H- m
      ); while
; S) ^! Z  C: l2 q( D5 q, F; \0 Z. \9 }6 K0 h

$ m0 d0 a2 N6 k. a      (if (not (equal old_undoctl (getvar "UNDOCTL")))
' }, c! ?9 @8 L# {* v' {0 Z; P% @3 q        (progn! P* s4 H) k* h( x* R
          (cond* m6 E9 }2 Y; E) U
            ((equal 0 old_undoctl)' t, L  c2 [$ p& U$ A9 c
              (command "_.undo" "_control" "_none")5 I2 N7 y& m& v7 f" G- Q
            )6 Q$ I" o* r' Q# I- ?1 ]  A
            ((equal 2 (logand 2 old_undoctl))$ N7 o( g' |& E: H  P) e' Z7 C
              (command "_.undo" "_control" "_one")  I  v/ H, N" l# `; t$ T0 \* e  A
            )# h5 j* a3 @" D* I+ e3 v
          )
# ]% P' K( ]# }% n8 n6 ]          (if (equal 4 (logand 4 old_undoctl))
: a( l6 a2 {: c              (command "_.undo" "_auto" "_on")* E4 N- |( O% x6 o: X
              (command "_.undo" "_auto" "_off")
5 c9 ~3 m! v: x% M- {( I) @! V' a          )
5 I1 z) b" d3 h* a) m# a        ): G# I  D# B1 p* a1 z) k4 Y
      )
# n( B) {5 m. K8 c      (setq old_undoctl nil)
* w: _9 q/ B3 m- V% Z9 S1 O      (setvar "CMDECHO" cmdecho)
7 N) D* Y: x0 L' ?8 n    )4 U: u" E+ X0 S+ ?4 S# }6 L
  )# z" v0 P: d" W1 V3 S/ g* m  Z# D
); defun undo_restore) H, @( W8 L# E, J; w

) @& Q) K: ?) z( }/ Z/ B;----------------------------------------------------------------------------
: c% O. T1 y: Y5 I) K# |5 B; Save variables% a6 m" p/ r" o8 H6 e: k* o
;----------------------------------------------------------------------------
2 a( X( `9 s2 e& k$ z8 Z: Z% O(defun var_save (a)
2 e0 a  O/ f# n% }  (setq m_lst '())
, m: K4 i- z! a/ Y+ n  ~" k; l  (repeat (length a)0 \, B5 S0 ?2 K4 {+ u) B- f% {
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
5 V; X( Q. _5 ^0 I5 G    (setq a (cdr a))
- ^# @1 C9 `0 q& u  )
& n$ P6 G4 E- D7 e); defun var_save
  s! a5 E3 b! \2 t
2 t0 M1 D( s6 s& [7 a: O;----------------------------------------------------------------------------6 }. u/ r2 m, d" `
; Set variables
6 a" g8 m* p# [9 ?;----------------------------------------------------------------------------
, N7 n7 I( j7 N# P(defun var_set (m_lst)* q( s8 b! s1 q- @( C
  (repeat (length m_lst)
2 [9 g1 N: u- ~, O8 C- ~) O. v    (setvar (caar m_lst) (cadar m_lst))( m4 S( Z8 h4 |
    (setq m_lst (cdr m_lst))
# q; q& w+ e- j9 b. U  )! _+ \' t9 X, q* c/ |
); defun var_set
* s- e6 W! g! S; Q7 V1 j# P4 O/ i( C7 c/ r2 C* }0 g5 q0 U* M4 v
;----------------------------------------------------------------------------
1 ]0 _$ g6 O, q7 w6 f; Restore variables
8 T/ h5 e* c  A, r; x;----------------------------------------------------------------------------- C9 ~3 G; c* a  q
(defun var_restore ()
9 J% C+ g: }2 j  }. b  (repeat (length m_lst); _% Y9 A2 `! S( H6 Z
    (setvar (caar m_lst) (cadar m_lst))' ]0 r2 m( }% Y7 ^" m4 u  U: W
    (setq m_lst (cdr m_lst))3 q: `, J* e# l$ H0 [
  )
% g+ ?. x) r8 F0 P); defun var_restore7 H  h5 M) S1 q' [0 u( }* ?3 `" l) ?

6 P; L& D( I! D: d;----------------------------------------------------------------------------" |. k% `% K+ z: U# M: E' y& p' W
; Initialize routine ) Y, d1 U- U$ Y  X: E/ n  O  X$ F
;----------------------------------------------------------------------------: W! j4 E; v8 r6 I% \) b
(defun err_init(e_lst u_enable add_fun). b# `: s7 J1 @$ \7 G' N5 i& E" N
  (if err_alive (err_restore))          ; To avoid nested call
6 z0 R; B9 s8 M) e2 [  (setq err_alive T)
) C+ i# `' l, e+ }  (var_save e_lst)                      ; Save the modes
7 @2 p, @' @$ S  l  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status" X8 s' n1 `. M
  (setq err_old *error* *error* err_main) ; Save the handle of *error*
6 ?% J# q2 ^7 k# m# A, x! D  (if add_fun                           ; Add the user cleaner
$ ?5 }0 C/ ^; B+ m) j3 q+ v. E6 O; o7 j    (setq *error* (append (reverse (cdr (reverse *error*))). M. i+ O- o0 Z. Z9 n& E4 }  \
                          (list add_fun (last *error*))
4 Q) ~; Z" r* b  b6 Z                  ); append
3 |  {0 T# T* n' O' N1 M# O. l" G    )
/ m! c, d/ j3 H, p# H  ). |5 w6 m8 F8 z- v* r( A3 x
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------6 M7 h! |, d' I1 m+ h7 Y
; Error routine body, e( m6 x' V& a! U1 q, o+ [& }" @; d
;----------------------------------------------------------------------------) F7 c- d1 @: n
(defun err_main( msg / )                ; Body of error routine
+ N- y5 V! [4 V% F  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs# n/ k& A- M/ Y% p% G" W
    (princ (strcat "\nError: " s))      ;while this command is active...
& v1 ]& s. q7 d; R. u  )- h4 B6 _; q8 {* O) U& p
  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
0 T! c" R5 e: V+ n# i8 F% I6 @3 x4 `3 ?  z2 g
  (if old_undoctl
+ S" c! V1 R' y- q: D    (progn+ a1 F' s: y, @: w
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See8 v" N" U, V" L% a3 L% @4 L: W9 D
        (command "_.undo")              ; if it's in UNOD command
' Y9 J+ J+ p" X      )
7 K- g3 ]1 x5 z( S      (command "_end"). Y1 F8 Y& {  M3 L8 {! t
      (command "_.undo" "1")
  I/ g  j* y2 d, U& B" |      (while (not (equal (getvar "CMDNAMES") "")) (command nil))1 m! b9 }8 n$ U! x  \6 n3 d! Z
      (undo_restore)                    ; Restore the status of UNDO
0 b8 S% _; ^" E' i' `3 w. P3 C7 o    )7 J; o" _5 S) [7 c* ]1 [; c+ B
  )  j6 ~  k" \4 T- U

, |- t% ?2 L1 a/ }1 X! M  Y# \5 n  (var_restore)                         ; Restore the variables
7 [+ y7 N3 O, W  Y  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
" I% Q8 W5 z* G$ L  (setq err_alive nil)
8 W, i0 ]  r0 W& n/ j; P  (princ)% L  y3 V3 R1 W7 b, ?# e
); defun err_main$ v. g/ X* v* W1 X' x* w$ z
; W  S% v0 I7 ?( S) v' \( q% _
;----------------------------------------------------------------------------5 g0 T  Q3 q. z, s
; Restore error status
' g' @" X- Z/ a/ J; F;----------------------------------------------------------------------------
% O+ B) O9 ?  G: z/ R- v(defun err_restore()
4 y" E: \7 R% c  (undo_restore)                        ; Restore the status of UNDO
7 N+ L2 z7 V0 q( T* h4 s9 Q  (var_restore)                         ; Restore the variables3 Q+ L1 \3 |, r- L- ?9 u" o
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error0 d9 p" W/ V. m& d6 o
  (setq err_alive nil): ]( y( q& ~8 [3 i% e
  (princ)
  d! r  S* ^2 w! ]); 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, 2025-2-19 06:59

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

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

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