CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:, Y/ `$ i) Q1 L- {7 M
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”$ Y9 V: J, ~# ~: D( \
提示:加载成功. \' U. b+ T  L2 i" W, }2 h
然后使用CLOUD命令,2 J3 ^3 s, W8 L% R$ h+ ^7 K/ w, z% K
提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”# i9 H9 w% S% `: z' l0 v& ?
请高手指点一下,这个是怎么回事?应该怎么改正?! Q+ h) X# J$ J
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx1 z2 g4 Q5 ?' ^* b3 o/ {
;;;. u8 j# a5 ]% Y7 j: u! ]+ [& G2 i
;;;  DESCRIPTION
, L9 F6 U- G2 b* L! |( R; P;;;     Draw cloud and you can specify the globals variables listed below9 P: l8 \. C8 R5 u5 U. q! \
;;;     to decide the characters of cloud# ~, x1 [7 o/ z  A/ f( c9 ~' F) ~
;;;$ X4 O, ]- E6 h; w, Y) j" r
;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/985 @" t7 z% g6 ^& T
;;;1 I( T5 d. d/ b/ U  n
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed8 Q4 t* o7 g/ a5 g6 G- a
;;;           Change CLOUD.001 to use CLAYER to perform the same function
4 S1 T# U' u5 c) n$ \- l;;;           Use the common error routine UNDO.LSP to optimize this program9 j; U$ F6 O9 \3 O: t
;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE& c. ]/ Q; x4 T1 u7 @
;----------------------------------------------------------------------------
! }/ K3 J7 q! N. a;  GLOBALS:# j% k/ h7 Z5 s. j0 m7 l
;     cloud_layer -- layer of cloud. F# h$ t* O1 j' C; k2 n9 \
;     cloud_scale -- scale of cloud% Q3 I. q2 x3 }- p' E* T/ M
;     number_rev  -- revision number
3 w; }6 ]0 I! O4 q" `2 U;----------------------------------------------------------------------------1 _4 U. L. N" `2 R& @* M* \' J
(defun cloud (/ locked temp first_point next_point relative_point
4 o3 H" e+ U$ T$ b5 }               last_point point_tri point_ref corner_1st corner_2nd length_tri# H& `0 n; [  F# i  E
               length_cloud angle_l_to_f dir_tri repeat_count
5 I" Q3 t3 D7 Y" }. [) \/ a               table_cloud )
  @0 p! u% e. C' I( k# Q) ?        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))# r9 L# ?/ v/ |1 D9 t3 V
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))7 b. ]2 K$ n/ K6 {5 y, f, T" j! i
        );if, C+ O" p- y( l
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE", P% E2 L: l/ N- \5 ?) \. ^+ l
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
: G3 f; F( I$ m        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
( C9 J" V3 y' _" [2 M6 m9 |                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
. N9 R! v- L3 `3 s2 |; I) U9 j+ |9 H5 B, ?- t% n5 L
        (if (not (numberp cloud_scale))
! h, a8 x; u; R, b9 R            (setq cloud_scale (getvar "LTSCALE"))" \$ \6 {! u5 Y; A: i$ X( M/ H
        ); if
/ `& c! S5 h( r3 W) A& M1 f        (if (not cloud_layer); l: ]0 K; O* o! C& L- B+ A
            (setq cloud_layer (getvar "CLAYER"))
8 v$ ]" l4 ~$ t        ); if( x( ^6 p7 b3 p. m7 a! y& a
        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
0 p2 H+ M: X8 n1 o5 `% H7 l8 q        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))" [& P0 U1 Y+ t8 @3 U7 }
        (if (= (cdar (laychk cloud_layer)) "No")1 g! l& o( v2 o
          (progn
' y4 H" c6 G! h9 y' S' |; n            (laychk (setq cloud_layer (getvar "CLAYER")))5 K- P. _# R& ~, N
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))$ B& D) E+ J* }
          ); progn  I" x2 V  I3 L3 H: l
        ); if
+ v( B* i& A4 B% q$ W9 W3 {% h( ~0 t% y! K* Z' g, o6 R
        (while (/= (type first_point) 'LIST)! V1 _- [9 u% n/ K! Y4 o" Q
          (initget 1 "Layer Scale")
. F7 Q7 f+ \7 V$ u% M9 C, G$ s          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
- }1 B6 J( V0 Y- z0 _0 _1 u  r          (if (= "Scale" first_point)      
( i: c9 R. Z, n2 w' y6 J            (progn
9 U: F5 M( K) V              (setq temp cloud_scale)
) h0 A  C0 \  L( N              (initget 6)
2 p$ w, Y0 w& {  ~: W, v* l0 G              (cond' z! ^" z- y. `$ V/ L$ X
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
" t" y5 e; N1 x) L& i                                                          (rtos cloud_scale 2 2)
/ J2 R9 d$ [, \2 l4 [$ A                                                          "> "))))- d& v" @! e1 d4 P* g
                  (setq cloud_scale temp) )3 o: l* c2 ?) _, P2 P% i
              ); cond2 w" X4 G& o2 ^. R- s
            ); progn; }5 |9 U& o' t) d
          ); if
+ |  R% J3 ?& b4 L& y6 s          (if (= "Layer" first_point)- G5 x7 C- _8 c) {0 f
            (progn
/ M- J4 ]5 Z8 K0 @              (setq temp cloud_layer)( ]  a/ ~2 x" \- O
              (cond
; O. k. N* b% `& B                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"7 ?- b$ N9 J+ g7 z+ e2 x5 C
                                                          cloud_layer "> ")))
# M4 M! y' y/ i  J1 M" ?                     "")
( l0 k9 M! F# V                  (setq cloud_layer temp)
. v  j( f' k& `; x                )
. ?5 C9 Q1 J8 N& v              ); cond
) \- [8 |+ u/ F' c$ k              (if (= (cdar (laychk cloud_layer )) "No")4 `1 ~% L2 X% h) R! H
                (progn* X1 ]' j* d3 ?7 A4 m
                  (setq cloud_layer temp)
3 {. d# y# U$ T3 _                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))2 Z' |& Y3 S0 I1 N' ^" {
                ); progn
  i  a. C8 Y6 g              ); if
8 L8 K# H; H# W+ {  r9 ^            ); progn
1 Z1 M2 r9 x4 M8 d# L# y2 ^          ); if3 }; n5 I; G1 ]8 C
        ); while
" E9 F( U1 B# u( Y7 V        (setvar "CLAYER" cloud_layer)7 F+ z5 ?. m2 D# W: }: ~4 H7 g( O

8 |- M4 h$ {# C1 j        (if (>= ( getvar "LUNITS") 3)" T/ Y  Z1 F& t# O2 G
          (setq length_cloud (* 0.25 cloud_scale)
1 }( m4 N7 D# `4 s  B, Q* x7 A/ e                length_tri (* 0.3125 (getvar "LTSCALE")))4 B2 U7 z; i- K. R* f3 J: @7 V
          (setq length_cloud (* 0.3406890 cloud_scale)' y8 C, Q. g1 q  j
                length_tri (* 0.438366 (getvar "LTSCALE")))2 i: G& j0 u7 N- S2 s
        )
6 z" Q/ `, f7 D$ {        (command "_.PLINE" first_point "A")
. f! b# S2 D. @9 r- t% g        (while (not (equal next_point first_point 0.000001))
; z$ a8 I( N# |. P* N          (initget  "Close")
: @+ H; j$ O) m) ?. k$ E          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
# [- k* I" d  f' t        (while (and (not (listp next_point)) (/= next_point "Close"))  c4 H* K) s+ D8 b5 G
          (initget  "Close")
( @3 G; u2 Z) A          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
* t$ J! W' q& P3 s        )
! b) L3 S/ b9 i" d. S          (if (= "Close" next_point) (setq next_point first_point))  I  E: l' A" s& H: [3 _% x3 P
          (setq angle_l_to_f (angtos (angle last_point next_point))
' e. H$ Y8 y. Y& t* k                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
1 i( z6 ?- @* n$ t' H& y          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
  v: S7 s+ N' H$ C3 i' x" ?! l+ h             (setq repeat_count 0)
+ D6 A* E) P2 `7 f* e8 o             (if (>= (- repeat_count (fix repeat_count)) 0.5)9 L" x0 F0 ~8 X5 w
               (setq repeat_count (fix repeat_count))- b/ h" X8 S+ d* K2 a1 v
               (setq repeat_count (1- (fix repeat_count)))& _5 c, r+ f3 v
             ); if $ ?. q! k% L* }! k- e+ n7 A  B- b
          ); if
3 u0 u  U2 @/ \) Z( K  e) {          (repeat repeat_count (command "A" "-100" relative_point))
: B- D6 a( m9 ~6 w2 ]$ u4 w          (command "A" "-100" next_point)
% V, V. q( I1 S' X5 N          (setq last_point next_point)
) S: B! v6 w- f* Z2 J! t        )
1 p0 @% r8 H1 y; t        (command "")
' r7 b. Z" m! e+ M  d) ~3 l        (if (= (type number_rev) 'INT)* K& G0 {6 N! i
           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))- L% e& ]) @/ e7 e
           (progn9 |0 R0 B8 K- f
             (initget 5)& L2 |# l! x; b+ q5 i) N+ x
             (setq number_rev (getint "\n请输入版本号:"))
0 h7 \- ]9 D+ \2 u4 t* I* M6 X           )
7 _, m+ f. `& x, i( w# o* `        ); if
  ^, w. ~+ }: O, s/ h% ^" F        (setvar "OSMODE" 512)- _, _0 X. j4 k* ?0 u0 x2 W7 {* r( E
        (while (/= (type point_tri) 'LIST)1 C: c7 n! j) z% r( K/ ^& n
          (initget "Number")9 j7 W2 s5 h! k& ]9 b+ J/ O6 ?
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))* i) D6 `8 z. \- P# S' p
          (if (= point_tri "Number")$ N/ q% f  c9 [# l3 O
              (progn' o: U2 g$ r' R/ z& G- Z
                (initget 4)
  P; V9 h% x* }                (cond
% p+ {2 R% X* S9 L                  ( (not (setq temp number_rev , T& a" q: F& k9 r$ Z) }% e6 E
                               number_rev
  t$ X" D# G, |2 `; u  F+ {                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))# l5 C* f3 }  t4 A0 [
                    (setq number_rev temp)
) x; ?; `# p: m2 ?; @$ S                  )3 r8 x2 V* ?  k$ }7 k% X* ?
                ); cond
7 u3 [  u$ ?% y" y8 n( A              ); progn7 f, o) @/ f& H) v8 I
          ); if; w# c: c& {# {8 z" ^8 ^
        ); while5 E: e5 {3 ^" p2 x" B" K/ n! z
        (setvar "OSMODE" 0)/ m. n& T& z& G, U
        (initget 1)( J7 L' D1 Y* h# o
        (setq point_ref (getpoint point_tri "\n请选择方向:"))* e8 t1 X9 G; r
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))* ?+ [& @9 n9 E3 O% ~1 y
        (setq corner_1st (polar point_tri" {" P8 }# o8 h. z. }" X
                                (+ 1.570796327 (* -1.570796327 dir_tri)): R  H7 l5 A( \
                                length_tri
4 F. E' i" [0 C8 |                         )
8 B; t, C5 f5 Y* V& U        )4 u( Y- ^% T. q% M5 B
        (setq corner_2nd (polar point_tri6 S0 `. W- E# \
                                (+ 1.570796327 (* -0.523598775 dir_tri))
7 ]. k8 ^6 \- [7 P. _/ e' G$ q                                length_tri
; H! [/ H2 t" }* q0 S                         )) g7 v5 v+ k% b- O8 v" @
        )
7 I* i% X* p+ P* t/ L% e        (setvar "CECOLOR" "2")* s* b/ t$ t" L) a5 D! Z
        (command "_.pline" point_tri corner_1st corner_2nd "c" )
3 y5 ?* ]7 O. J: M        (setq textstyle (getvar "TEXTSTYLE"))
  N4 R3 X1 b. z1 `: F        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")6 y- Q8 S6 U7 g1 A9 Y' L& a7 W7 @
        (setvar "CECOLOR" "7")
" S* p; y  j/ v0 r        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
; u9 E$ N; x3 \" h$ o/ K" T                  (* 0.4 length_tri) "0" (itoa number_rev))8 N& \* [9 L, V6 G
        (layres)
' o" n/ K6 j% F; r        (err_restore)
* q! G* |5 y/ @        (princ)7 H( j# x  O  L( z
); defun cloud
; ?1 k; m4 e. W" e; z( N/ X
: l; I% `2 ^( a0 I(defun c:cloud () (cloud))
  ^7 U) S  I6 k(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy% O$ f, X- r6 e' i# K: h6 v0 ]
;;;
& d0 D2 j% a8 ~& K: S  Z;;;  DESCRIPTION
  O& D- f; H* f7 y0 ^9 [/ c0 ~: H;;;     These are general error routines which can be called by
0 t$ P- Y5 L% f" k4 ^;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference7 \- s5 A* G3 Q# l. a
;;;
: F- x# |! {9 A! t% q7 `* s- m9 O( r;;;  SUBROUTINE INCLUDED IN THIS FILE/ H  C1 O$ u: n# Z$ I$ c
;;;     UNDO_INIT
' C1 N& a2 c% F7 W; T;;;     UNDO_RESTORE
6 W: M9 O, b: e. e  M; Q% x;;;     VAR_SAVE
4 y' V% d2 k6 h( ?$ m. e;;;     VAR_SET  
2 |' |# R7 a4 j! ~# a- s;;;     VAR_RESTORE
, y0 G5 p$ H+ G- H4 w+ s: ?4 f" S  _;;;     ERR_INIT
7 q5 D/ w; I, \1 [# i;;;     ERR_MAIN
8 v5 h3 }' u) j5 c;;;     ERR_RESTORE! H) g/ K, a2 q' a4 e
;;;3 [4 ]- p# m  C) y/ }2 i
;;;  DATE: 10/17/98; 03/31/994 ~2 s% ~2 l$ @- r+ d
;;;
8 h" u) e! @  }0 |;;;  HISTORY: 5 j  A1 O. i) }# T2 s
;;;    Add routine of mod_att
  Q4 Z5 e4 K" L* N, ~;;;
4 G) H! x0 {& N8 ~! j! s2 O;;;  USING METHOD
/ p6 R9 E. F3 c0 A/ A;;;    ERR_INIT:/ \/ M: _2 M+ T9 w7 T5 j# W8 Z
;;;      This routine initialzes the error handler. It should be called as:2 ?& j- q% b. W& `2 l1 b# g
;;;4 I7 ]  G/ c7 G
;;;      (if (and (not undo_init)
8 t# L, i: m$ A+ S: n( f( u) X;;;               (equal -1 (load "undo.lsp"  -1)) # U; p( y4 J! U7 C1 R: e6 k2 K) H: |
;;;          );and
/ {/ q1 v" A! f& ^/ `;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))  \8 i; f9 B) U& R0 A" Z( \6 l5 ]
;;;      ); if4 k  I* A* J) N- @* O
;;;; Y( e3 _2 t1 C! ^- J
;;;     ARGUMENTS:$ t* A4 g% `5 G3 H2 x9 A
;;;       err_init Takes 3 arguments.
$ Q+ ?- y' Q8 \; D2 |;;;     1. - The first element of the argument:
* ^" T, j8 A2 D9 D! v0 [;;;          This is a list of system variables paired with9 q5 z; }2 @& @8 \, ]% z1 k& h
;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
0 c0 o% b3 X. h1 c6 [, o;;;     2. - The second element is a flag
4 ?" r9 C) y) J& k8 t;;;          If it is true, then in the event of an error 2 P' U3 \8 j' R. O8 a
;;;          the custom *error* routine will utilize UNDO
) z- I. n9 M% |+ A;;;          as a cleanup mechanism.
( K! }. y* F& V4 P' h8 ]$ T;;;     3. - The third element is a quoted function call.  G! e% x% l6 i5 c$ Q9 g% [
;;;          You pass a quoted call to the function you6 t3 U+ W( t& l5 S
;;;          wish to execute at the end of nomal routine if an error occurs.
1 Q; W7 k$ \! S;;;          i.e. '(my_special_stuff arg1 arg2...)8 j, w, s, V( h9 p4 r
;;;          Use this arg if you want to do some specialized clean up
+ V" H$ G  U$ o: E# t( t% c2 s1 g;;;          things that are not already done by the standard bonus_error * d! J' S$ U" @
;;;          function.) v! k7 h( N4 p2 A4 N
;;;
9 Z3 s; c" f9 u0 M/ F) g;;;    ERR_MAIN: Body of error routine! G5 V/ n$ P! t' ?2 r6 a
;;;4 Z* M9 a! O% ?9 D' b  T
;;;    ERR_RESTORE: This routine should be called at the end of command to7 A9 n# w8 Y) [) s
;;;           restore the VARIABLES, UNDO & *error*., X7 m  w$ _0 @0 T  }9 b4 L
;;;
( P( u6 U5 R8 h;;;    UNDO_INIT: Initialize the UNDO status# J6 m7 }6 `: P8 ~! n" f8 G8 _
;;;1 `/ L% O# ?; p+ l/ @1 I
;;;    UNDO_RESTORE: Restore the UNDO status9 m+ Q9 l7 c( R" Z  q
;;;
' D5 `( l( J4 z. i( |2 Q;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
6 s4 r# ^' N# _$ g0 n1 `;;;
# ^0 j5 Y$ w1 x* S+ e6 J1 ~! O  B0 \;;;    UNDO_set: Set the variables. the argument is like
( G! v3 X# [: C. {;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
+ j) i4 p% ~0 h- {;;;
- b; r* P, t+ x# c+ M6 L; w3 i3 Z! q;;;    UNDO_RESTORE: Restore the variables
0 G" J- R0 S: r: w% s0 b; z; L1 X2 L;;;
! i' B# d: r1 T( g;----------------------------------------------------------------------------
( t5 x6 ~# W0 V* j' h;  GLOBALS:
; o7 P/ c- l- O;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)$ Z, [8 @# \- I
;     m_lst       -- list of variables (voided by VAR_RESTORE)/ D8 F- X7 ?, j* T. @
;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or
( p3 Z0 W5 _5 f+ H# S: x;                    ERR_OLD)( W, X: T/ n3 E; k
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)4 ~! W& W0 Y6 p! n4 b
;----------------------------------------------------------------------------
, K6 M3 m1 m3 i  m# |
6 k6 Q6 `1 w- p" P;----------------------------------------------------------------------------
  v( K+ q7 U& }4 k2 y; Modify attributes according to entity name, attribute name, dxf_item
# b( C1 m* C' B# Y7 o2 \+ o0 f! K  v;----------------------------------------------------------------------------
; @' ^" M! S) A2 j(defun mod_att(ent id dxf_item)        # {$ R5 C3 w# N' G9 H
  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
7 e; Q5 G! i' ]: ]3 S) f* q5 i    (setq ent (entnext ent))) b+ R1 j7 m0 Y) z& k
  ); while  
# X/ s, E0 F4 L7 y! B/ B$ [6 O  ((lambda (x); Y0 i  y* Y) e$ x7 Z( Q
        (mapcar '(lambda (y)6 v  o2 G  g1 J6 K. O3 u3 ?: n
                   (setq x (subst y (assoc (car y) x) x))
# h, c7 d; y# |* Q& M, f                 ); lambda' P, [  j9 x$ j; T! @
                 dxf_item1 [8 A- _1 _. V# {4 ]1 U; f" j8 u
        ); mapcar( A3 B! a- K" P
     (entmod x)2 R" ]/ d$ p- e) e6 M( J4 k' f( c$ u+ }
     (entupd ent)5 e' B, o1 m1 {2 X
   ); lambda6 u6 ]" w4 @4 z( ~
   (entget ent)
* X$ S* u# k8 Z3 I9 ], n7 ?8 Z! i )
* G# a. V6 t# |) E2 V7 ~7 l; s( i, y1 B); defun mod_att
0 |6 g& }9 O6 D/ P
: }' [1 Z- U1 ?  J7 x1 V;----------------------------------------------------------------------------; t/ O! u* o8 u  E3 p
; Check layer status, return a association list which contains layer information
) b, X* z7 x! I# i3 Z! T;----------------------------------------------------------------------------" i) O7 K( Z2 z, F
(defun laychk(lay / l_sta)9 d8 ^1 D- R% R
  ( (lambda (x)& [. Q  N( m' F" ~. M' T
      (if (not l_s)
. @* g. y: i; v1 z. L$ }# _7 ]3 ^          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))$ d/ L4 X- U. e, q2 d2 ~# t5 Z
      ); if. d9 @$ P" \" T6 E) T3 e
    ); lambda
; [' s% A4 S4 B0 j7 Z    (getvar "CLAYER"): k2 K6 x. ?; G$ A5 _
  )
" Z# I) |/ v# z9 @  (if (not (tblsearch "LAYER" lay))) P: Y+ j$ u9 E$ z; O. ^/ j
    (progn  
" p7 u: X/ R  ^3 `% r: W8 u: A      (initget "Yes No")3 D6 u* c8 f* F/ k  d- N" y: r
      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
7 U6 ?% w3 |5 v+ ]; H/ h        (progn! m; u/ `" p. _1 G4 `2 S6 c0 }
          (command "_.layer" "n" lay "")8 F( ^8 O$ Y) T
          (setq l_sta 0)
' |1 E4 J3 G; Q! a4 a        ); progn7 ]. `% w( V0 f
      ); if
$ ^) |( N# ]8 @5 }( c    ); progn" `) d, A8 Y7 K, }+ d. ^
    (progn
/ f4 ]$ j6 t: d# G      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))- H" u3 e. m/ T0 y+ o- Z# v
      (if (= 1 (logand 1 l_sta))
9 B* z3 C, @# k3 f          (progn
1 \" A& e: r4 f  L& M            (initget "Yes No")8 |4 D# h; p3 E
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")3 f% @$ W2 a+ h8 F" q* p4 d$ ^$ f
              (command "_.layer" "t" lay "")
% Y( Z9 I* @; f& I- s* Z              (setq l_sta "No")
- R$ V/ L7 V% Z7 N: L0 ?1 `             ); if
& }2 h# w- r9 R, p& |$ J* r          ); progn
1 E6 V$ ]3 a; E7 ~8 I      ); if
! y- C- F" \$ e      (if (numberp l_sta) 1 T+ f( a+ T" ^# G! h
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
7 }! u& |( F4 v1 W      ); if" i4 ^1 A: k! T, t8 F
    ); progn3 v0 ?+ V$ |6 B8 k- {8 k
  ); if$ h+ d# ?, U& I+ H  m
  ( (lambda (x)% |: Q0 s$ N, d6 W/ c/ D" O
      (cond
: n: P2 R, ^+ Z2 f        ( (not x)
8 O; k2 x. N5 X) c' j          (setq l_s (cons (cons lay l_sta) l_s))
/ S9 }7 G3 Z1 w& W5 N; U        )
! e* t9 @4 S# y# w* O0 X3 N. O        ( (= "No" (cdr x))* \3 b' h8 n; E
          (setq l_s (subst (cons lay l_sta) x l_s))
' O8 T# h# B: `, ]2 k  c( I        )0 {8 D% m1 F; M/ B7 V" B
        ( T l_s)) i. c+ q1 Q0 K% R
      ); cond' t1 u. ]  ~6 h- @7 G
     ); lambda
/ j. W. z& {! d     (assoc lay l_s)" x& F; s  E  ~$ {: y  e
  )/ W, q* G$ B; u7 i2 X! r
2 y  ]/ ~2 B$ R; i! b9 c7 S
); defun chklay% L6 V8 d4 g1 Y0 x2 p' \; a

- y. o) O. P  \* a6 P' }7 Q;----------------------------------------------------------------------------
, c; s* a$ H$ _6 F3 F& X8 y; R; Restore layer status according to association list l_s! c9 \7 j4 W0 Q3 u' O4 w6 s3 s
;----------------------------------------------------------------------------1 N' E- c1 s$ X7 R$ m1 Y
(defun layres()2 S; |! f4 J4 r2 q3 p8 H* F
  (setvar "CLAYER" (car (last l_s)))' P# z9 [& T# Z
  (repeat (length l_s)8 q, A7 K; m" A% v5 {  w$ m3 C6 U
    ( (lambda(x)  
5 |0 |' z" [6 L, [8 c        (if (numberp (cdr x))) b7 ~; R" G; U  n" |
          (progn   ~# W: B, C4 n* k' W& M
            (if (= 4 (logand 4 (cdr x)))8 u* B$ f3 x9 d9 ~1 c
              (command "_.layer" "lo" (car x) "")( h; }6 {+ x6 [6 U% v3 k8 {& Y+ i
            ); if
% ]' E  }& l( s8 v- [* u; s            (if (= 1 (logand 1 (cdr x)))' j  m% n, b0 J* m0 X" X
              (command "_.layer" "f" (car x) "")8 E# ^: S: }3 H
            ); if
3 ?9 d8 i' F) @& O          ); progn$ ?) a7 j" x' z0 v+ I/ w/ x( b  [
       ); if    {. X4 d" ^) O/ x: z1 E* o6 ~
      ); lambda
* _! b$ }& e- |* b# D2 h      (car l_s)0 d# u0 w6 W8 [8 n6 i2 s
    )
! S1 s4 ?1 Z- f) ~    (setq l_s (cdr l_s))
6 F( ]' Z* a6 z" O, u4 p  L( x$ P  ); repeat
; P5 \: X# E. t: Q+ M2 H1 e- P# a); layres
+ `7 U5 ]+ b7 L9 H# [1 I6 W' f9 E( _1 K% @
;----------------------------------------------------------------------------( r& m# O+ e* J8 d: E! g
; Get DXF codes
+ R6 e0 ?" l. C& ^2 T0 @;----------------------------------------------------------------------------( E3 @+ H! n" k& o8 z
(defun entgetf (index ent). q9 k+ f$ b  G2 P$ f
  ((lambda (e)
' y; v4 t1 }4 B9 ~' K      (mapcar '(lambda (x)
3 L# X: Z2 ~" U1 j+ x; e                 (cdr (assoc x e)), K: i" V! Q/ s* i
               ); lambda( U; X% O7 z' J' w( m( V6 I) n3 G/ |
               index) ; internal lambda function
/ Y* ~$ p% U7 V# r8 s# E    ); lambda1 m) z7 u% v. _  Q
    (entget ent)
1 v% J' j) v6 c. c0 S+ F  )8 S0 ]1 X. T: t7 e$ W
); defun entgetf
; |7 f/ V+ E4 W* V! ~+ L: Z1 A( I' k. w* F4 j3 V
;----------------------------------------------------------------------------
/ N1 q- ]4 p$ F1 c8 \; Save UNDO status8 ]' W  ~6 D/ j8 \" u0 Q
;----------------------------------------------------------------------------
6 K" k! K: Y  y6 K% y1 q(defun undo_init (/ cmdecho undo_ctl)   6 g; X9 t( Y2 z# F' ?
  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
* W/ P& o3 W+ E2 D: B6 ?( }  (setvar "CMDECHO" 0)3 v2 r6 \2 O3 A5 O6 b2 D
9 F, x# w) T' p0 _
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
& K7 K) W5 ^: a* s* W+ J    (command "_.undo" "_all")8 y3 l- G2 }1 [9 ]2 n, Z" }
    (command "_.undo" "_control" "_all")" X" I% J; w  s1 Y
  ), B5 ^0 O! j% }$ |

& u6 q- B& y7 A9 }/ a. h7 a% W6 S* I  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off% C" w% W: L( ~
    (command "_.undo" "_auto" "_off")9 R/ z0 f8 O$ G- ^0 _2 M
  )+ T# [$ t9 x: `+ E

7 r% I# ?: z/ @3 w& S) b  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
# w3 I9 s8 s  ]9 i+ d- v8 |5 Q    (command "_.undo" "_end")
6 j* J7 q4 c/ |, |/ i1 h# M4 C4 Z- B  ), @( W+ Q8 b: h0 `

  i/ H: t) O) z9 B9 m  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))6 w9 F) h( g3 a
    (command "_.undo" "_group")
$ ?) d  Q8 B7 u* _  )! |0 }( d. B% V+ c

2 j" l4 [, f5 y7 g  (setvar "CMDECHO" cmdecho)
  ]- K# B8 ?5 q$ N0 R) I  undo_ctl' t* f& f$ H9 i& w: b
); defun undo_init# z* o1 x" k" M0 V( v- n+ v
, @! I* c6 I# k
;----------------------------------------------------------------------------
" W1 W# x" i8 _' O; Restore UNDO status; l$ t' f" P7 a$ [6 X: E
;----------------------------------------------------------------------------
2 P: t1 x/ _" R: z; ~9 u(defun undo_restore (/ cmdecho)
0 T/ S3 k( n( H5 \  (if old_undoctl
% v4 C3 V9 z1 A4 l0 X7 r, N, S' t    (progn% }( {8 p  r  a4 S8 [% @$ X
      (setq cmdecho (getvar "CMDECHO"))) Y2 r+ G  t; F+ ?
      (setvar "CMDECHO" 0)
8 L* `) ?  k, k
9 O+ s) s1 ~1 L! y2 j7 W8 ^      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) " h3 R: O$ b- T9 W" X
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
# D# C2 T/ Z" c0 ?4 k# O        (command "_.undo" "_end")3 T- ~5 H/ n7 L- G4 N
      ); while+ V! l3 X* J# @, G1 D
6 f# z; ~5 F$ |

* z* a: h% [: n; _) a) s( x      (if (not (equal old_undoctl (getvar "UNDOCTL")))2 w2 B% H4 e# ~( m- W& F: \
        (progn( l3 r' A! b4 f, `
          (cond; |' l. Z/ d4 _, z: ^
            ((equal 0 old_undoctl)
- u* o, x* X9 r              (command "_.undo" "_control" "_none")
4 P+ y7 N5 X: S+ z& T' Q0 Q! ^            )4 q( c/ w% d  K$ ^) r) z' _0 E
            ((equal 2 (logand 2 old_undoctl))- u9 Q( U4 \* ]
              (command "_.undo" "_control" "_one")
, z8 x- [& q; L/ ~; @            )" D! c* |9 D7 u4 t- `- ~( z# X8 }6 T1 i& N
          )1 R3 N0 G$ Q% l4 |4 [
          (if (equal 4 (logand 4 old_undoctl))
; ^) l) z0 m' T  u% Y! a              (command "_.undo" "_auto" "_on")
0 w( v  k& l0 b2 {# r              (command "_.undo" "_auto" "_off")" e8 ?$ r; r6 A+ G' d+ p! w, k; B
          ); i+ Q- F1 W9 [- I5 f* W7 H
        )& P( G2 V0 ?  h( E- T
      )
$ [# A0 J( C- \/ K3 q3 n! \      (setq old_undoctl nil)
! C7 t! t2 ^- ~# I1 O4 t2 R. a+ T      (setvar "CMDECHO" cmdecho)
' r, M1 i) ^8 v  }4 I7 R* ]1 k    )
1 P( W+ m0 K8 g  )
0 A/ B; w! @# P; ~); defun undo_restore
0 I/ ?& \  u2 U4 {' P+ H0 O* e/ y, k- A
;----------------------------------------------------------------------------
) |& X% m( k! ~4 s# [( B9 e; Save variables/ V- L1 @5 ^" W( x
;----------------------------------------------------------------------------
( \& o6 Q) U0 E' C( M7 }% u' c4 y1 A(defun var_save (a): j" I7 w( a/ ?7 _# G9 Y
  (setq m_lst '())
/ b7 N( b& D0 C- n# z! b  (repeat (length a)
. L+ s9 `, K$ D2 Q1 [    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))6 a$ [3 Z* ?- C- h
    (setq a (cdr a))
3 y& M3 S8 b4 i; e9 r' Z! l6 `7 }  )
+ Z- e) D$ x9 H7 I); defun var_save# o, Q' f% M9 F; p* m

" O5 z* n, M& j, Q5 o! h" m;----------------------------------------------------------------------------, k$ S0 v& i, s# M! w3 G. j7 T( m
; Set variables8 c1 ?  b5 i7 L7 g. W) \' B
;----------------------------------------------------------------------------
- \5 R3 W  R0 K8 J5 _& M' Y(defun var_set (m_lst)
* ^, W1 i% K9 x  (repeat (length m_lst)
7 C' J( }9 w- Y: r. T9 M    (setvar (caar m_lst) (cadar m_lst)), @- J" A+ _: ^5 e% o& v8 P: I8 b  v/ y$ |
    (setq m_lst (cdr m_lst))" D& ^( i  W$ x& |1 H: ]! g
  )
, ?6 N0 |+ L' C! m5 m); defun var_set
) v; l) ^8 Z' P" N) {! c, _& H* `2 }% m: s9 O
;----------------------------------------------------------------------------+ [7 G7 D9 X1 ^3 d$ W$ J+ Q
; Restore variables8 L& z' l' p5 v: M
;----------------------------------------------------------------------------3 ^0 b8 q  I  B9 y4 _0 m5 R( h
(defun var_restore ()$ q$ \5 k+ e/ T* D7 U0 U  y' s
  (repeat (length m_lst)
$ `8 T4 L6 J. v) @: Z    (setvar (caar m_lst) (cadar m_lst))
, v9 w* s3 N& w. T    (setq m_lst (cdr m_lst))! {+ y4 G2 n5 P  w5 B
  )
3 P5 p; k) w5 C, A) A/ `( z4 U); defun var_restore
! U5 t2 H: Y; |4 R+ Q# F7 m: |4 z$ \: E# z! _  Q2 [
;----------------------------------------------------------------------------
' B2 }% f# V: n5 b; Initialize routine
. F- w5 R* `! }. ]# o: ^$ `;----------------------------------------------------------------------------2 f4 I7 `% i& S! [# X8 n2 Y$ l
(defun err_init(e_lst u_enable add_fun); G+ ?  m! U6 F/ U' z
  (if err_alive (err_restore))          ; To avoid nested call- W& |4 v1 O/ ]" b0 ^
  (setq err_alive T)
/ M+ J4 p, @, U5 S  (var_save e_lst)                      ; Save the modes; O( s, g8 c: u! J7 m3 N2 F
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status
% E6 J4 Q# a& Q$ y. j  (setq err_old *error* *error* err_main) ; Save the handle of *error*
" K# `/ Y4 v0 S7 B7 j9 s  (if add_fun                           ; Add the user cleaner
+ N8 G& {; f, N/ T    (setq *error* (append (reverse (cdr (reverse *error*)))$ U) }) s$ X# E4 d0 ~
                          (list add_fun (last *error*))
6 s9 X; [9 N. Q& I% b/ |                  ); append
; h5 Z. K% C7 H7 ~    )
, T) @% n7 Q7 ]4 g9 H  )
$ T3 j; h6 a$ P. ^: |& c! D); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
( F+ _! O5 w9 z; Error routine body* ^* u6 c9 X1 s+ {' u
;----------------------------------------------------------------------------) C1 l& S$ d+ ^# O$ i0 p, G, ~
(defun err_main( msg / )                ; Body of error routine
; K  U1 @8 b! K1 {- \  Y  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs
" B6 _( G5 w* g6 X    (princ (strcat "\nError: " s))      ;while this command is active...
2 \: P+ t* g* Y, {# ~/ c# P  )
6 Q5 T  @8 R& p: Y, k( {& O  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
8 ^5 k" j. I9 I, H2 s! C& _9 `! |8 l# Z# i0 O
  (if old_undoctl! w+ V9 J2 e$ Y- ~& e
    (progn* M: J) e  A6 C8 K1 ^4 p  ~4 q
      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See7 y5 `* h+ ^2 E! o
        (command "_.undo")              ; if it's in UNOD command9 R+ W; B4 I$ ^$ o
      )! `6 M; }+ `% h4 E  W2 O
      (command "_end")9 Y/ K1 O, e  P8 n" X- v  Q
      (command "_.undo" "1")
- q. ?2 B8 C0 S0 ]6 M- m" A; c: T      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
) o! v7 x0 {4 j* I# O) N      (undo_restore)                    ; Restore the status of UNDO, K  v; Q/ t" E/ {
    )
" s1 a( s8 S; {4 S$ Y) ^  ). t* h+ W, x7 W& I- n

3 j/ s" T" V! |, \, A  w  (var_restore)                         ; Restore the variables3 E# h3 o5 @9 Y$ k! R( X; c
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
9 C# A& E% l+ n# |  (setq err_alive nil)
; A) V' m7 o# N: V  (princ)* r7 t0 I* G1 b% Q) N3 B
); defun err_main% M+ V% Q  g0 W# I# G( n
6 M" B% s; O# \( r3 O3 h0 C. ?
;----------------------------------------------------------------------------
& _6 ?3 @/ q; i$ q; Restore error status, Z5 `9 G3 f- a" |. P
;----------------------------------------------------------------------------
+ I8 E" w9 z/ @) ^( k1 \9 j0 G1 g+ _(defun err_restore()  T6 C% X0 [( p/ d% K
  (undo_restore)                        ; Restore the status of UNDO# G5 \' Y$ [; A! K) }
  (var_restore)                         ; Restore the variables0 d2 J, h" O6 u' D$ U( m" H9 k
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
: ]1 B3 n: \* {* j+ d5 {$ R  (setq err_alive nil)
2 p* i3 ?( h. Q) I  (princ)
" L, Z% U7 M' T); 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-7-1 04:59

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

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

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