CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
6 X9 {  R% \) ^% G! q: ?! h “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
. Q" F7 W7 I/ y( ~% w4 p& s提示:加载成功
5 r8 L5 _' U' f. f2 q) c然后使用CLOUD命令,
; g, T/ E" M% }+ @+ s" C9 P5 i提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
* H6 d7 N# G0 P; ]6 B请高手指点一下,这个是怎么回事?应该怎么改正?9 S# ]+ `; ^5 |1 }5 H: j
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx3 Z& U- Q3 L  f, t2 E4 {
;;;
! C9 ?& p, @, x3 @6 K2 H: Y- W;;;  DESCRIPTION: }% D+ e. Q8 Q! g! a$ C
;;;     Draw cloud and you can specify the globals variables listed below
- N$ A8 S' ^8 z1 G% F;;;     to decide the characters of cloud9 _* b0 f4 T- {1 l- A; D2 x6 @
;;;! o& w9 `' n% S2 s( [* b& z, r) Y3 x
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98* A3 P: F# Y5 ]- x( z  Q9 J: S
;;;
: ?. b4 A  d5 x& [1 q: G' p; k;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
  p4 t* D& M. R' I; \( w;;;           Change CLOUD.001 to use CLAYER to perform the same function
% w5 o- a) ~. J" {& H$ m, A" X;;;           Use the common error routine UNDO.LSP to optimize this program
8 L; L" s+ i5 O;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE& ?5 Y, I1 M. y% w: D
;----------------------------------------------------------------------------, x8 ~$ O( u9 f7 ]
;  GLOBALS:
  R0 F$ m, p1 x7 t" X( Y" p;     cloud_layer -- layer of cloud
* U" F; I3 e- E7 Z$ c4 s) {;     cloud_scale -- scale of cloud
6 s6 x4 S0 e( u& b6 B;     number_rev  -- revision number, n) U7 H# q: N0 Q( w2 ^+ a; H- }
;----------------------------------------------------------------------------
4 B; o5 d$ I# [) X: a(defun cloud (/ locked temp first_point next_point relative_point+ V/ ^% y7 p7 Z
               last_point point_tri point_ref corner_1st corner_2nd length_tri
; n; z5 x$ ]1 @% j- J& p2 x               length_cloud angle_l_to_f dir_tri repeat_count
& y. e& I, |, J3 l/ Z6 L+ [* i               table_cloud )' u/ J- ]0 x( X$ \7 i
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))! f# u7 w' `* G8 A+ l5 S
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))8 m0 ?* d1 C; _' x) k
        );if- K) N; s5 P7 H8 _7 f9 h
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
  }! n' C$ q4 |" _                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))( @( Z$ J5 _& E2 n2 n4 R/ y
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
2 J5 r0 t8 C2 |4 ~5 i: P                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))9 L+ |7 N8 D/ Z' [( I# E( y

; n; ]$ w- h5 d9 o4 N        (if (not (numberp cloud_scale))9 G* k2 F( u/ z% g9 `: H5 F
            (setq cloud_scale (getvar "LTSCALE"))
0 j8 k2 r# ~+ b# T2 }        ); if
$ C0 b$ ^$ [  Y6 n        (if (not cloud_layer)6 o+ k9 t$ Y* u" U' k( ]
            (setq cloud_layer (getvar "CLAYER"))
5 B% ?/ U0 C7 h; J. ^' x        ); if# s# {( r. k( d6 t6 ^
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
) z* }% y! d6 z( A; b        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))0 H5 p. m9 x+ v/ N  c
        (if (= (cdar (laychk cloud_layer)) "No")9 _* T0 ^1 R4 n$ ?4 |! X3 F1 Z& m7 @9 Z
          (progn6 w- I8 K  L9 t: O& _( T- q
            (laychk (setq cloud_layer (getvar "CLAYER")))
/ j/ e+ }( E3 h' l1 S* o8 d3 o- B" S8 _' F            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))) j4 T" w. b4 c$ W% k: j+ }/ V" J
          ); progn
" ^! g! `/ U( m7 v        ); if  r5 r8 E# F) g% c8 q! L

$ G# `8 |6 R5 C        (while (/= (type first_point) 'LIST)2 y; z2 |: m# S  d7 {
          (initget 1 "Layer Scale"); p& j7 e; y" p
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)/ o( W( w; k2 b! A+ L- \
          (if (= "Scale" first_point)      # z) m; M" T' }( v
            (progn
2 J. [, @/ o; M3 r/ L) A              (setq temp cloud_scale). J5 C( l, `0 u. I: T8 d
              (initget 6): }. @" H4 |) E; ?
              (cond( c4 a3 w$ ~+ f  {8 D& F
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
( a$ J- w" r/ }/ `% h$ h& q                                                          (rtos cloud_scale 2 2)* W2 x( b1 X5 g7 C) ^
                                                          "> "))))
) ?! |* ^' l3 L3 H                  (setq cloud_scale temp) )  o1 ~2 t! \8 V0 |2 @
              ); cond
# g/ G6 T0 u+ f5 t            ); progn% b2 G1 W1 @2 z2 G) Q
          ); if
2 U8 P& K9 E. i% Q$ [6 Z' n! c  ]          (if (= "Layer" first_point), k" L+ g2 l* u2 W$ o$ u
            (progn
2 |9 v$ u" l) K3 |& E  o! Z              (setq temp cloud_layer); q/ u  i5 L5 ?5 E% [, p
              (cond
  \2 \. p+ [* ^+ ?) U6 `                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
$ a+ @0 {# R+ r: i                                                          cloud_layer "> ")))
! A( _% c1 S* D* C                     "")2 F! ^9 o3 C8 N8 G) S
                  (setq cloud_layer temp)
4 P( T" @- E; ]. G) k                )
5 u8 b  f. b; A! n              ); cond
, W5 o, a# U0 {6 H+ l' `5 P  U( u              (if (= (cdar (laychk cloud_layer )) "No"): }9 E% p7 T% z0 J0 O
                (progn5 D9 G. ?# b, b, q6 H; d
                  (setq cloud_layer temp)
# o/ T- c+ v' i0 }; o! l) g) i                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))" \$ W+ I; v# m: \8 j5 v
                ); progn
( I& k8 m. O5 M5 I, ^6 d% e3 z              ); if
$ y) p, h9 E) v$ O9 I            ); progn) m- A' U% x9 U! f
          ); if6 g  O0 F! d8 O6 Y1 R( Y
        ); while
3 P+ |& D& u5 e: g6 }% n        (setvar "CLAYER" cloud_layer)/ w2 D& W! m" A, U
: C# V9 r) s$ y% f* r2 ^
        (if (>= ( getvar "LUNITS") 3)
7 b6 I0 `5 v  X' @1 |& W          (setq length_cloud (* 0.25 cloud_scale); i) R: S7 k' [, n1 ?
                length_tri (* 0.3125 (getvar "LTSCALE")))
& c3 t. d* K) k6 |0 q9 U          (setq length_cloud (* 0.3406890 cloud_scale)" q. ?8 c, B5 f1 n% f
                length_tri (* 0.438366 (getvar "LTSCALE")))
. v4 n: E2 x9 ~1 Z2 o7 m7 ?- J3 q        )2 x' p4 M. t; {3 l+ P; T4 c
        (command "_.PLINE" first_point "A")
0 e6 [9 Z0 f) r5 _7 Y        (while (not (equal next_point first_point 0.000001))5 ^: H$ E* \! H) E' l8 O
          (initget  "Close")
# K$ _, X! {7 u6 Q          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
& e/ j" _& J, ~; R5 u        (while (and (not (listp next_point)) (/= next_point "Close"))
) e5 D+ l  K# s) {7 a          (initget  "Close"). C- Z6 R* X# D/ t1 Y) Z4 ~6 m5 A
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
" F4 Z5 q, |: I9 |# }        )
, |6 c* ?/ V7 X" y" |) v, @          (if (= "Close" next_point) (setq next_point first_point))
; Q* L- W6 Y2 d6 |" B7 h          (setq angle_l_to_f (angtos (angle last_point next_point))
  U  ]  Y% X; f  h                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
! w0 A) i/ D1 t, T3 X; f- ~          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)8 e- a8 b! b) b& b, p
             (setq repeat_count 0)" c8 ?, r  Y4 q' m
             (if (>= (- repeat_count (fix repeat_count)) 0.5)7 V! k# j$ G. {1 m" ^# G; l
               (setq repeat_count (fix repeat_count))
: z6 Y9 T0 x* u- G               (setq repeat_count (1- (fix repeat_count)))
. a& ^2 h- H. `( k             ); if 7 X2 y- t  A  |0 R1 F" j
          ); if
6 e, y- H: ]% Y" y          (repeat repeat_count (command "A" "-100" relative_point))$ ?, k! e9 B3 I4 ^; n
          (command "A" "-100" next_point)
! e  a& U7 r2 L: v5 v% ?% G          (setq last_point next_point)
  c, C7 u4 {* d( Z+ {, u0 r        )8 R! n2 F0 _# i* [; ~7 J: [
        (command "")
" b, b: D; V# `        (if (= (type number_rev) 'INT)4 x1 x- G7 x8 I% O# _
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))
9 ?5 R, U" D; ]; B2 F! ~           (progn4 Z+ Q$ O* G0 J' L
             (initget 5)4 ^- E+ z' Q! a+ b* m$ O/ M
             (setq number_rev (getint "\n请输入版本号:"))
! a% x7 n5 ?7 T$ @& d! z           )9 {; U) E8 G9 ?' C0 f
        ); if. s) g) z3 t1 v! i$ T. n
        (setvar "OSMODE" 512)
) g4 \9 a! D5 [8 H- ^& n        (while (/= (type point_tri) 'LIST)
& U$ L9 Z! G& J          (initget "Number"), V  G7 D) i; G; Z; I+ }
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
4 J7 Q( k" M) ^' ]! ]5 z# W          (if (= point_tri "Number")4 i( m& s2 E5 z4 f" p3 f( j0 i2 Y
              (progn& E- {9 O& n% K# d
                (initget 4)0 O& v6 u9 k% m- K
                (cond
# Z8 I( T  p# z& c2 c                  ( (not (setq temp number_rev
/ T2 |* d. V, c. K, ]2 a. B+ F                               number_rev
/ Q7 j9 @( A" {, S* l% \5 d                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))
: {% p7 r: u: @: T: Y# v                    (setq number_rev temp)
. F1 z" b9 \& F) ]* ^; a                  )3 x7 Q0 u/ m2 l* d6 U
                ); cond/ `+ s, I9 L8 n# l3 c
              ); progn
) Y3 d$ _( E8 q7 o4 y: `2 e          ); if7 o; ?: {1 M& `' A+ A7 s- d3 M5 ^1 ~
        ); while
3 o$ O, |; P$ X* `( N        (setvar "OSMODE" 0)
+ b# F3 o6 P. {4 |        (initget 1)
7 R( }" B) c8 r: Y' U, I4 e        (setq point_ref (getpoint point_tri "\n请选择方向:"))
, I! x6 m+ j: d+ Z        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))
1 h  b1 A2 V0 h9 C" O        (setq corner_1st (polar point_tri3 Y8 D3 s- O/ Y+ X
                                (+ 1.570796327 (* -1.570796327 dir_tri))2 W6 t0 n! K' D' F( f
                                length_tri
. @$ D; X0 D: e1 d& e                         )
5 F3 w. d5 A1 e# d" j2 b& L        )
" h+ T! ~3 f5 O: \* Q        (setq corner_2nd (polar point_tri
; g; h4 @6 X1 P                                (+ 1.570796327 (* -0.523598775 dir_tri))* G2 e  ~$ o1 v' J+ b9 G
                                length_tri4 f# P* o( b" q6 c: J  E
                         )
6 K0 a' N& r. h/ C        )& ?$ c3 j( w7 M& I3 \" ]
        (setvar "CECOLOR" "2")
3 \9 o9 q5 j: \( @        (command "_.pline" point_tri corner_1st corner_2nd "c" )
# b5 t+ y7 l8 Z5 C" U; E" x        (setq textstyle (getvar "TEXTSTYLE"))
) |; q/ D: L+ @8 [! R0 q1 g  u        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
" x' u7 m8 T6 k& _% k# s* Z        (setvar "CECOLOR" "7")
0 X& N3 w2 z) {0 Y+ g# t$ ]        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))$ o  c# r' F' I2 ]& x5 y$ s+ u
                  (* 0.4 length_tri) "0" (itoa number_rev))% Z* {& S, w- \: l& T
        (layres); U* C9 ^; g* D$ l' H; D7 r
        (err_restore)
- F  @. Z1 Z. D        (princ)
5 |1 Q6 |9 ?1 D% A+ s); defun cloud  G! z/ Y* S; T8 t

+ Y% k0 @0 s0 O(defun c:cloud () (cloud)); t# N) @" T9 q5 s
(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy
2 m% B9 B6 K' `4 X6 f2 `/ C: F;;;
# N- a1 V/ F1 {8 O) b' k# V;;;  DESCRIPTION
5 X# w% u$ L* ~# \+ _- D; w* H;;;     These are general error routines which can be called by
1 N; B( V' s  l; R  G;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference
( Z  V6 P, J4 \: N;;;
8 Z  y3 m3 j# j+ y+ P2 k! z" ?;;;  SUBROUTINE INCLUDED IN THIS FILE
( }  M# m' t9 ~; g5 T8 x;;;     UNDO_INIT1 {. H( D- K  E- q2 S4 u; Y+ T
;;;     UNDO_RESTORE
+ i" n1 y- I0 V+ E;;;     VAR_SAVE 4 w# ]% k+ ~7 }& h2 @9 @
;;;     VAR_SET  
) e  Q5 ~! y  H8 u;;;     VAR_RESTORE+ ^+ f2 ~. G1 V& a( Z
;;;     ERR_INIT
% e' n1 F. V+ y2 J' f) x! s;;;     ERR_MAIN
! J1 |7 x- P- X8 Y9 X3 l' K" j;;;     ERR_RESTORE2 h5 {1 [. U; T+ I6 ?& E$ F/ w
;;;# K. @8 e- r4 j! W7 L* t
;;;  DATE: 10/17/98; 03/31/99. y( \4 x6 n; ]. F1 W4 q# ^; O
;;;3 x4 R* E2 I3 x5 b. M6 B: k. A
;;;  HISTORY:
! h8 k3 p  N% {/ @;;;    Add routine of mod_att$ h( h9 b% u6 A+ [" R: z
;;;
+ a. H1 s% R, Z) D, ~( i! ?;;;  USING METHOD
' G) N( @9 J0 S2 }. Y- g;;;    ERR_INIT:
& Y8 y& V6 ^, ]* r+ p;;;      This routine initialzes the error handler. It should be called as:6 g$ Z  Q( o( s  C
;;;2 u4 N! N4 ~5 V6 q
;;;      (if (and (not undo_init)5 p! h0 M# N6 f: P1 }3 G; v
;;;               (equal -1 (load "undo.lsp"  -1))
& S% Y( J5 b: P5 U;;;          );and& u  N5 G, C0 q$ f( l
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
# J; J2 T4 t. ]6 S/ L. I;;;      ); if8 r/ |& l% X, @
;;;
; q) V& D" b' w/ e2 a;;;     ARGUMENTS:
3 z3 R' t! f3 D  i5 j;;;       err_init Takes 3 arguments.
$ c& e' V6 g% H5 z5 O9 J;;;     1. - The first element of the argument:
9 J/ v- g& n& f8 j. L0 x;;;          This is a list of system variables paired with* H6 c  B7 h' j( ~1 E4 o3 f) P
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
" o" q; B6 |4 h, i% _;;;     2. - The second element is a flag
# w" {/ c0 q. j2 C4 c! e$ {8 U;;;          If it is true, then in the event of an error # Q- @' a. ]& ?4 J
;;;          the custom *error* routine will utilize UNDO 6 z7 ]1 D7 o" E+ t% b& L9 O
;;;          as a cleanup mechanism.
9 a+ x: ?0 l' g8 s;;;     3. - The third element is a quoted function call.
+ V0 {6 }- C7 {# U, T2 z;;;          You pass a quoted call to the function you, ]* E3 S; J. l9 k  w, f( m9 E
;;;          wish to execute at the end of nomal routine if an error occurs. . o" d' T4 R) M) Z- s% v# x
;;;          i.e. '(my_special_stuff arg1 arg2...)
% A6 N1 V: {+ O0 I7 Q; n/ c;;;          Use this arg if you want to do some specialized clean up
( D! ?! A8 z2 Z+ o/ L* {+ r;;;          things that are not already done by the standard bonus_error
6 t# T5 t9 n, W1 ?$ {6 E! f* {;;;          function.
% w4 s5 G, @% u5 b8 w;;;7 [4 @7 n0 v, b5 r
;;;    ERR_MAIN: Body of error routine
: C3 \, ?+ c5 D6 y9 V;;;( D# b/ z" w" ^% n- Y: H/ u
;;;    ERR_RESTORE: This routine should be called at the end of command to
  ]& O. E, ^) z, @;;;           restore the VARIABLES, UNDO & *error*.9 i: Y) n3 r7 K. z* i& V
;;;
0 q- @0 k6 @7 i3 z5 s+ {;;;    UNDO_INIT: Initialize the UNDO status
  x1 z# b6 r$ ~  C/ O;;;
% B* @" r& N9 w4 H6 T;;;    UNDO_RESTORE: Restore the UNDO status
9 _* G' O/ E) o) j8 @9 z" Z$ B8 r;;;
* G. U! G2 y( I. Q3 {;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
" w; m$ Z7 n! b' U" w2 ^; L;;;
# L0 _8 |& d+ y% r) G) ?! a; U7 s;;;    UNDO_set: Set the variables. the argument is like
/ ?5 C1 ~& G0 f0 k2 s;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))6 L1 s/ @- [2 _* ]* Z
;;;
: g0 v3 M8 ~- v5 D) i! E;;;    UNDO_RESTORE: Restore the variables3 ~5 B7 Z3 Z' [& G4 i1 s
;;;
  D, v% u! J2 V. h. y;----------------------------------------------------------------------------
5 P) S* l7 c/ z$ V: U;  GLOBALS:; N) d( `: U: j( d
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)# B& R7 T; P/ T- o
;     m_lst       -- list of variables (voided by VAR_RESTORE)
) G( ]( Z2 g. }3 G& R9 e;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or
8 V/ n/ R; C3 V: w! ]8 z;                    ERR_OLD)  F' X. y6 I1 E' d
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)  J# [( M5 b# T/ s* y; O
;----------------------------------------------------------------------------
/ C1 p, G) B/ x5 |2 c+ L% I
1 f& q3 ^/ i4 q, g' Z* w  A;----------------------------------------------------------------------------
( H: e/ W" m) L1 Z/ u6 w4 U# X9 F3 }; Modify attributes according to entity name, attribute name, dxf_item
* P' ~( h5 r, b* C1 k5 N3 n# ~;----------------------------------------------------------------------------2 s8 Y. r0 K% z( s8 _! L# @: [
(defun mod_att(ent id dxf_item)        
, Z: P/ N9 U' |9 r% l" O8 K  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
$ W& W6 q0 h8 e; N" E% M    (setq ent (entnext ent))
1 a- g& Q# @/ c  ); while  
- a& W0 I/ d# t3 b. F  ((lambda (x)
$ G$ M% A9 H8 [1 M+ u        (mapcar '(lambda (y)/ _  H. c" n9 |' a
                   (setq x (subst y (assoc (car y) x) x))7 M. @7 v- q) D" B- }. w- D
                 ); lambda2 }! J1 T- ^- u& X6 O' @( ]
                 dxf_item
0 K% X. m% E& T7 l3 {        ); mapcar5 b" Z: i+ m  ]
     (entmod x)- P+ f: T; ?0 m8 U: g
     (entupd ent)% r# x! g, z! z" V9 j
   ); lambda! V( ^/ Q* R1 s6 j& `
   (entget ent)$ N! e  E/ S( _+ R9 {  D
)6 I3 O7 m+ X/ B
); defun mod_att
  V9 l4 E4 W+ l! q/ {# m# ]4 S  {) k3 D# \; V5 \6 a/ B9 ^
;----------------------------------------------------------------------------5 d& y+ O) P$ o9 U; Q3 E2 B
; Check layer status, return a association list which contains layer information8 _$ k- w) i: c  z# g) \5 x
;----------------------------------------------------------------------------# V4 y6 n6 O+ x
(defun laychk(lay / l_sta): d! S5 H( `! C9 {2 m( U! F% W
  ( (lambda (x)
% _  Z) E1 d" N7 V6 U3 V( |! T      (if (not l_s)
& n5 @# S2 v7 u/ j          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))3 z# t& `4 R: s
      ); if
% k, O* ]& P9 O$ f1 o    ); lambda , Y( E* `: Z: z9 N$ L* I8 s4 h
    (getvar "CLAYER")
0 E* U6 V* ^  l* a  )
# {$ Z, t8 {' w0 \- E' h  (if (not (tblsearch "LAYER" lay))
3 m  `% p' S4 Z* R% B3 _- A    (progn  
3 ~% M$ \" a4 w9 ^- ?+ i      (initget "Yes No")5 v, }7 T3 F" N( p
      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
2 h- X0 z' C7 A" I3 k% ?! w        (progn
4 B/ Q% l7 y0 A7 o) n7 V1 P$ i- c          (command "_.layer" "n" lay "")
% z, F2 _( h/ o, d  s, z3 v          (setq l_sta 0)
( k. m1 c2 V  d) H! U7 Z: l        ); progn  p! v$ C1 y! A) d6 D
      ); if. M& {- b) t! i1 t  i% U
    ); progn  i* w$ Q% U" ^+ G+ k7 U
    (progn$ w0 _4 F) n  Z6 d
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
9 }/ h! f  }& V# i7 s# a      (if (= 1 (logand 1 l_sta))
3 D1 |; L: {& y+ L6 T          (progn* \2 ]9 @( J1 a0 ~9 j7 j' H) u
            (initget "Yes No")
( I2 A5 i- t, I6 z4 b; ~& ]            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")
: Q) t. a6 N" K3 Y3 v              (command "_.layer" "t" lay "")4 T' e7 D* ~2 O
              (setq l_sta "No")
9 j/ _* y# t+ v- D' n0 x             ); if9 X$ n  D$ X- ^
          ); progn, g+ a  n9 M- B2 Y
      ); if
. j- @: }# W& ?& l      (if (numberp l_sta) ; l" L2 O- }, b- c: _7 n
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if$ d' k6 ^/ R7 T4 T! E4 v: H& I
      ); if9 e8 ^) E( A7 H8 U! e- W& C
    ); progn* {# e2 F; Q. L- H
  ); if" A  W7 l. r- w! V
  ( (lambda (x)9 N  G" t  G+ }1 O
      (cond
+ e3 u* {! k/ Z0 w, W; P        ( (not x)
/ T1 f! i; F' P( i1 g6 {7 ~' e          (setq l_s (cons (cons lay l_sta) l_s))
2 U$ A" }' g5 [3 W1 j, z        ); y6 ^9 b' H) L4 t( F7 b4 z
        ( (= "No" (cdr x)): n, }* ?7 p% \, ?- h; Y
          (setq l_s (subst (cons lay l_sta) x l_s))* o, D* o2 P/ w; |4 Q; v/ H$ ^8 N
        )
/ E- x2 U/ M; Y5 q( b        ( T l_s)" E4 M% I$ v/ G$ p
      ); cond) y! ^8 D  N6 o: d* [
     ); lambda  x0 u- L; k9 S: W! O9 p6 _% V
     (assoc lay l_s)( }# v; F5 v' H  Y# e
  )
/ h0 {2 {: j; Y, W( L1 C, c5 c6 _! }% g. Z3 l) [
); defun chklay
3 x/ o/ H, r! I0 V6 D6 Z' I5 ~+ v  {8 a$ j3 `! z$ P
;----------------------------------------------------------------------------
# a: i- A. x# @; L9 m$ g) Y" P; Restore layer status according to association list l_s
( X. m7 B  l9 q* I;----------------------------------------------------------------------------8 F+ f: f+ G; f( a8 m$ z7 c! X
(defun layres()
" U( K% g  U* |' I5 T8 E6 C  (setvar "CLAYER" (car (last l_s)))  H3 n! q! p! z9 k* ?
  (repeat (length l_s)2 m' p) k* N( h
    ( (lambda(x)    K$ a" n8 ]( p& I2 O7 ~3 J/ v
        (if (numberp (cdr x))& N. W( i# m( U& z
          (progn 7 Z5 P9 Y& v6 Z
            (if (= 4 (logand 4 (cdr x)))
- Y1 j7 _" g* d8 ]: ^/ K5 j6 n              (command "_.layer" "lo" (car x) "")! n1 b( S4 h9 F" h7 g
            ); if
2 T2 N3 h% A7 Q; L5 J! Y' P) F1 E5 F  B            (if (= 1 (logand 1 (cdr x)))
" ~/ I& K# C, a( i; X0 j              (command "_.layer" "f" (car x) "")2 V. K, T- l' V4 I& y& ~! K$ y
            ); if
) n+ `& ]8 {- ]9 k8 o8 L" z          ); progn
1 q/ i5 L4 H* }+ M! P, a+ z" |       ); if  8 d6 K) ~5 ~# d" v
      ); lambda" ?0 h/ P$ ~+ {% s6 m
      (car l_s)
( r! J' P% H' w% x3 X; w4 U: D( P' Y$ J    )/ w- C/ S, P+ b& d1 B
    (setq l_s (cdr l_s))+ }" U8 O) y6 u* I0 C; F* y9 p( h5 c
  ); repeat1 K5 e  N9 W1 p9 T) P2 F
); layres
. _% K$ w; G7 B, C( \* G  Y: e2 Z7 A+ F
;----------------------------------------------------------------------------! M/ O) m7 W3 {6 d& G2 p2 x4 M
; Get DXF codes
; G  K4 Y1 \$ j;----------------------------------------------------------------------------* g6 u6 B& H3 w3 |1 N
(defun entgetf (index ent)  g7 P. }3 U; Y2 l. W2 ]3 Y( `
  ((lambda (e)/ F5 R& h7 C9 T8 h
      (mapcar '(lambda (x)7 }. m' `9 u% K" Z
                 (cdr (assoc x e))
1 E# W4 b4 @. Q+ b* z; Z8 I  n0 d               ); lambda
! [; }: l# v: C/ d3 f               index) ; internal lambda function
* T3 `1 N/ F: A0 _$ j* |    ); lambda
0 s0 H( T, f; E    (entget ent) . i- n% S3 X0 r3 {( B
  )
( X9 U* a( b; @. Z; c); defun entgetf% {# m. s/ V* Q0 b+ a

) N0 A5 [- H7 m;----------------------------------------------------------------------------2 ~9 b( K/ L7 |
; Save UNDO status1 I% p' e) G. I2 a1 e. \9 s
;----------------------------------------------------------------------------
% T8 @3 ?; D1 u. l(defun undo_init (/ cmdecho undo_ctl)   
' g9 d! i0 E: v7 D8 a5 a# A  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value! S$ I- F3 y6 S, m
  (setvar "CMDECHO" 0). c; ~& p% Y$ Q* Y* y! b) D

7 x; B6 K. K( z2 Y& `  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable- o" S6 g& v2 K1 n1 n9 t
    (command "_.undo" "_all")- t' a% S/ _6 U0 `; M  k8 ^
    (command "_.undo" "_control" "_all")
  ]) o6 K* o9 a$ w# y! R) j. d  )
; w+ ?! A5 m  {- d( y) N6 {! o$ s& U$ U& f& {7 r! [+ D
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off9 N% X: N$ a. _( C/ x% p$ j
    (command "_.undo" "_auto" "_off")
$ r2 {; D- d! F# ?  )
6 @* w* J+ X/ Z8 Y4 S1 q: U+ g
7 l. P( F( C8 X- \) R  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
- _, E9 z* A* g. L" l    (command "_.undo" "_end")
. b# y  T) y$ X4 a! B  )# l+ L3 n- Z% c9 _$ \3 r# z, T  r
$ W7 o" a0 W7 c% S: A
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
7 Z/ C! H- S+ f, @& Z6 h    (command "_.undo" "_group")
. u6 W; k5 {7 A7 u  )
; o. z( P9 z4 O0 \: x. y5 W* c- o: U. o0 a- I
  (setvar "CMDECHO" cmdecho)
" r1 W. O& D* L. T# Q: F  undo_ctl+ p4 ?% X6 g1 b% m- V" `% z
); defun undo_init
$ o7 v2 g3 r& {( j( q6 s: d1 a4 O8 l* ~8 r. O+ i
;----------------------------------------------------------------------------& V) ?3 M$ z& E' S( {
; Restore UNDO status
" ~  k9 b. u! y! y;----------------------------------------------------------------------------, t* A4 s9 P; v% d2 |8 W
(defun undo_restore (/ cmdecho)
; E- q2 U+ C+ d! q  (if old_undoctl
( C; q( x# ]8 M( a    (progn
+ B% c8 u1 G3 L% R- w. g) D      (setq cmdecho (getvar "CMDECHO"))) V8 A0 a$ z: a2 d  J+ Y& r
      (setvar "CMDECHO" 0)
; I/ ^6 n+ |" Z8 x5 w' m7 W* T
! ?& P$ p* j4 _& Z      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
3 g  J: n2 k$ M      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
# o. o) o% a: d4 \/ S1 |! _        (command "_.undo" "_end")
, U# l8 z  j5 n$ s; c" Z      ); while$ o- b8 E7 R5 v& F

# L% O' H' j- O4 P4 x/ Q- J
0 z% ?& B, s% ?; u/ u5 _      (if (not (equal old_undoctl (getvar "UNDOCTL")))
. \  o" V( U" N6 T. r        (progn1 a& n6 l5 a* m1 P
          (cond. z' C4 Y0 o! n5 x% U
            ((equal 0 old_undoctl)) l* u- L% h( q+ @
              (command "_.undo" "_control" "_none")7 o+ t* G& x$ S9 U0 W
            )5 D& j. R/ x4 q' A$ X$ s6 H/ W! I
            ((equal 2 (logand 2 old_undoctl))- l0 D. T7 ?" x( z
              (command "_.undo" "_control" "_one")
. Q$ W* k2 d% i1 b5 _& d            )
1 b3 N+ U/ t+ Z: V) l5 z- v          )$ p" `) Y8 b) F. u: c
          (if (equal 4 (logand 4 old_undoctl))- @$ q5 n- M( ^! o: [& @; Z
              (command "_.undo" "_auto" "_on")6 S1 v- p, c4 E% `1 h
              (command "_.undo" "_auto" "_off")1 P) {% J& F/ i0 h# G( J
          )0 F' ]! T) T! J. v6 `3 b9 p0 m
        )
6 W) g" C# `1 X3 Y      )
0 O0 N# n$ @7 U) z- |: K      (setq old_undoctl nil)+ P! ]" i( H% Q/ L4 d& G
      (setvar "CMDECHO" cmdecho)9 N4 O  ~8 T( G/ P4 b8 P
    )
6 _4 Q( H  r" F! w$ p% T8 v$ i  )7 y. h* F. N$ T4 e# r" A
); defun undo_restore
3 [7 M, X: p: L  S* s- r1 B, ~6 h- H% a) w- W1 L; K) z
;----------------------------------------------------------------------------. K$ U7 N% v3 z1 L4 \
; Save variables* N) Q! ]$ k9 P! b2 }. l
;----------------------------------------------------------------------------! z& F/ e4 m# q3 M; K2 p9 \  F
(defun var_save (a): q. @9 s5 {. ?/ b8 k( q
  (setq m_lst '())6 h% _$ g% M- D# x) p
  (repeat (length a)
8 s# D- M8 i; e1 ~3 J! k0 m+ l7 m    (setq m_lst (append m_lst (list (list (car a) (getvar (car a)))))); G# h$ s$ I( C  J! C* t8 N! r
    (setq a (cdr a))5 ^! s0 X$ Z8 M: V
  )
/ @1 j) b! s2 l. L9 u); defun var_save
+ w# R! `5 g% l1 E+ B& }2 `$ _6 Q9 T* C. J9 W4 J" G0 G
;----------------------------------------------------------------------------
8 D# S( ^8 L4 a! Z% b; Set variables9 g8 f$ Q. H, i" F3 [5 B, P+ P# t
;----------------------------------------------------------------------------$ L# e" `# z# L+ T" u
(defun var_set (m_lst)
0 t5 a8 V( {, {  {, G  (repeat (length m_lst)
/ t% s/ c0 |, _$ G( G- w2 K    (setvar (caar m_lst) (cadar m_lst))$ V( ^5 B$ o5 z; v6 @- E8 E
    (setq m_lst (cdr m_lst))4 D, Y6 K) N* `2 @& w! W
  )
% y% S! b. w: `% r2 N! z); defun var_set
1 A' L! H/ A' o% j) }! S
, y# a: _4 m2 Z- R2 U; I; [0 F;----------------------------------------------------------------------------
; U5 F) O, B1 J7 b* S/ G; Restore variables1 o2 g: M0 A9 x" E0 z
;----------------------------------------------------------------------------6 u' {7 i( ~0 J$ `) S
(defun var_restore ()
) B8 L8 L$ v8 a* r$ A  (repeat (length m_lst)
- X8 c. [% z* G8 W4 `' Y- O# d! L$ L    (setvar (caar m_lst) (cadar m_lst))
% t' B+ E$ x+ e' s5 f) Q    (setq m_lst (cdr m_lst))
$ M* a; ^% b  V/ r  )
( V# [- u, a4 E); defun var_restore
8 a3 }" t7 k7 s" ?1 V, g6 M9 h/ W& F. b1 G7 Z6 W2 I
;----------------------------------------------------------------------------
6 z( W! V# {5 f% v/ S# w; Initialize routine : {- h+ n6 o3 ~5 \
;----------------------------------------------------------------------------
; q) L  H8 p7 v& t" y2 |$ O! B! |(defun err_init(e_lst u_enable add_fun)  x  k( U' Q6 E8 J" y
  (if err_alive (err_restore))          ; To avoid nested call
% U: _/ b$ S  g1 g/ p+ z( V  (setq err_alive T)
, p8 G- y  M; l7 h  (var_save e_lst)                      ; Save the modes
" E2 i% h0 s1 }0 S) J- m  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status1 b: N& }: Y8 r" Z+ R. M3 V
  (setq err_old *error* *error* err_main) ; Save the handle of *error*
' V* `6 ~$ R, x: m# v  (if add_fun                           ; Add the user cleaner1 k4 G* h. T) r+ n; `  ?; M8 [
    (setq *error* (append (reverse (cdr (reverse *error*)))$ K3 `* [: d1 @) c, g4 M% S
                          (list add_fun (last *error*))
' W; I. ]1 _) w% j, s- W                  ); append
- I5 q' h  C2 a3 \    )
, ]; U$ [4 Q% @) i# r  )
9 u( q2 D+ e" c+ z* V6 s; U* J6 l9 l); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------5 [, e7 J% h2 {0 f9 p; P4 }9 U9 d
; Error routine body+ g( U% S& V& C: O9 W
;----------------------------------------------------------------------------
5 x! j4 j2 O$ [9 g(defun err_main( msg / )                ; Body of error routine$ f) S' \9 @7 b1 X
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs; S" L7 G' E, B8 M( H3 s6 [
    (princ (strcat "\nError: " s))      ;while this command is active...  a5 Q3 n$ K# e8 ~
  )
. M; ~" d! k- J6 I1 A3 V1 T7 B7 c  D: Z  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command3 b; H7 u2 X' y9 {7 a- R

5 s8 l, T* b3 f) Z  (if old_undoctl; B" V$ a4 Y$ {8 Q# s
    (progn  b* E) X# r# C' s
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See
7 ~0 }/ N! e3 a7 Y' Q) ^  v+ q        (command "_.undo")              ; if it's in UNOD command
7 e& e, a/ e; o8 [0 C9 V1 R+ P8 ]      )
% T# w  Q1 E1 Y) Y; F      (command "_end")
( h+ T3 @8 V9 z. G+ m) l2 q- g& K- \" ]      (command "_.undo" "1")
/ T! G% B# r7 ?7 J3 y7 s9 l$ q/ H% c8 q( t      (while (not (equal (getvar "CMDNAMES") "")) (command nil))' U+ ]/ [; f4 p1 ?' f1 P
      (undo_restore)                    ; Restore the status of UNDO5 o% b- l8 E, B2 s# V. G$ \3 O5 [
    )
  M+ I' _3 T+ @/ E4 B3 w; B. N  )
% L0 Y6 S8 l) a7 d" o) Z" x8 ]1 Y& x3 i1 c
  (var_restore)                         ; Restore the variables
  x. m0 L  v0 Z. n# ]) t  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
1 J3 A# q  b, Y5 S, M. c  (setq err_alive nil)5 r8 F: y4 ~. Q$ U9 o; |5 y2 i' {
  (princ)9 h6 K6 ~1 V, f; {7 b
); defun err_main3 T( {4 g" p$ J& z+ g% O

, N4 P/ h8 L  V/ g) {, e;----------------------------------------------------------------------------
8 O" }' l) z' W1 Q7 l& ?; Restore error status
9 _+ n' r) o+ F5 [4 Q- D. M% P;----------------------------------------------------------------------------
: D1 U( I' ~! O& c& h0 w(defun err_restore()
: x+ b& T! b. Q! `; d/ Q  (undo_restore)                        ; Restore the status of UNDO
! {3 Q4 Q$ a+ Q( R& V; N8 u  (var_restore)                         ; Restore the variables
" T2 q1 z$ |+ k0 L# n5 [" k  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
9 M; `, M% N! \' f# z) V  (setq err_alive nil)
0 l& L) v8 @7 E2 D$ U  (princ)
8 `# Q+ t" m% B* n2 _0 g); 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-5-3 12:33

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

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

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