CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:2 I5 T: g1 X; W; ~, [
“工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
, g. \( i( x, g提示:加载成功; }8 X: G3 y: p
然后使用CLOUD命令,
$ N3 y) n! U8 Y4 ]2 T提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
( G3 U1 s- B4 B0 n, @6 f& e请高手指点一下,这个是怎么回事?应该怎么改正?3 W- B# Q2 U5 H7 p! s* L  a  z0 j$ [
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx# v: w: F6 w1 r. i. _
;;;
) Q% x4 ?% T* C! ]' O;;;  DESCRIPTION( O& p8 h6 P4 u- ?  H1 S: A# A
;;;     Draw cloud and you can specify the globals variables listed below
# A5 O1 f2 v8 N  I' @, F: i! M;;;     to decide the characters of cloud
% y  f2 n8 b' K; U;;;
' e. o# }0 s* A0 a7 C;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98
6 [& o1 ?* \0 m# Q, ?;;;% u# P1 `: f0 [+ f
;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
, ^" ?- C# Y) ]0 k9 c* I9 B2 P9 {;;;           Change CLOUD.001 to use CLAYER to perform the same function3 W7 p( B5 h( n/ ^* d$ _
;;;           Use the common error routine UNDO.LSP to optimize this program
8 H0 t. E0 u% _2 };;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE
4 V) ?) \. G' _: n( N( B3 c: g$ Y;----------------------------------------------------------------------------# c; A0 i: }0 ?! |+ y( }* n
;  GLOBALS:6 U+ z0 A6 m+ y# s( _
;     cloud_layer -- layer of cloud8 Z; @4 s0 n- Y
;     cloud_scale -- scale of cloud' \3 A  H9 C- u5 k, e
;     number_rev  -- revision number
# y$ }$ P2 i% W+ U, _7 i7 L4 r1 ^;----------------------------------------------------------------------------
+ I" Z! E$ M' V* f4 z(defun cloud (/ locked temp first_point next_point relative_point
9 l" X, A+ C: R. d               last_point point_tri point_ref corner_1st corner_2nd length_tri( b) F, T* T/ h6 i, c/ @
               length_cloud angle_l_to_f dir_tri repeat_count 5 k% C' |' B1 j8 a' h% F
               table_cloud )0 I+ h2 v2 m) T: b4 I/ L
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))3 A* D2 o( {) p6 V! z; ]! u
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))9 H% L. U. S" m5 |
        );if) x: }/ \1 `( m
        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE"
% I* @: Y# t. e8 a8 M+ C                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil))
9 X5 I0 k0 r- g9 `5 G        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
) X: v. D& ^, [# c- |) {                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))
$ h& a: G6 u  s9 Y- r  J4 o5 I4 b" k1 A: H1 J" O- z
        (if (not (numberp cloud_scale))
0 L( Q% O/ j- Y4 w1 ?9 P            (setq cloud_scale (getvar "LTSCALE"))
) g2 Z+ i4 M- `" S/ |* F- C        ); if4 a  x% e$ ~3 u* m3 `
        (if (not cloud_layer)
) ?% k9 R& L" g# Y( d3 e% G$ B            (setq cloud_layer (getvar "CLAYER"))
. S4 V' G1 B7 E1 }. |7 G9 m+ W        ); if
* n, Y9 ^& U" r- L        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))+ I. \1 i- u9 ]7 }$ ]+ R! m: V* J
        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
$ L9 R' P! Q( i5 j6 P3 X% X7 F$ L        (if (= (cdar (laychk cloud_layer)) "No")
+ {9 l; n1 m% M1 p  f7 u          (progn; f+ ^6 |" i" p0 S4 J$ V0 y! Q3 ?
            (laychk (setq cloud_layer (getvar "CLAYER")))3 M5 ^0 s9 d2 w% z
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
, c& L' |- |, ^          ); progn# p  {- S" ~) c3 E' ^8 a6 f
        ); if. V5 L1 _! ^7 L

% u- Q* J- Y) ]! f( _2 ]3 r        (while (/= (type first_point) 'LIST)
! s8 c) i" f  W% h' J! c& Q! L          (initget 1 "Layer Scale")! a8 X+ u$ x: P" c
          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)
; w7 ^6 [1 v+ W! B# |$ L* N, \          (if (= "Scale" first_point)      6 T0 w, p. H% B  e& V& p
            (progn
1 f3 i% H% t, x. u7 t              (setq temp cloud_scale), y- V9 w3 v, `  Y5 u  T, c2 J' m
              (initget 6); v* H2 [9 I3 ]6 Y' H' A9 r$ L
              (cond: z& ?7 @* a9 E+ U
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
) |: K( n0 J5 t% P                                                          (rtos cloud_scale 2 2)( N( x2 B0 s8 E" C3 d
                                                          "> "))))
. @9 B# r2 G, X2 k                  (setq cloud_scale temp) ): }' O1 D; G& C5 T; z+ C& v
              ); cond
; _' A, Q+ _) z% U9 m1 q            ); progn
4 @. C- h4 k% Y7 ^6 y9 s$ G5 s- k! \4 ^          ); if8 e8 m4 v% T0 U) @. ]9 s: l! M, _
          (if (= "Layer" first_point)
( C/ z( ^& z' {: ^1 p            (progn, X" }& @+ O! \7 j& _5 X
              (setq temp cloud_layer)7 [$ E$ ^$ X% F2 \$ q
              (cond
( l2 a; F4 T' q# C                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
7 ]2 A0 [- ^1 z' o. `                                                          cloud_layer "> ")))
6 g  g* B3 H5 p0 D; o                     "")7 {8 R6 W! e: F0 N
                  (setq cloud_layer temp)2 ^9 Y5 l" L8 d0 n+ t
                )
) Z, r4 w9 K' z8 E# P. u0 k              ); cond' p0 |) L/ k) B  e# u
              (if (= (cdar (laychk cloud_layer )) "No"), J/ k. a. F( G7 ?! r
                (progn8 T1 F( q3 O  |1 h$ m  o
                  (setq cloud_layer temp)9 Z& h& u" I# }' @' |
                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
5 }1 Z# {' g, \7 B. z                ); progn
7 n$ g) ?# l1 ], U; e              ); if
, {' K4 w3 ~5 W9 u: G' s            ); progn& i& B  e& G" F9 ?3 w2 v
          ); if, s4 p5 `! w) f( f! I( }
        ); while2 y3 e) P4 O0 J% h2 Q
        (setvar "CLAYER" cloud_layer)  C0 P, [: n6 ?% V/ Z! n: k; ]
9 i6 y3 d. W" x7 d& V  U4 W
        (if (>= ( getvar "LUNITS") 3)5 ?4 o! X9 v- }3 N" D
          (setq length_cloud (* 0.25 cloud_scale)
  z0 r. R9 z6 H, N+ D0 O- f                length_tri (* 0.3125 (getvar "LTSCALE")))$ p: G% g% `7 w% f" j4 k& A8 d
          (setq length_cloud (* 0.3406890 cloud_scale)
( h) v, W. L+ Q. H                length_tri (* 0.438366 (getvar "LTSCALE")))/ X# y" j$ T' Z7 s& C' Q/ \
        )" [1 _3 z, B" n3 K* X1 F! o% Z
        (command "_.PLINE" first_point "A")
0 A; b/ h2 r" U3 [4 Z: E        (while (not (equal next_point first_point 0.000001))2 Z. W# `- W* p: l5 u/ t1 |
          (initget  "Close")
( ]. ]; S* _. N( @          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
$ H: n: }: Z/ A8 B; {        (while (and (not (listp next_point)) (/= next_point "Close"))5 r( B; i6 b4 l. a( ]: t9 G
          (initget  "Close")0 L8 w# n! q0 y, |$ b. j+ t8 X
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
9 r2 O& I+ g/ y0 t# Q        )7 d2 i% x9 P: N/ n% N' `
          (if (= "Close" next_point) (setq next_point first_point))
7 h) S) b' C3 X, C  R( X          (setq angle_l_to_f (angtos (angle last_point next_point))& s7 Q1 R, E. J% O- K5 o& [# ]3 X# ], ~
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))
+ Z) |4 l4 R5 F, u" B2 B          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)9 J6 U  O# S$ \0 B4 ?, T1 c4 h
             (setq repeat_count 0)! K9 e9 P' p& l/ e; k# H3 j9 D
             (if (>= (- repeat_count (fix repeat_count)) 0.5)
+ R& {. M/ O$ ~8 ]. z               (setq repeat_count (fix repeat_count))9 k! V% Z5 ^) x0 T4 u' n+ D( v! U
               (setq repeat_count (1- (fix repeat_count)))
  {4 [9 ]  b3 v3 c             ); if - r* Z5 e% @! U/ J) p
          ); if- ^- T9 p- f, u
          (repeat repeat_count (command "A" "-100" relative_point))2 \6 ~8 x/ w9 n2 d# G% J. ]1 ?" R; O
          (command "A" "-100" next_point): x& K0 k* i/ F7 ?- T
          (setq last_point next_point); V: P. ?# d: N" g) I* F
        )" y  h# s* |. `
        (command "")
1 m6 {/ y; @5 z        (if (= (type number_rev) 'INT)
2 g* l2 n- W* i& t$ @           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))9 g6 f/ Q' ^7 d& C8 i% x
           (progn
4 O# X( G; W: e# X/ @; B! I. Z2 j. o             (initget 5)
3 \' B& s% R% A* s5 B5 y             (setq number_rev (getint "\n请输入版本号:"))
' R* a+ D" ~% a/ N2 ?: P# g% c7 u) G           )
5 g$ i! v& M; _/ C        ); if6 e+ b' c( c: z
        (setvar "OSMODE" 512)3 N& e$ L. s! @1 I7 y! a  P* D' n6 ^
        (while (/= (type point_tri) 'LIST)
  }: h1 Q; m: w" A# l* g- L          (initget "Number")4 c; d6 l! r8 @1 f% H
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
! a, N+ }  |+ o3 l! o$ n0 A          (if (= point_tri "Number")
! t3 o- _  \) o* V9 q, @              (progn
* v4 `. I* X* S( [                (initget 4); c3 u5 x" J) B0 e8 V
                (cond
/ a; f! L" X" k. S0 Q                  ( (not (setq temp number_rev
5 L, W+ l( v& R8 ~; c! Z                               number_rev( ^1 l4 O# F( \4 \$ f$ L
                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))' ~7 T/ j$ H' f  s( G
                    (setq number_rev temp)
7 d  J! w! n) E& }' N1 w0 s7 u                  )& m9 B/ ~7 l  |  g7 ~0 I
                ); cond7 Z8 e. f- ?, @0 E' g
              ); progn
0 \# W* A/ S3 x- M( }4 a; J          ); if
; B# y2 ?2 F  Y( D0 s( e+ \        ); while
! \6 {$ s: m1 E, C; j' p        (setvar "OSMODE" 0)
9 e3 c# q- }# v7 m        (initget 1)0 D3 Z3 G( w7 N8 Y3 C3 t
        (setq point_ref (getpoint point_tri "\n请选择方向:"))
+ N# X4 t  M4 r0 `! {3 v5 i        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))
5 l% t/ \4 K: n% d        (setq corner_1st (polar point_tri" P- N# q- q# ~' \5 v
                                (+ 1.570796327 (* -1.570796327 dir_tri))
6 s& E1 D( w, l* ~! e. T                                length_tri
- e! i$ V' E0 ?                         )
  @, V  t5 p  {        ). p/ p- C5 {9 z
        (setq corner_2nd (polar point_tri! ~0 b, Z5 H7 J* _+ w
                                (+ 1.570796327 (* -0.523598775 dir_tri))
" W* h) Q0 L. M$ p                                length_tri
3 F( T, G2 W% \1 o                         )5 ?$ v5 K8 v0 }1 {8 j+ c9 B
        )7 J5 R0 ]0 y# W, P8 j- b  X
        (setvar "CECOLOR" "2")& Z# R- `6 m: @4 i! n3 b' |; I3 ?
        (command "_.pline" point_tri corner_1st corner_2nd "c" )
( Y& \/ z8 m" N5 G        (setq textstyle (getvar "TEXTSTYLE"))
* ^1 R+ a8 T' C4 V' {# y- a) ~2 B& E        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
! j1 O5 e0 d1 }        (setvar "CECOLOR" "7")
, W/ v$ w" R/ @1 W# J        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
. a  |0 s. R: t& ~3 x! X. Z# I                  (* 0.4 length_tri) "0" (itoa number_rev))! m$ T; M3 I( a( i1 t  D
        (layres)
2 c9 U; B# |" W& K- Y! J        (err_restore); e4 l# c, Y, \  a8 r$ \5 t
        (princ)
, ?9 H7 a9 M9 p: ?$ j" g); defun cloud( N( {* z& j% j0 k
1 W# |* @  S8 _) r& g
(defun c:cloud () (cloud))
3 D+ L3 I& w7 X, a$ u" [" a(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy. U' W' a1 ?8 h' Y( _) B- C
;;;8 m+ T+ ?6 e" X% q
;;;  DESCRIPTION( ^3 h9 A4 V% ~! t; T- Y
;;;     These are general error routines which can be called by . b8 d; T: M+ ?
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference. t# M1 p1 [; C3 ?0 Q
;;;
- M: S; w" C2 D; @( h0 M1 D" v;;;  SUBROUTINE INCLUDED IN THIS FILE! C/ T- ?7 n/ `
;;;     UNDO_INIT. L  Z6 j% \9 X( q  K- G! ]6 J" \
;;;     UNDO_RESTORE
1 `# K$ M' e3 B9 a;;;     VAR_SAVE . O2 l; y8 c) R# I  e2 C
;;;     VAR_SET  % }2 K) f4 l% F" H0 A: ~
;;;     VAR_RESTORE7 n& w- K  k/ @; J
;;;     ERR_INIT
, b( a% ~- P" E3 H;;;     ERR_MAIN
3 H0 C4 X2 m7 y$ O;;;     ERR_RESTORE6 n" a/ P7 I' ]3 f, r+ V+ G3 m) V" V
;;;
9 w  V: f: W! z;;;  DATE: 10/17/98; 03/31/991 m6 ^9 t; ^4 r7 ~3 t8 o
;;;
: S2 H9 C- d: U, B; r;;;  HISTORY:
* @7 _9 ]; P' B# F3 |% ]# w2 o;;;    Add routine of mod_att
* j) M8 G& F! {2 M;;;
. t2 S1 v, L& ~- l;;;  USING METHOD9 k" F/ l% P: P1 L/ ~5 y6 m7 P
;;;    ERR_INIT:) V* N5 p" E8 `
;;;      This routine initialzes the error handler. It should be called as:
( h9 r4 ^) w$ ]. O3 r  L;;;* R& X8 \/ \: }5 O1 B( j& o+ ]9 `. c- f
;;;      (if (and (not undo_init)
% |3 n6 `: q0 F; R( N) l& a6 L;;;               (equal -1 (load "undo.lsp"  -1))
7 Q# f3 I$ ?3 u) p7 G;;;          );and2 C- G* q5 Z( i! p- h1 C4 ]
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))
6 Q0 N- A1 f1 i& D8 Z1 C& }- b" v4 l;;;      ); if
) }1 m: M) S5 s& d4 n# U* X;;;
. z. ^! U% A* b; C- [;;;     ARGUMENTS:! S2 ?6 y6 F$ c& |4 u! [
;;;       err_init Takes 3 arguments.
. r0 w( W- ]/ r, U2 I;;;     1. - The first element of the argument:
; \, P  Z' p7 g2 X8 Q;;;          This is a list of system variables paired with
/ M7 C6 D0 j* C" l# z& u* r3 |;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
! k5 M: y, _1 b2 p% P$ X, Z+ ^;;;     2. - The second element is a flag1 P2 q3 n- ^0 c. w
;;;          If it is true, then in the event of an error
. a# E* P; b& F0 l! `4 R;;;          the custom *error* routine will utilize UNDO 6 {7 ^, C/ u- \. Y$ O& d
;;;          as a cleanup mechanism.
! M7 [' [% K6 m$ W  W;;;     3. - The third element is a quoted function call.
- Y: |! y$ r2 J, W4 O# U, L9 u;;;          You pass a quoted call to the function you' k' }+ E7 @+ V! o; T6 e
;;;          wish to execute at the end of nomal routine if an error occurs. * |9 H4 Q/ H7 H: J. `
;;;          i.e. '(my_special_stuff arg1 arg2...)
! y/ ~: w! o2 z4 f;;;          Use this arg if you want to do some specialized clean up 0 [( x+ n! a8 `
;;;          things that are not already done by the standard bonus_error
) ~. T, a: D+ J5 P: |( a* |  u;;;          function.
2 C1 `/ _' ^0 k$ Z  u' L;;;& T% p! K7 p" n, J' D
;;;    ERR_MAIN: Body of error routine
; e7 Y3 {  b  |8 O+ r" ~4 ^" \;;;
! M! V3 X8 ~4 w/ S5 h;;;    ERR_RESTORE: This routine should be called at the end of command to
9 ?$ f$ y- r2 {* _' H# d;;;           restore the VARIABLES, UNDO & *error*.
6 d2 L/ ?0 y" ?3 b) p* o/ b;;;
: ~/ g& B* [( b/ O" [8 m;;;    UNDO_INIT: Initialize the UNDO status0 x' u$ R/ ?+ I6 n5 e
;;;' v% ]4 c8 y- [" Z3 e0 K1 `
;;;    UNDO_RESTORE: Restore the UNDO status
, N9 m0 G7 e9 c- h$ [5 f# W5 ^9 @- r: Q;;;
8 |" z! Z- y- \$ d;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")
4 G& c$ N3 A" b& U0 P, I;;;
  s& W- Z7 U( W: x! o, n;;;    UNDO_set: Set the variables. the argument is like/ c7 v( u8 C8 a7 R+ z
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))
- m! \; z+ _, e( R# e! h+ D;;;7 h  H& u4 V; O! I1 Z0 ?' u/ c
;;;    UNDO_RESTORE: Restore the variables7 W+ Q7 ^$ d7 R( Q1 t1 W% @0 i  O
;;;4 }2 y( I3 A6 L( N# r. F, ?  ~% Q2 x
;----------------------------------------------------------------------------7 k/ ?9 h: J/ c$ f2 U
;  GLOBALS:  R1 R; b0 z- g6 J8 D
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)& t- M5 G( X- ?$ Y
;     m_lst       -- list of variables (voided by VAR_RESTORE)
" L+ q/ J7 @$ L" `;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or: ]4 o0 n  w0 t: }, v4 ]$ l7 ^
;                    ERR_OLD)7 {$ m4 a. p% R
;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)& o) [8 r1 T1 i) G+ S0 N+ R. m
;----------------------------------------------------------------------------4 Y4 Z/ D$ L7 y6 t

2 Z5 E8 \  o9 I1 F; K$ p;----------------------------------------------------------------------------
. M( G+ e( o: d4 M6 e$ I; Modify attributes according to entity name, attribute name, dxf_item
3 n7 a; i& y4 o1 T;----------------------------------------------------------------------------- P- r( C, Z- d0 t2 M, W6 c
(defun mod_att(ent id dxf_item)        
  n, x4 M7 Q0 V$ s0 }7 W, T% r: P  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))  m* H& y/ L8 ?$ D8 N9 Q
    (setq ent (entnext ent))5 X* {9 b! y8 M3 ?: f
  ); while  ; S; h; q# R2 C
  ((lambda (x)1 {* L/ Q$ `  b6 X- {' O6 ]
        (mapcar '(lambda (y)5 I8 j5 F: W. ]* y7 y5 Y5 O8 P1 a
                   (setq x (subst y (assoc (car y) x) x)), d% `2 ~: M  p& f% y; H
                 ); lambda
+ Y. e9 Y8 K& y. ]                 dxf_item
& K' ~; z+ k' k( z" g7 R        ); mapcar( r. O8 B% l2 m* p
     (entmod x)
  e3 l8 o, v8 Y( M     (entupd ent)2 U* a- H* i6 }0 ~* h  Y& K6 l/ c
   ); lambda9 X$ m0 n' c# S5 |, A
   (entget ent)0 W/ J0 ?- Q' U( Z
)) N" I1 Z" j* I) s9 A9 f" h
); defun mod_att/ p( v- D1 V4 a1 L  s

$ J/ y3 a- @7 a;----------------------------------------------------------------------------; j" d  v4 V- s7 j. w
; Check layer status, return a association list which contains layer information
5 o% o  M" K$ h+ J; \0 F;----------------------------------------------------------------------------% O3 Q5 c3 ~, y$ g5 X' S7 Y
(defun laychk(lay / l_sta)9 `' K" k6 W1 n4 P: k) k
  ( (lambda (x)
5 a8 R4 F" M$ f  w  ~      (if (not l_s)3 G* O* U) O; v: f
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))7 K! e: z, a3 g4 ^  A9 W' e; y
      ); if7 t( s% n# ]! C2 s- f" N" x
    ); lambda
5 z, q  k$ z/ T    (getvar "CLAYER")
7 i1 M( E7 O: y! x  )( s  X/ ]( z& K8 q0 D' M8 j  M
  (if (not (tblsearch "LAYER" lay))$ L( L9 p$ H) p6 n0 |7 i
    (progn  ( o* N- G' [( T+ m3 ^6 _
      (initget "Yes No")) H" ?' C$ p, W& o
      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")1 r: i# N4 v0 T* R- f$ H' W9 u& d1 n! h6 ^
        (progn1 m0 M7 e. x3 D$ Z2 H
          (command "_.layer" "n" lay ""); l8 e7 T4 U! T4 J& Z+ w7 n3 t
          (setq l_sta 0)
7 u+ R" J5 B4 [        ); progn
9 v- U3 O+ ]: \0 _      ); if
2 J1 ?9 E9 _7 }& E1 \5 }    ); progn' W6 k$ G& C9 [; {0 I3 Z
    (progn
% b* K! A+ M5 L8 l. r9 U  v0 ?      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))
. U! K( x1 A/ I$ [      (if (= 1 (logand 1 l_sta))
# b6 m' Z* i3 W4 z8 T% E. _          (progn8 O8 W. S" F; [/ {7 N, R. d/ u* ]
            (initget "Yes No")
$ E  G& l: W( X5 `+ z+ h4 l            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes")/ c3 K" W/ F% o! v- G; \+ o4 y. T
              (command "_.layer" "t" lay "")- _" w* q4 k4 B
              (setq l_sta "No")
/ \) h. z9 @/ n7 o, a5 R             ); if% g( Z( X1 v9 z4 V9 V0 ?
          ); progn+ ~9 `1 N( j) g9 ~- U7 C
      ); if! X2 [; w! d! w  A8 C* l# g. q
      (if (numberp l_sta)
( X9 c7 H- F4 g) P        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
) `) N$ `* S" t% C- {: Y6 ?      ); if% ^+ r# g8 U8 \( E
    ); progn% R. ]8 b' U) ~+ r  F% h3 P
  ); if
9 R3 p- e! m- Z' g: |  ( (lambda (x)8 T; {5 Q2 ^( G* _
      (cond
2 s, u9 ?2 P- |. }9 r        ( (not x)
6 ]1 C8 b1 X* k" F3 [) q( y          (setq l_s (cons (cons lay l_sta) l_s))
  z) n% f8 {, M+ i9 E9 M. {/ ?        )) d( U& o7 I% X' F  Q' R
        ( (= "No" (cdr x))
' H3 m, }. H9 Z$ Q7 b          (setq l_s (subst (cons lay l_sta) x l_s))9 B' L, C, O" F! c; C' n9 z0 ^
        )) {; r. S  l# o- Q7 a9 {, L" q
        ( T l_s)8 T+ ?# {" \  e& A4 n1 p
      ); cond% Y% D# c" B% @% h% v6 I: z
     ); lambda9 s" I2 r& K4 i6 G- C
     (assoc lay l_s)
( j$ L! Q1 M% v3 n1 a' M7 S- G  )2 O% [. L# l" ~
8 S7 @; |) O, _
); defun chklay2 F3 W8 q( m$ c0 i. K# |# [( U9 M
) B# }2 W* ?2 n2 |) Z
;----------------------------------------------------------------------------7 d; h$ L* Y( y. `/ N
; Restore layer status according to association list l_s
/ F- I" J, ?, @$ l: N* W+ L- h;----------------------------------------------------------------------------
0 d& n2 H& r5 d! f(defun layres()* ^  l3 ^* t( t7 ]+ Q; m4 O" @
  (setvar "CLAYER" (car (last l_s)))
5 v, l8 _- U) f5 k) z  (repeat (length l_s)
& q- B$ B7 |4 ~    ( (lambda(x)  
$ p) z! U9 Z/ I& a; O5 @8 U        (if (numberp (cdr x))
$ f; _3 s' q# {, o8 a          (progn
, {7 U# M. |/ h/ \            (if (= 4 (logand 4 (cdr x)))* e. q) s9 L. D% J+ R
              (command "_.layer" "lo" (car x) "")6 f% X$ h% O6 A% D# ^. W2 ?
            ); if; h' x# e0 H: ^; X1 N
            (if (= 1 (logand 1 (cdr x)))* W8 r% T. W! Y1 n: J- D9 R
              (command "_.layer" "f" (car x) "")
7 L% n4 S+ P" _6 R  ]7 A. D# K- a            ); if0 ]6 q; y: c" H# F  x* K) V
          ); progn& d" S$ ]" w8 J0 `8 J
       ); if  
7 O+ \5 W2 H: c" {      ); lambda
; c3 w3 L6 ^, H- {1 j) [. W0 i      (car l_s)* ]- ^0 Z3 J% w1 l- i; j3 z
    )& o+ A0 J) o: ]/ T5 j2 H
    (setq l_s (cdr l_s)): s" M8 g9 r1 C, l) K$ ~1 c8 K
  ); repeat
" F6 }) `* n% z); layres4 ?7 o  ~0 r3 O# y

* d, U2 e, ]6 ^;----------------------------------------------------------------------------
4 d4 U! r2 C+ q# r& a+ A" _% T; Get DXF codes8 t& l- q' @" F
;----------------------------------------------------------------------------+ n% t3 u" c. e7 L
(defun entgetf (index ent), f) F8 P) r7 D8 j. m4 I. P
  ((lambda (e)
1 g: k7 B" X2 F7 S      (mapcar '(lambda (x)
$ E6 M) F2 A  Q1 h  J9 D                 (cdr (assoc x e))% f- p+ u/ k" g7 C8 W
               ); lambda5 |2 b* ^$ t" U/ d6 A5 t
               index) ; internal lambda function
2 B: s- O* m* |) B6 I$ y- P    ); lambda2 w2 B% t: D0 ]2 a0 H( ?' Y
    (entget ent)
; ]3 A# w9 M1 _1 r  ). e) s" ]& B; c2 n
); defun entgetf
% Z, L# x! L; x# L; U/ M1 R: S9 R! S% Z; D* Z% U1 g0 [
;----------------------------------------------------------------------------; N1 [: i% z; K
; Save UNDO status6 J' \: U1 s' O* E
;----------------------------------------------------------------------------) q  U2 ?9 p5 D' R
(defun undo_init (/ cmdecho undo_ctl)   
! T6 H* ^1 Q1 X, z6 y0 i% Q  M  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value
; b% u, O7 H& g* X( o  (setvar "CMDECHO" 0)
4 o7 p* b* t, K# k+ O$ d& x: L. Y+ ]' M2 P! u8 N5 ]5 C, b$ w
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable$ N# M. |- l) W% i3 i( v
    (command "_.undo" "_all")
/ `6 }. I3 F8 i$ m! K& j4 f    (command "_.undo" "_control" "_all")1 ^4 j$ s! q* w9 x8 A: J: y5 t- V8 _
  )
- N" ]) p2 |  ^1 n: W4 u# y: k! H! N
  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off( H! T1 r9 i. X1 e1 n9 ?8 M
    (command "_.undo" "_auto" "_off")
9 `  Z5 D3 _: E8 B  )' I) @8 X4 i0 T$ C* d! q
" T! {8 |) [9 k& x% x3 O# F
  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
" f: f, h4 T7 L, o6 h  ^0 h    (command "_.undo" "_end")6 k9 ], H" L# e* h7 j. f
  )$ i+ X0 W0 ^6 O! q: n/ t
2 N+ ~& ^" T9 g  M
  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
' C* y  }% h( n& Y8 d& b$ o    (command "_.undo" "_group")% p9 Q$ K+ T; m7 J
  )
/ v6 x5 D$ Q* n9 j$ r$ v
; d# N9 N# C- T1 T# M$ J1 y5 K2 @  (setvar "CMDECHO" cmdecho)8 m9 h0 X2 K! J; t, H) ^! Y4 E
  undo_ctl: f, H' U, @6 v! b3 N6 u" C6 y
); defun undo_init
/ u& v! S- n9 t  A' K" H. n# o5 a0 Q9 M4 o
;----------------------------------------------------------------------------* O  O4 A( i+ h8 v* n8 n
; Restore UNDO status  H  I: J0 }- r1 X
;----------------------------------------------------------------------------* v  L9 [5 L& O. w: m& ^/ C2 B
(defun undo_restore (/ cmdecho)
: A# v$ f& Q% T1 l  (if old_undoctl; f$ @, Z4 b4 _+ P1 ?* M6 `
    (progn
& ^/ U* @2 I; d, |+ k, x4 e      (setq cmdecho (getvar "CMDECHO"))
3 u- }" g  e# h- }      (setvar "CMDECHO" 0)# a7 b, X1 h, c* \; L

1 q! b1 m8 s+ K- k5 {( S  d      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all")) " n2 V0 F& V  G+ L" z! |
      (while (equal 8 (logand 8 (getvar "UNDOCTL")))  b/ s4 [1 A$ Z/ L' {5 S
        (command "_.undo" "_end")
- j! L( ~7 V7 e: |7 q; J, E/ M      ); while
% T9 c: R/ B8 U+ V4 s6 ^+ m6 z7 H: W( c2 D, y8 Z7 M  k4 n

# v8 ~# C9 p. T9 D: n+ ]9 E" T      (if (not (equal old_undoctl (getvar "UNDOCTL")))1 C; F% j* g% Y" q: \2 [
        (progn8 h9 q' }' C$ _. Z3 f/ ~4 I
          (cond
2 O9 R8 x, U' D9 d7 F            ((equal 0 old_undoctl)4 ]1 C9 ~1 ~. o; Z
              (command "_.undo" "_control" "_none")* C% G9 \5 G- ]: y; A! A( D( `
            )
% \, W7 |( K: N& [' y: t( R7 f" c            ((equal 2 (logand 2 old_undoctl))
) ~. a8 e4 j. W" @              (command "_.undo" "_control" "_one")
% ^# w! f4 A- @+ |. ?3 N; J            )
; o8 E* `  m0 |' d5 B5 y8 l          )& Y' C" k$ C) W5 s' b* N
          (if (equal 4 (logand 4 old_undoctl))
! ^) @0 q, n" v              (command "_.undo" "_auto" "_on")
! k3 j) U) |# \7 F" z              (command "_.undo" "_auto" "_off")
% {% X+ y! B  Y! }          )) w+ f* k8 w0 d3 n# R/ W) _2 m
        )
) }8 Z: d. e$ q; \! ^* e7 A      )1 h# h+ q# k; ?8 t5 ^
      (setq old_undoctl nil)
, ^4 D4 f9 ]' [! q      (setvar "CMDECHO" cmdecho)
0 {7 p4 h8 G$ k9 K. N- r1 _+ V3 _    )
* ]; g" ^9 ?  _1 [  )
: i$ {- p; `5 `9 O) X. ^' f* v); defun undo_restore  S* U3 M3 d- c* H8 q1 x' `

# c  o) e/ J8 ]+ j9 \8 I+ \;----------------------------------------------------------------------------2 I% ~0 k( M4 C, S. U$ B5 g
; Save variables
, o% L! m/ k+ V1 ?. P. e  o; r3 U2 H;----------------------------------------------------------------------------
; Y8 F- [/ N2 A(defun var_save (a): |( e3 B5 Y6 V" e% p* }
  (setq m_lst '())
% d7 x7 B  X& E' l2 U/ E  (repeat (length a). x* I- H7 B0 u- f
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))
' T9 ^9 R, }; Q5 x1 t- I    (setq a (cdr a))" q9 z- B  c* A+ E) s* H" u
  )
. J, C7 E% u  U$ d- K  k% `& K); defun var_save
- N! m; c( Y0 V  C% Y$ p# o! d$ M' H' B( G' X4 W9 |
;----------------------------------------------------------------------------( i3 u; d- h4 j+ g* m
; Set variables  H9 i- Q  s8 W" K" R
;----------------------------------------------------------------------------* h+ G" l# q7 K; c/ S& ^$ o5 f% B. j
(defun var_set (m_lst)) L: @2 h- ^! F
  (repeat (length m_lst)
: b( s9 A% p' R    (setvar (caar m_lst) (cadar m_lst))/ @3 [  z* @' K6 O3 a
    (setq m_lst (cdr m_lst))
5 F1 c8 _7 l/ v; V& y1 C  )  x& g  a" S9 @! r) A
); defun var_set
8 J- _$ d1 j5 x. f
  @: G: Z+ Z& p& T1 c: h/ Y;----------------------------------------------------------------------------
0 [9 h- H  ^& c' B. l; Restore variables, _* P9 m; o+ y! e- Q# m, e
;----------------------------------------------------------------------------$ I, G3 b& n) v) m
(defun var_restore ()2 o& L6 I8 Y& R8 T
  (repeat (length m_lst)( m4 u  z5 S* M
    (setvar (caar m_lst) (cadar m_lst))
( E. J9 o. z  i# {, T1 h    (setq m_lst (cdr m_lst))
# r% r6 K8 ~1 I! q' A; _  )
1 S/ V8 ^" n" L/ c! y1 d); defun var_restore/ @# S/ [0 R; A5 [& r/ q
6 N# {( b4 D+ b/ q
;----------------------------------------------------------------------------* ?) c$ \! o/ V, C0 @! a
; Initialize routine
) f8 y; B( |8 ]" H( }+ v4 e3 _;----------------------------------------------------------------------------
) t5 Z& g! c/ G- w! j(defun err_init(e_lst u_enable add_fun)
. w7 r7 t* p* S+ i7 n/ B. x- @  (if err_alive (err_restore))          ; To avoid nested call2 R( }3 G; U3 }8 |5 J) a" |
  (setq err_alive T)
  @, t1 k) d# ?7 O) I  (var_save e_lst)                      ; Save the modes' l+ W4 R( F# W1 M. G
  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status' n  a/ Y$ |( B/ r# s
  (setq err_old *error* *error* err_main) ; Save the handle of *error*" c( x! _* N$ G+ b: K; P
  (if add_fun                           ; Add the user cleaner4 W& p* a; i+ a- f( R/ D0 ]9 W
    (setq *error* (append (reverse (cdr (reverse *error*)))
: {' ~: J1 _2 i( W- |8 v4 p: T                          (list add_fun (last *error*))& \/ W: B0 r, Y! A7 r) F
                  ); append
0 Y3 Q1 Y: q) _: w0 m: a    )6 R9 V2 y+ T( t) g) h
  )
) T8 w: K9 t4 y% S/ z5 |) [); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
2 h. X+ \8 w: D; Error routine body3 h: _/ J, e& g8 V- j
;----------------------------------------------------------------------------8 Y# G& `$ \" J' ?  D5 l1 H
(defun err_main( msg / )                ; Body of error routine
) _- p* @$ H4 B/ d  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs& j8 w! D. L; |$ m; v. v
    (princ (strcat "\nError: " s))      ;while this command is active...' x% `4 \- v! Y& q/ ~8 ^
  )
; p) c/ P" u; [' J9 q  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command; N7 X. E: q, d+ ~' V
# x: g. U6 \( t$ _
  (if old_undoctl6 w5 C3 j- C0 q( O. K% o& d8 [( A4 ]/ `
    (progn
6 c: X& p( E5 b: s1 a, r1 u      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See& k2 u2 r$ ?" P
        (command "_.undo")              ; if it's in UNOD command  {* F7 r  E/ r- s; J
      )
4 d% W. G& b0 ]# d      (command "_end")! F- @* z7 J+ e2 v
      (command "_.undo" "1")
( |8 Z( _) y) s( ]0 \/ c; V% t      (while (not (equal (getvar "CMDNAMES") "")) (command nil))- K* ?( b% p4 g% m/ A: @" d/ i
      (undo_restore)                    ; Restore the status of UNDO  Z/ X2 k) m4 I* v3 D+ {7 \: a! X
    )! z' @- N" C, S
  )0 _: ?( Z( D. Q( K
9 E+ C& Q5 P. T! ]2 r: m, l% D
  (var_restore)                         ; Restore the variables' ^( _. [& _5 b9 E0 F3 T
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error- l- }( l* \8 s5 r. |
  (setq err_alive nil)
; |& `" f  F; V# S! S3 B2 I  (princ)
! {5 j- ]: H& ^); defun err_main
& y% H: v9 c* [9 [7 e  p1 @
3 E& b# r# j. j7 _* g, G;----------------------------------------------------------------------------$ Y; a8 y# G  l( j, }- D
; Restore error status
2 U, K3 i$ w/ ~. t. t; Z6 ^;----------------------------------------------------------------------------
" M; {% A; v# i5 H, p  m. L9 r0 s1 X(defun err_restore()
% }" i; \) I( g  (undo_restore)                        ; Restore the status of UNDO6 D! K: E' o; t
  (var_restore)                         ; Restore the variables
" ]; G0 L  p: Y& x  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error
1 P; ?% {  @, P! h" x& \  (setq err_alive nil)0 V! g; I( Z, L- c# m: W
  (princ): ]3 v: Q. Z8 r
); 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 13:02

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

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

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