CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
6 s' d3 i$ a" {& d, h “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
- @5 p' u1 K; R0 Q  @提示:加载成功
# u0 F/ ~2 @7 g& O4 c& W然后使用CLOUD命令,4 x3 M. A! o" |  u
提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
' d) Q) g6 k- C# F请高手指点一下,这个是怎么回事?应该怎么改正?% h" e7 Z& I" q. e- P3 t" D5 `
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx1 p& F: ^% }8 y  }* ]6 Z  h
;;;7 S5 Q( X" d2 f0 \
;;;  DESCRIPTION2 i0 M  K# o/ X# _8 T  O! C" p
;;;     Draw cloud and you can specify the globals variables listed below5 x$ o4 A0 J" Q& X+ Q* s
;;;     to decide the characters of cloud
- c; e$ D+ t# V/ M, v;;;# @) B+ `  A! {& v5 l: e' |/ q. x
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
4 g, j2 _6 W7 \- `8 e2 w;;;
( R% O0 X; {' T( X4 |; i: C;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed' M4 l' V' W9 A8 I" Q/ g7 Y1 Z
;;;           Change CLOUD.001 to use CLAYER to perform the same function
$ `% V" Q$ `* Y0 {' m) {( g;;;           Use the common error routine UNDO.LSP to optimize this program
6 e- I% S$ |! B! j+ x$ K4 R;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE8 [( H$ t1 W7 L. b: O% _
;----------------------------------------------------------------------------
; Y' \8 E9 z2 d' d' x0 f. j( D4 d;  GLOBALS:, w; o$ {; H" y; \  }) i" B1 e, ]0 i1 M
;     cloud_layer -- layer of cloud+ m6 [1 i8 u' N% k3 X  \, q$ I
;     cloud_scale -- scale of cloud) Q  j* W. j. [8 Q1 @. o: O
;     number_rev  -- revision number  E. x6 x( g2 L4 t0 [
;----------------------------------------------------------------------------- W. D$ M& b, d# f. O
(defun cloud (/ locked temp first_point next_point relative_point
" b( I: l9 _# n" m+ G               last_point point_tri point_ref corner_1st corner_2nd length_tri1 d6 E% m' b2 b/ y' f4 K
               length_cloud angle_l_to_f dir_tri repeat_count 2 H3 S( f- M% q, l) l  F
               table_cloud )
# M$ O, ]$ Z- ~9 f        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))5 }1 v: L6 o0 H* d6 n7 R& X
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
' b! O& C1 K$ S  `( _! ~        );if6 b& Z* R0 n( U- O. ^
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
  p& j" j1 V/ a# B1 Y7 C3 M                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))" l2 H4 Z8 `7 H( @( u3 f
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
1 D! P. f9 O% ^- b- r                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))! K; G; \! j( s6 r' e; a

  r6 I/ X1 i7 l, o4 E5 n, U        (if (not (numberp cloud_scale))' Z& e( O: B; j9 k9 n6 v6 z
            (setq cloud_scale (getvar "LTSCALE"))
9 k; w! f6 A9 V, `        ); if( M1 S! [) j/ X& ~0 M( \& U) Q, {* _
        (if (not cloud_layer)$ ~  [7 z( u. c4 Q9 `# T
            (setq cloud_layer (getvar "CLAYER"))
; Z% P4 V% z& R& s        ); if
% H% Y5 o- c0 o( r( Z  ]        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))$ y4 A& j7 f) k6 R
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
$ g* t& T% M1 m$ v# C2 [" P! q# y        (if (= (cdar (laychk cloud_layer)) "No")
9 x# O1 @* l. I/ Q          (progn
) Z4 ]) R: P) t5 n            (laychk (setq cloud_layer (getvar "CLAYER")))
! N% V! r* W2 s# L+ X* f            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))* C2 g  Z4 S- A8 s& y/ x
          ); progn3 u/ w7 W. o% i9 i2 ^& y
        ); if
9 A& F" g; A; m
! V2 y) X7 F& a6 G        (while (/= (type first_point) 'LIST)
( a" W2 J, g, }          (initget 1 "Layer Scale")$ I4 s! x6 u. ]
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
( P9 t+ u. V: Q/ ^+ ]5 @          (if (= "Scale" first_point)      & L) `+ P  l0 _
            (progn
) ~/ Q5 g9 ?* f              (setq temp cloud_scale)# ~* f) u. t7 T# s
              (initget 6)
1 K6 o; }4 J; ?/ a8 W              (cond+ O0 ?. {5 u; b* ~( H
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
, B0 w% G2 @4 F! v" i! F                                                          (rtos cloud_scale 2 2)
, ]; K' D; y& j: a6 l                                                          "> "))))
& j0 K& C5 R: t/ H                  (setq cloud_scale temp) )( y; ^1 ?0 ~( D( a: y
              ); cond
: [1 R' F3 y& y9 b& g            ); progn+ _6 v1 Q6 ?9 g2 G1 [
          ); if/ g! j: V) U2 w: q
          (if (= "Layer" first_point)& O: W2 ^2 W. ^4 f% [6 A
            (progn
9 J. f  z/ O8 ?# ^              (setq temp cloud_layer)7 k. P0 T3 x4 C/ B5 J; J* R
              (cond
  t' b" Z7 a' M7 [                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
. a$ Q8 L3 d9 [2 v                                                          cloud_layer "> ")))+ v7 `) f+ n; O9 g: n7 k- e) F
                     "")
9 u, c! I' q8 E, \) b9 ]7 \                  (setq cloud_layer temp)" C1 F+ u, T% `- [/ W
                )
$ _+ S7 u* O5 ~$ T7 y              ); cond, e+ J3 I! @, Y' |4 q1 ^  H
              (if (= (cdar (laychk cloud_layer )) "No"): `& K  z  B$ }4 r8 Y( O
                (progn
* O# _5 p: l9 G( n4 D3 C                  (setq cloud_layer temp)
4 s) G2 v( A4 \7 ?                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
! q3 E, n& @& g' P8 B/ K# ^( n                ); progn
4 w' `. {2 S2 X  I              ); if% M6 {. Q2 D! _/ q% S( i
            ); progn
7 U( T, h5 w* U          ); if2 J# C% _- G/ Q% W! \2 o: i8 x+ ]
        ); while4 [: {& @  Y/ P
        (setvar "CLAYER" cloud_layer)
0 K1 P. m$ @- A$ d7 P; ^$ Y" F& F: S9 [7 W$ b1 R
        (if (>= ( getvar "LUNITS") 3)4 A. b8 H* j0 E, q" T4 M4 L2 _
          (setq length_cloud (* 0.25 cloud_scale)
% F! K& t* n  r$ ^9 `) p                length_tri (* 0.3125 (getvar "LTSCALE")))7 ?3 z% |" ]( P: B9 b' k
          (setq length_cloud (* 0.3406890 cloud_scale)
: m' M- P9 b9 u) v                length_tri (* 0.438366 (getvar "LTSCALE")))- i# _- O3 p: N
        )/ _& L4 N7 @( B) }* C
        (command "_.PLINE" first_point "A")# \7 s1 O/ S1 I: y8 S/ {
        (while (not (equal next_point first_point 0.000001))
' H7 A# Q$ t2 E! J          (initget  "Close")9 N; {1 w. R! ?
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))' W' X1 Z+ E. k$ ]& K
        (while (and (not (listp next_point)) (/= next_point "Close"))
5 ^) p. \8 M) |# L          (initget  "Close")$ T/ r6 r& J$ ~. ]& x: @, M: W
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
/ r" f# s7 K, h0 O5 y% N        )
' Q! u/ f4 ^0 D" }$ e* o/ O; P          (if (= "Close" next_point) (setq next_point first_point))4 _2 @/ k% O, R; C* b) b
          (setq angle_l_to_f (angtos (angle last_point next_point))! J* u7 r! {1 O6 I0 I6 c9 J
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f)). v/ f/ P: e& p8 l$ Z% Z
          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)! h5 y% _$ O  z$ q- h; [- |* W9 J
             (setq repeat_count 0)9 W* ?) Y$ K1 F
             (if (>= (- repeat_count (fix repeat_count)) 0.5)
1 X4 U: T9 u6 \" z% M               (setq repeat_count (fix repeat_count))( ]8 T" k4 O- l- a/ R, u6 F7 m& z
               (setq repeat_count (1- (fix repeat_count)))5 n4 T% u2 F' t7 h1 l& ~: h
             ); if
/ G9 H+ k$ E3 _. W0 X9 m7 _          ); if2 o/ ^. M/ S: |3 ~" \
          (repeat repeat_count (command "A" "-100" relative_point))- R7 @2 p$ w8 E& p4 N
          (command "A" "-100" next_point)
5 N! g  ?  K0 U          (setq last_point next_point)
5 n  T4 P" J  R* R7 O! g, t6 d        )
: C- y+ S+ Y2 Z        (command ""): U* a& c- n$ C/ k% ^, c6 x8 Y3 G  T/ v
        (if (= (type number_rev) 'INT); b# O5 ]- H! {; L
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
. F  @' K: @8 \4 a           (progn
4 ]7 V/ b: F$ N             (initget 5)
+ |" l$ f  s9 W- P# ~& Q) C* x2 E             (setq number_rev (getint "\n请输入版本号:"))0 o$ x* u! z( A$ _& U
           )) ~! _( R* C* A) x; ?  f, A  d2 c
        ); if
+ K# \4 k0 J, e$ t. T        (setvar "OSMODE" 512)8 t0 b6 \0 k: @3 Y
        (while (/= (type point_tri) 'LIST)1 N1 t' k8 e& J$ f3 d# I
          (initget "Number")8 U, w; a3 ^' T" T- Z: J- v1 {
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
2 J4 t& b- p2 M( s( w4 W          (if (= point_tri "Number")( l" ^; w! u# A& l5 X9 d5 P
              (progn+ ]* d% C4 H( e! }8 x; V$ r
                (initget 4)3 _! Q% m/ N3 {% c- L9 r
                (cond1 g% k9 H2 X, R' \* K
                  ( (not (setq temp number_rev
* I% K7 L5 y% J6 R# S) K                               number_rev) y  J% X5 k  v$ ?: m8 c0 e8 ^4 u3 I
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
9 d6 l! a" k+ ^2 J8 L& m' y4 j$ `9 a! V                    (setq number_rev temp)
5 [. ]5 O* j1 U# Q                  )
! F: S* y# I9 H) _1 L                ); cond
4 Z( B) S( f8 F! F2 R              ); progn
% p; r% Z  R. ]9 K( R1 G  l          ); if
! t/ v5 w+ f" c! m6 v        ); while
6 o4 e2 A% P) a% e4 n        (setvar "OSMODE" 0)
% u0 T+ Y  h- H6 {, P- H9 h        (initget 1): q; k- g. l5 L- p& b$ @
        (setq point_ref (getpoint point_tri "\n请选择方向:"))' Y/ @4 n! U$ U) |7 C
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))6 y9 Q# |% L! E. {; m
        (setq corner_1st (polar point_tri
7 F2 F% i; m/ }& D8 {/ G" _                                (+ 1.570796327 (* -1.570796327 dir_tri))
/ V' a! c- K2 k0 p1 h                                length_tri
- @5 T8 h: V; Y3 M$ f                         )
2 W! [! q3 S$ z' C4 f8 b        )% @( T, W7 i" Q8 h7 D3 `& X
        (setq corner_2nd (polar point_tri
" |) w1 {8 N* ^' I4 J                                (+ 1.570796327 (* -0.523598775 dir_tri))0 v" i8 d% |4 Y- c
                                length_tri, d, w7 S. r; Y0 M$ D0 N4 F# P; F
                         )/ J- r& ~9 D5 D0 f* O+ U0 |; }
        )
5 t) j) v4 h0 z/ C, z$ N! I  d7 }* C        (setvar "CECOLOR" "2")
0 H, D" A& R8 g7 G6 m& i2 e* q        (command "_.pline" point_tri corner_1st corner_2nd "c" )
- T9 i" Y$ |& A* F        (setq textstyle (getvar "TEXTSTYLE"))
( X9 J: ?0 `) B: C  X- z# S        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")& L# c3 `7 f3 d0 L) R
        (setvar "CECOLOR" "7")
# l' f- S# l  d. X$ e# l+ T: ]        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri)). O# k! s$ b  V. a
                  (* 0.4 length_tri) "0" (itoa number_rev))# D- t9 ~' g: \) J3 o
        (layres)) P! W. O6 i) X- i. x0 X
        (err_restore)
" q1 U0 z% J; Z        (princ)- I2 h# P8 r. J) b
); defun cloud
2 ]  ~% O# m1 k6 {$ C3 i
% M/ y8 `  @5 V1 x+ y0 a(defun c:cloud () (cloud))/ w# K0 p" k1 a0 l  p4 X
(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy5 g6 s" \/ L+ B/ c* P
;;;
3 g5 a; _9 ^+ t* x" h;;;  DESCRIPTION
) x  A) L! i) X5 `% U  e" a/ n;;;     These are general error routines which can be called by
  U: K3 u: k" H: l! D( @4 `;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference0 q# }3 A/ i; Y: w' D: |' g
;;;
. s; {# ?7 j3 s! h( X  N;;;  SUBROUTINE INCLUDED IN THIS FILE
' N6 c" c4 ~2 j' a, f9 u;;;     UNDO_INIT
4 `* T. \1 K* i;;;     UNDO_RESTORE! g9 f: ]% G0 Q4 m' a8 h1 D
;;;     VAR_SAVE 4 h3 C8 H# x  T" G
;;;     VAR_SET  ' H  j2 z8 q. I! i2 c) l6 i( G% _  Z
;;;     VAR_RESTORE( |4 g5 j. M1 w1 y) p
;;;     ERR_INIT 8 q3 H( `1 F# G& z% z4 K3 Q7 B, U
;;;     ERR_MAIN
: K" z" j% i( s% e; {) k' e;;;     ERR_RESTORE
( F8 J1 v7 _! K: H9 g$ \$ _" Z;;;- Z( f3 l/ |7 _: E" w+ v
;;;  DATE: 10/17/98; 03/31/99& T! P; z. w9 Y! r
;;;. w- g0 X! H0 [# L1 w5 i7 c2 I* [" ~. a
;;;  HISTORY:
3 M8 ]  W! x/ N" C8 r9 N;;;    Add routine of mod_att# ~+ x# N" Q( t+ N' B* s
;;;
9 Q. V' F: K7 s* w7 x& q;;;  USING METHOD
( u( M& G" o1 M3 l  S9 B! m;;;    ERR_INIT:
! g+ s# v4 f! ?;;;      This routine initialzes the error handler. It should be called as:
* Q% Z( V' {3 R% o;;;4 z1 m$ D4 H7 T" N" _/ d
;;;      (if (and (not undo_init)
1 j  `( m, K; Z* R; u;;;               (equal -1 (load "undo.lsp"  -1))
' ], ~3 T" A0 H' s0 f/ b;;;          );and
0 v6 s3 h6 O  q% U' ^;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
6 z. h1 D% _; q% P1 w2 l2 [;;;      ); if3 \* N. l! C+ C# K8 T2 X9 G
;;;
) y! H1 B: P+ c3 l& u- F1 R;;;     ARGUMENTS:
' O& {6 s& l' f( ?;;;       err_init Takes 3 arguments. ( Z/ z# ?9 |! {, r- u
;;;     1. - The first element of the argument:9 X! i$ {: H7 v+ W6 K4 }8 |
;;;          This is a list of system variables paired with5 @' k# b6 z1 Z- \0 F6 s
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE"); \+ e7 Q) \+ `" E# G
;;;     2. - The second element is a flag
! M& t$ M+ @& p0 f# Z;;;          If it is true, then in the event of an error
) g- w) t" R$ g5 z% F; ^% J;;;          the custom *error* routine will utilize UNDO
) B  r; R. }6 B; |;;;          as a cleanup mechanism.( p  d" C2 ^% P8 P0 W+ U3 n
;;;     3. - The third element is a quoted function call.
" P$ |; }. W# u8 j! `) R;;;          You pass a quoted call to the function you& P5 s$ Q6 q& @; d. Z
;;;          wish to execute at the end of nomal routine if an error occurs. 4 {1 K$ ~7 C  p9 k# l& c
;;;          i.e. '(my_special_stuff arg1 arg2...)
7 [" w- h$ b0 t! i;;;          Use this arg if you want to do some specialized clean up
8 H5 p2 l- f0 V7 M2 ^;;;          things that are not already done by the standard bonus_error " }' Z8 J; V0 K
;;;          function.
7 D0 \: P8 b  l- G0 X+ b;;;
9 n4 L$ Z- |/ @3 I;;;    ERR_MAIN: Body of error routine; J2 D5 u2 \. h  E6 F' Q
;;;
5 V  i6 }# f7 H/ ];;;    ERR_RESTORE: This routine should be called at the end of command to
& r0 }" B/ r  G& _/ j;;;           restore the VARIABLES, UNDO & *error*.
3 N% Q9 Y6 r( S- @' J;;;+ C& V$ \1 k' S% m* ~4 G
;;;    UNDO_INIT: Initialize the UNDO status
2 k8 z# W3 k/ m' a5 K: g* V8 M  B;;;# \7 O% K3 @9 ?6 A' ]: z3 a
;;;    UNDO_RESTORE: Restore the UNDO status
2 a8 B0 L# [2 x) O;;;6 H! l$ K3 U& L
;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")$ `) ~& l9 l: H+ \  @; O5 Z/ z
;;;
, b0 I9 {7 d# \7 L6 q* W;;;    UNDO_set: Set the variables. the argument is like# h, N( h& t. T/ v# H
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))- E8 i$ T0 d9 Y2 L% X- @. x1 i
;;;, g% e3 f+ u, s6 _: U
;;;    UNDO_RESTORE: Restore the variables
" B9 R$ W; L6 Z! L;;;* e4 T0 r" g, x
;----------------------------------------------------------------------------
1 o* C7 P6 C  \/ i7 f6 V;  GLOBALS:
# d6 g1 J. q, Z) ?8 q;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)% D) ~7 u+ V; K( Q
;     m_lst       -- list of variables (voided by VAR_RESTORE)8 B+ d: L$ @$ N' F* B
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or* j, X. \0 Y/ m1 d
;                    ERR_OLD)( N( h; [, b+ p4 c; J
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
5 u# M6 w/ K0 l. U( U0 K* p;----------------------------------------------------------------------------
% h  r! a  f7 U* T1 W0 K
  d# q/ H6 f  S/ z1 k, y;----------------------------------------------------------------------------" j& J6 }6 m- U
; Modify attributes according to entity name, attribute name, dxf_item
- _! Y+ m( Y* r, t1 q9 F6 W% f" e8 s3 P;----------------------------------------------------------------------------
; d  W: T$ y1 J8 g8 B( y9 z(defun mod_att(ent id dxf_item)        
3 C& M  V, ]' @9 m/ d& i  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent)))); p! d6 K8 J8 W
    (setq ent (entnext ent))
. a  u1 h# ^) }  q8 o  ); while  % ]+ ^$ x- Y( m% F2 ~
  ((lambda (x)
0 O9 @. k( z+ x2 {9 m2 N        (mapcar '(lambda (y)
: T' q6 b1 u1 n  V, \! [4 k                   (setq x (subst y (assoc (car y) x) x))! H/ ^' ]$ |8 H
                 ); lambda& S: {/ Y1 r0 D% T$ r2 ?/ C
                 dxf_item+ C# i' G) _1 u2 u$ y3 o: S
        ); mapcar
8 R% ?* }( p( d5 e+ l     (entmod x)  f* _; O7 x/ T
     (entupd ent)
# s/ l# J! n( j& O7 y: ?- z   ); lambda
! a5 R# l% L. f6 Q0 M9 z   (entget ent)
6 Q5 F: [: r$ |+ \' w- R+ V )
/ c4 r! k+ }/ T1 O% ~0 R* G: S* t); defun mod_att
( J0 E, Z4 \! Y1 f4 m. X4 H3 q, n+ q) J3 X
;----------------------------------------------------------------------------0 ~. D; U. r6 ~
; Check layer status, return a association list which contains layer information0 t% _; A; G6 e& }, x
;----------------------------------------------------------------------------
. [# c" _( A$ ^" c. W- R! Y7 h(defun laychk(lay / l_sta)
' z2 f: ~* k. w+ R% @1 ]9 p4 T  ( (lambda (x)8 {4 \) P( g: L; c$ d) _! {
      (if (not l_s)- Z" w( x, b9 ^- u, O2 R$ B6 B
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
# O" ]1 `7 t; T2 j3 X      ); if
) i) b; t) ^% |  ?0 ^  t% v. J7 Z    ); lambda 9 G( u5 z, w. x  ^
    (getvar "CLAYER")
* x+ k6 e2 j  O" J7 P2 |) |5 G% T  )9 |7 X3 N3 e# {! }* G1 W8 {
  (if (not (tblsearch "LAYER" lay))
0 Z$ R* _8 {0 e    (progn  
6 F/ _$ X) E6 }0 ~8 t      (initget "Yes No")6 K6 C! W$ w5 [0 p. q4 }
      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
4 v* R% i. o2 E" c        (progn. t! O+ ]# n+ Y/ W! j( M3 I* a
          (command "_.layer" "n" lay "")
) `" {; F0 d! P0 [8 r0 Y; i          (setq l_sta 0)' S% l, @' V! }- Y$ c& R- u4 ]9 M
        ); progn% r$ ?; _! e" Z8 m& z2 `' O5 e, k
      ); if
- t' Z+ M1 J8 e7 X    ); progn
' U* I0 M3 l* O; @" q& _    (progn
1 M) K5 I% A: m2 f      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))$ W  c% K, Z$ s/ \% b! p$ i# J% z
      (if (= 1 (logand 1 l_sta))3 `6 Q1 s8 V  a  K0 y/ v+ w+ \
          (progn
! B, ?+ f0 o* d5 R0 j- Q) [" f7 A            (initget "Yes No")
8 d2 P) |5 F3 A3 B' ?+ X0 H" L            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")
+ Y4 n. f5 Y+ J2 H              (command "_.layer" "t" lay ""); I1 S5 \  `, k. W+ f0 ?+ b
              (setq l_sta "No")+ q+ o: x# p, N, ~0 o& a: L
             ); if3 i$ \! z8 B3 Q6 V
          ); progn
! L! g% V) A- b      ); if, W6 c/ S1 ]# I. V7 x: p
      (if (numberp l_sta) 8 J+ a( i3 N9 F" T. r+ b  k  X! A
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if, O2 N; ^/ ?+ ?
      ); if
+ Y+ y7 P' H1 o9 S    ); progn
. v1 O% \! j) G  ); if
! [. A! z) U5 e- E4 t  ( (lambda (x)6 ^* o1 u* ?' C/ h+ L
      (cond & v- f1 g- V/ q' J( B) s
        ( (not x)
2 r1 S* O. q- `6 F. |          (setq l_s (cons (cons lay l_sta) l_s))
" G0 q$ b5 }2 V) C, X3 R4 Y- f: m        )
- z) a4 e3 Q! f4 a        ( (= "No" (cdr x))$ H& D$ ^0 T) {6 r, o  \/ _. s
          (setq l_s (subst (cons lay l_sta) x l_s))' ~) Q: s8 p% E2 B$ f) z2 D% B
        )
+ O5 u. c9 h8 {4 R6 u' f% y        ( T l_s)7 h2 y2 @/ j- @; V. F
      ); cond: V# d( x8 @, D; G+ i
     ); lambda; v; r+ [* p& @7 X6 P1 S4 z6 @
     (assoc lay l_s)8 c! a7 y- s7 Y% T1 y/ t
  )
. t- w" m% A" ^" _! _! `+ n/ u7 q* p! |/ K
); defun chklay
4 ]8 _( ]% j2 c5 s$ n" R$ E$ F$ V
0 F- [5 F7 {8 @' r5 x9 r( Y% A;----------------------------------------------------------------------------
) }+ b6 l. e7 q1 X/ ]: T; Restore layer status according to association list l_s
3 L  p( F# b# W1 H9 f8 v;----------------------------------------------------------------------------$ ?8 D! w0 u8 ]0 C5 L! H% |! |
(defun layres()
, D4 d4 B* o8 g- |0 H- N  (setvar "CLAYER" (car (last l_s)))
0 Q! i' {) |/ m  (repeat (length l_s)
  r! T9 m" |0 v. L$ |# w) {    ( (lambda(x)  
0 {- Y" V" E+ |6 P$ g, s. D        (if (numberp (cdr x))
! e) u; ]0 u* y. q7 j$ `          (progn
' e; v0 U3 f/ {- u; H( \* u            (if (= 4 (logand 4 (cdr x)))
1 }+ {1 s4 W2 x$ d& {+ @2 `8 h              (command "_.layer" "lo" (car x) "")" Q6 t+ F* V4 \- @  j" R
            ); if# F+ I+ x8 v; X" K
            (if (= 1 (logand 1 (cdr x)))
- N  Y6 L1 \1 }3 @% \" ^. ]% l/ O              (command "_.layer" "f" (car x) "")$ e5 w0 W3 ~) W
            ); if
- v6 W" M/ s9 v8 h$ F, h          ); progn/ |& K* V4 \! T8 [6 H
       ); if  
  [2 D" A( J% ^. B2 I      ); lambda
5 r; J/ T5 @4 {. W4 ~% s      (car l_s)
4 X# @- U$ y+ V1 s: E3 V    )
$ s4 B8 y. Y' S- e( X2 k    (setq l_s (cdr l_s))- ~7 J9 A7 D4 i4 h6 y! v
  ); repeat
1 [- ?6 f" e: N); layres9 \' h+ C0 z5 x) X/ K7 a) x

1 C$ Y6 D) R- O;----------------------------------------------------------------------------
8 ^& z# @: [) R. n; Get DXF codes
1 \/ N+ M* t- {;----------------------------------------------------------------------------3 W# r2 \; V$ n4 B
(defun entgetf (index ent)
* Q6 h$ y! M* h2 N  ((lambda (e)
7 @. N  q& @) n) x  T* y8 V) q, P      (mapcar '(lambda (x)
' a: [$ Q% T" Q$ {* x; x  X: i                 (cdr (assoc x e))
, }# u6 r, y9 t5 A0 l3 w               ); lambda
& l5 ^1 e6 g$ K2 a2 f* y  o8 A               index) ; internal lambda function
( Y2 s( Z' F+ ]8 E4 y0 h    ); lambda1 a  @+ a& s& l7 P" O/ W
    (entget ent)
* U# z6 S4 b" Z/ T# C  )
$ X9 e$ n+ d! Y" c$ @, U( Q); defun entgetf9 c0 S4 G& v% p* v7 l: {  _9 w

3 v* `) u. ^4 a' m$ N;----------------------------------------------------------------------------
, F, {8 g! W' ]' u8 y6 x! V( T3 y; Save UNDO status7 ]; N) I2 p, \2 c( K% j: {
;----------------------------------------------------------------------------
) M6 c+ `' i' g$ @(defun undo_init (/ cmdecho undo_ctl)   " n; @5 f7 |, G; |/ }, D8 s- C. A
  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value5 G# W3 U' n$ _: N: w% @. M
  (setvar "CMDECHO" 0)" G7 B( R' u+ [7 C0 a9 ^' s

" x7 B+ `3 q: Q+ [  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable( t/ N$ b8 [! V+ Y1 H
    (command "_.undo" "_all")
4 h7 m; a" m. ?0 ~% R- L    (command "_.undo" "_control" "_all")/ K' r0 z! h2 V/ [9 {0 D
  ), z) C) k8 o, G" I6 w

2 x* [# r! j4 j7 B! O  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off; ~: K  Y0 ^0 @5 E
    (command "_.undo" "_auto" "_off"): X  }2 `' `4 q" G4 k
  )
* r% V6 v$ E7 @5 m5 K2 ?+ ?
0 ~% W# A$ |" n( [9 b) ?  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here2 @* B. A) r& q6 Z5 `# r: L
    (command "_.undo" "_end")
4 O  h4 _$ @, d0 M) c2 A8 A. P1 W  )4 _* @7 G; [7 Y" }4 r1 _; p" a( T

" L- s; ~$ L3 X4 q* J  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
% f: D4 B+ i8 K2 K" {9 X4 }. ~    (command "_.undo" "_group")
. [  F& g) s, k7 h! M9 i  )6 T" @5 o; K9 W. N3 ?

) }. e& ^% V3 D  (setvar "CMDECHO" cmdecho)
) y7 r. b3 W) o  x* V& F  undo_ctl
2 n$ u9 ]# T" L6 X9 `. d); defun undo_init
" z- K- _. w; r9 C5 Y
4 ^% G3 k% h3 j;----------------------------------------------------------------------------
, W" A4 k. h/ p6 K; Restore UNDO status8 U$ F8 C$ `3 d* g7 M0 ~- U
;----------------------------------------------------------------------------
3 m/ U' m2 x. a+ m/ x  t. |# m(defun undo_restore (/ cmdecho)
3 p1 X9 n6 _% ]) c$ Y1 o  (if old_undoctl
0 e. k( y8 R2 B    (progn
- Z# F3 @. |; W: N' f      (setq cmdecho (getvar "CMDECHO"))! R" Z) O4 Q: ], b
      (setvar "CMDECHO" 0)- D6 E: I( O+ t# _$ d
- J6 @# a. R8 E8 a5 u7 L+ r5 Q
      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
4 o7 R: a1 e4 H! ?8 k) L+ ^( Y' a2 c2 T) c      (while (equal 8 (logand 8 (getvar "UNDOCTL")))2 i; }7 Q, F" k) s
        (command "_.undo" "_end")
2 O) U0 m0 T$ r3 y- d. h      ); while
- j" c& _8 @  @5 B: E  a% |; F  n' D, W* Q
/ Q/ ^! w0 d& w- T4 \3 E0 Z+ |
      (if (not (equal old_undoctl (getvar "UNDOCTL")))
6 E/ K$ H3 d$ k8 e4 @; G        (progn( F6 Y2 q; ?  t$ ?
          (cond
* Y3 S- j/ H  l3 Q) p' m2 Q            ((equal 0 old_undoctl)7 w  q- ]6 P( B# J' J8 h3 z+ I' J
              (command "_.undo" "_control" "_none")
" e4 q- i# y* K9 _2 ~4 F            )
7 O1 n7 `+ Z3 s, m$ A$ y            ((equal 2 (logand 2 old_undoctl))- o* I# q7 p5 \9 @
              (command "_.undo" "_control" "_one")) b2 M9 s& v$ ~. ^1 s! H6 N5 G
            )$ Q# N* d" `  `' p5 x
          )# g4 j" `" [5 R% b  c1 F* Y
          (if (equal 4 (logand 4 old_undoctl))
9 }, T' e  [$ j              (command "_.undo" "_auto" "_on")
' E8 D+ l% |# ~/ Q' [# m( \" E              (command "_.undo" "_auto" "_off")
7 J7 ]- _2 o& k+ ~- F5 l          )
$ Q/ O$ T( Z, x7 C# G( U* w        )4 d* T1 S8 g4 ^# \$ Y; \
      )" m4 g5 a" G7 r- Z8 {
      (setq old_undoctl nil)
$ ]% I2 t0 k$ }% l; p1 `( d* d8 i      (setvar "CMDECHO" cmdecho)7 _8 R6 O2 h, _* l- w$ p
    )6 c+ P3 d% i- I$ Z$ H/ ~" z" T  b0 O" m3 S6 h
  )
0 q  q# _; T9 p8 h); defun undo_restore  q+ y" w' r- `+ [0 x/ L

: u' V* f2 L1 l$ `% |+ q* y0 ?;----------------------------------------------------------------------------
$ |& \1 \0 u+ C; Save variables$ ~; e# D" t5 S0 K
;----------------------------------------------------------------------------- a) P3 c1 }# d0 T0 C6 l. |, C# R9 K
(defun var_save (a)( l! b: d$ w4 F4 P) V4 U, x
  (setq m_lst '())9 b6 J/ c) o$ t) s; \: \
  (repeat (length a)/ Z) D& t# h4 Q& |% t  V( S
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))4 i3 f( {, C1 E# j6 ^
    (setq a (cdr a))
) y5 [( z5 U: h% _  )  Q! @/ \& c% T2 J+ @3 q
); defun var_save
9 y2 M& C: D+ {# f/ E* [% N& V+ y6 ]3 Q* v
;----------------------------------------------------------------------------4 w+ v; U3 y% w# S1 Q5 L" H
; Set variables6 \; ]  _: j* \4 |, A# G
;----------------------------------------------------------------------------# I; b0 O" [% j; d" `7 Q
(defun var_set (m_lst)
5 a  O" l0 }. }+ E% l# W" f  (repeat (length m_lst)
5 Z' c1 i- U& o3 F2 c5 m- x    (setvar (caar m_lst) (cadar m_lst))
" `# t' s9 z* y3 H/ C    (setq m_lst (cdr m_lst))
0 O3 e; `  |, g& {  )- N: T2 M8 L6 W9 W4 X0 W: B1 Y
); defun var_set5 A/ ^, W" m. `2 p+ L5 M

+ H" C, ]: P1 U2 G) v;----------------------------------------------------------------------------
! P( y5 X/ ?- N$ a; Restore variables; P  `/ ~# z# M& d7 W& i7 k* I
;----------------------------------------------------------------------------. |& A4 x0 V8 o* X# S
(defun var_restore ()
# m0 a5 {2 {& g' u  (repeat (length m_lst)
$ J0 E1 Z; [: k, r) I    (setvar (caar m_lst) (cadar m_lst))" H. F' D% q9 ]( l# F; U# G
    (setq m_lst (cdr m_lst))+ p# c- N+ o" m
  )
6 G2 E) j; t) t, }); defun var_restore
8 F7 P: V- M8 X8 o6 T5 D. E: B# v
( e" S4 R, h+ F% Y( u4 [;----------------------------------------------------------------------------; S3 X3 I# i: H0 `4 @1 Q( B. e3 t
; Initialize routine 0 ~) D) P+ w8 @( u
;----------------------------------------------------------------------------! p4 ^9 X+ s! [5 [: Y2 |) t
(defun err_init(e_lst u_enable add_fun)
, }0 v) _$ g7 S( x  (if err_alive (err_restore))          ; To avoid nested call6 {: U2 |+ b, [
  (setq err_alive T)
% N. c  x+ e+ D- X9 [, G+ v  (var_save e_lst)                      ; Save the modes
% o+ d6 y' J( b# U3 N/ v/ `  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status
4 k* |/ s! y! `" n; @8 p1 s  (setq err_old *error* *error* err_main) ; Save the handle of *error*" ^. y  o$ W* G4 B% C
  (if add_fun                           ; Add the user cleaner
- @7 |1 R; j9 z    (setq *error* (append (reverse (cdr (reverse *error*)))5 {, a" _( m7 Z/ ~+ r
                          (list add_fun (last *error*))
9 U0 b5 V/ F+ o4 J1 B) p                  ); append- J( Q( u& h& Z# `, Y7 z$ ^
    )2 ?7 M! T( x" r( F2 w! p8 ?! N  E
  ): h6 [' p+ O3 ~, k* x' P
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
* E! f- E. P+ _; Error routine body
& R8 `7 Q# X8 Z# P;----------------------------------------------------------------------------" s0 O( |' A, a4 ^
(defun err_main( msg / )                ; Body of error routine
+ `% B: b* ]2 V) K  W3 n  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs# J9 g. T* D& ^/ C$ ]) }
    (princ (strcat "\nError: " s))      ;while this command is active..., ~  l4 v# Q. [1 G; j: ^! p
  )
& B- i$ }: V/ {3 w$ K  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
6 J6 t* u7 ~3 a( }7 K2 r. T6 L" j8 c9 w. y: {
  (if old_undoctl" U& z6 @, W% p6 J3 V4 z
    (progn$ ^- g* d3 O5 g) P5 G
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
0 j8 X, Q" w& l        (command "_.undo")              ; if it's in UNOD command
  b7 D! p! m$ n/ \! t, x      )
/ D' L# Y; z- E; c. _4 l, x      (command "_end")8 b0 \1 z  I0 b. x+ p
      (command "_.undo" "1")0 U2 z. @; D' \8 R' e7 r
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))6 E& k/ d# f3 a* a# P3 y
      (undo_restore)                    ; Restore the status of UNDO
% I, C' I5 T8 q3 u& t    )
6 n( Z/ S$ M9 f4 Y1 y  )
" [7 [+ m5 U0 U8 E( }3 {. L$ e" T" b7 R$ f4 ^/ U
  (var_restore)                         ; Restore the variables6 f* N" B) e9 [  e6 `' H2 p
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
& v' m9 G- V3 R( C  (setq err_alive nil)) }( a" s' F+ ?) C, g2 c1 ~
  (princ)
3 X( {) i2 J5 W; [); defun err_main# k( z9 J* S9 a6 q! J* s6 E

# d/ R( N6 C4 I/ H. G6 [4 {;----------------------------------------------------------------------------6 z* x. r, H; o2 z# S" J
; Restore error status' C) @* N. b5 G; E
;----------------------------------------------------------------------------$ l6 r! a2 {2 Y
(defun err_restore()
! t4 }( ~* x8 @2 Q5 O  (undo_restore)                        ; Restore the status of UNDO2 W. D& A$ E+ `2 k  p- a
  (var_restore)                         ; Restore the variables: W" O; U3 B4 z2 G5 }+ M- r8 Q
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
3 h- f! G+ m* E) [: Q7 d$ i: O  (setq err_alive nil)
& W% n$ o: _0 w) d5 R7 h  (princ)6 \9 }- i& u- x) h6 ]$ o0 E
); 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-5-27 05:08

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

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

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