CAD设计论坛

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

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

[复制链接]
发表于 2007-3-12 15:01 | 显示全部楼层 |阅读模式
最近在用2007,发现自己添加的个别小应用程序出现了问题,无法使用,具体操作过程如下:
- _& G4 }+ `6 h- x5 }- ?1 W “工具”----“加载应用程序”-+--“添加CLOUD.LSP和UNDO.LSP”
- o& @% S% d' y" [提示:加载成功9 C( \5 q1 I( _4 V) j( v5 I1 ?, k. _
然后使用CLOUD命令,5 Z3 W- _8 w- P
提示“命令: cloud ; 错误: *error* 函数中出错参数类型错误: stringp nil”
5 o! Z2 K, `! Y% Z请高手指点一下,这个是怎么回事?应该怎么改正?" z0 p% Y& j: I7 o. v
这个小程序我在低版本也在使用,程序应该没有问题的,为何这里用不起了?
发表于 2007-3-12 15:09 | 显示全部楼层
你确认原来可以在2007版本下使用?将你的程序帖一下看看
 楼主| 发表于 2007-3-13 08:30 | 显示全部楼层

cloud.lsp

;;;  CLOUD.LSP made by xx
6 q% M) ]" H1 @. Q/ H3 t;;;- U% P6 Z$ M; k- U7 w; ]4 e* e
;;;  DESCRIPTION6 A6 S  Q9 B; R/ F
;;;     Draw cloud and you can specify the globals variables listed below
4 e1 T" J* Y' D& c;;;     to decide the characters of cloud$ u7 ?4 g% x7 o' V9 L2 l# A
;;;
( W8 t% N8 F0 A;;;  DATE: 02/18/98; 07/03/98; 07/06/98; 10/19/98; 12/11/98/ G# I% r4 P" d4 C8 m
;;;
# ~) i" K8 W1 I. l8 f;;;  HISTORY: Change CLOUD.000 in order to solve the problem of speed
& o$ U7 l0 ]% t! v;;;           Change CLOUD.001 to use CLAYER to perform the same function1 c! U2 V, i+ e& P! o& @
;;;           Use the common error routine UNDO.LSP to optimize this program
5 k9 }" z1 H# U;;;           Use the layer routine LAYCHK to solve the problem of LOCKING & FREEZE. h* U, v% S+ B; U0 G8 ~( b
;----------------------------------------------------------------------------8 K  ^. R% O: r+ J
;  GLOBALS:4 M7 ]* |+ ?1 ?# r0 R
;     cloud_layer -- layer of cloud8 r! F0 O5 z) B0 ~1 p  \
;     cloud_scale -- scale of cloud4 u- ]- ^0 p( \7 ~3 ^& s5 K$ [% i
;     number_rev  -- revision number
+ l( b5 B  F% \. m6 O: s6 _;----------------------------------------------------------------------------5 r# F  b/ S, S! C+ P9 t! T6 m
(defun cloud (/ locked temp first_point next_point relative_point0 D5 y! U" a& V# C1 z, \7 Y
               last_point point_tri point_ref corner_1st corner_2nd length_tri- O2 n  h6 ]# S* l' u+ o7 H# Z
               length_cloud angle_l_to_f dir_tri repeat_count
8 O; N9 A4 ]0 L+ U               table_cloud )! r9 m# u8 B6 |  D8 [9 U  b0 M
        (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))1 @4 C8 ^. w0 i8 @
          (progn (alert "Error:\n   Cannot find UNDO.LSP.") (exit))
3 w7 f) n( o# }        );if
  F8 Q! s& u  O8 y3 t        (err_init '("CMDECHO" "OSMODE" "ORTHOMODE" "PLINEWID" "BLIPMODE", r7 q' b% P+ S) c
                    "TEXTSTYLE" "CECOLOR" "CELTYPE" "CLAYER" "REGENMODE") T '(setq l_s nil)); z! K9 t% ~. R& q8 A4 u
        (var_set '(("CMDECHO" 0) ("PLINEWID" 0) ("OSMODE" 0) ("BLIPMODE" 0)
& h6 p+ v- k0 F& a  f! B                   ("CECOLOR" "3") ("CELTYPE" "CONTINUOUS") ("REGENMODE" 0)))- V5 U; Y6 i$ M0 \
) D% N# h& L6 ]
        (if (not (numberp cloud_scale)), {3 `4 L& L0 |; @5 k) b# @
            (setq cloud_scale (getvar "LTSCALE")); f9 Y) g. i5 e# [9 }6 G
        ); if# A5 ~0 |- _6 W) k
        (if (not cloud_layer)
1 A: |# T) c0 O. A6 A' G            (setq cloud_layer (getvar "CLAYER"))
7 {- t& A4 U5 P- k; P: k* {        ); if
: \' I3 \& L2 J8 C! y6 \! \* r        (prompt (strcat "\n默认图层:\"" cloud_layer "\"。" ))
" k2 A; _/ |3 Z; q. j/ g; f        (prompt (strcat "\n默认比例:\"" (rtos cloud_scale 2 2) "\"。"))
" b5 I5 G; b( X5 d$ R        (if (= (cdar (laychk cloud_layer)) "No")
9 k) w% v8 G, |8 h          (progn
: E& o; F6 O: b# [8 `            (laychk (setq cloud_layer (getvar "CLAYER")))8 g  X; x& e+ M8 J0 u5 K3 R
            (prompt (strcat "\n图层被设为当前层:\"" cloud_layer "\"。" ))
  k- x- {. k& G+ K2 x          ); progn
: E! d0 Q) P; T9 }1 S5 l        ); if7 a; t6 X+ `: u$ m7 u# \
# N9 z& N, I$ T: B4 O3 P
        (while (/= (type first_point) 'LIST)
6 G* H! J+ {6 ^          (initget 1 "Layer Scale")
& S& E6 S. a5 x' z' i% ~& _          (setq first_point (getpoint "\n图层 L / 比例 S / <起始点>:") last_point first_point)4 `- y  J# u+ a
          (if (= "Scale" first_point)      1 J  w0 [) @) |! M$ M6 Y
            (progn' N# e8 ?% L6 z- s
              (setq temp cloud_scale)
# O! ~  B8 x5 w- o( d+ O              (initget 6)
- C/ n: ~1 a- q: z: l5 Y+ v+ _1 A( @              (cond! X4 `& y% S, j0 h9 D
                ( (not (setq cloud_scale (getreal (strcat "\n请输入云彩的比例:<"
4 J: E6 n- F! L4 g( `                                                          (rtos cloud_scale 2 2)
1 u1 X3 P9 C8 h                                                          "> "))))$ @$ D$ @, t$ t  f
                  (setq cloud_scale temp) )
3 U- x* e6 X" y  I( \              ); cond! b6 [: g. w5 V9 G: ?8 b6 j
            ); progn
: p! T) z( M; N, C$ l4 @. [: _          ); if; O3 e* X  Q2 H2 ~2 D) ~
          (if (= "Layer" first_point)% B3 u9 s* B3 a6 `, k, v
            (progn: Z1 y8 s; f1 \8 x. B* Y5 z
              (setq temp cloud_layer)* q1 X  D% z" M0 n$ U
              (cond
: R8 B1 G) t7 S2 [1 T                ( (= (setq cloud_layer (getstring (strcat "\n请选择图层:<"
& m4 I. H- ?3 A+ \' x- F( A                                                          cloud_layer "> ")))
  ]3 @2 O+ A$ J/ ]4 ~' o                     "")' Z9 I3 V' ]5 @( X: F: H1 g& y
                  (setq cloud_layer temp)$ I- }% J0 M+ A
                )) a% A3 d7 c- z  J
              ); cond- m  b+ }. T4 @+ H
              (if (= (cdar (laychk cloud_layer )) "No")
- n7 G. G/ B, g/ ~                (progn
% A, v: A$ ?) m# S, C, K                  (setq cloud_layer temp)
1 y! `. A! G0 P5 C  f! ~4 [) \                  (prompt (strcat "\n图层仍为:\"" cloud_layer "\"." ))
8 l) Q& N6 ^0 Q% P' ?6 |0 ~                ); progn
  L) N9 h" V6 x  J& Z              ); if2 R9 a; p3 a: J8 o
            ); progn
1 [9 X; o4 U3 U! d7 Q. o. z) P          ); if
( S  [) Q3 x& {  R5 c4 d        ); while
8 \+ E$ q3 l! J$ g. x; J: Y, _        (setvar "CLAYER" cloud_layer)
# f, p, ^. \' f6 l- }! S  ]: K. }0 a
        (if (>= ( getvar "LUNITS") 3)" k. _# G/ e9 J. b  y4 M8 R8 S
          (setq length_cloud (* 0.25 cloud_scale)0 r( ~3 [4 F; l- s, v2 x3 S
                length_tri (* 0.3125 (getvar "LTSCALE")))- i$ t+ e+ S- M& D, {3 r1 H
          (setq length_cloud (* 0.3406890 cloud_scale); b2 L6 W( c: z( N6 I/ p
                length_tri (* 0.438366 (getvar "LTSCALE")))
) _8 U, u# L$ R' M" W) K5 i' j        )
- R( u) ]# ?4 h1 }1 z* ^        (command "_.PLINE" first_point "A")1 P3 t) r. S& m* P: a: I
        (while (not (equal next_point first_point 0.000001))
$ L) U: o, }, H! N: X          (initget  "Close")
5 ~4 s# P' A0 j0 [) n! s4 Z  z          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))
5 a3 G$ N# }: T. y* a) D        (while (and (not (listp next_point)) (/= next_point "Close"))
& B4 W9 n+ ^& \% U          (initget  "Close")8 |7 B+ z" B- V
          (setq next_point (getpoint last_point "\n关闭 C / <下一点>:"))+ I9 Q+ E( F( p; Y1 D
        )
/ t! q; W' u' y2 I% f          (if (= "Close" next_point) (setq next_point first_point))
6 D& p, M) y2 Q: N) }5 `          (setq angle_l_to_f (angtos (angle last_point next_point))8 H  T' M; `6 v8 [; s3 ^
                relative_point (strcat "@" (rtos length_cloud) "<" angle_l_to_f))7 E3 \, M* o  A- l  o. O, k6 D
          (if (< (setq repeat_count (/ (distance last_point next_point) length_cloud)) 1)
* G  O7 g7 R% s             (setq repeat_count 0)& b6 v  ^8 g; C! `, W
             (if (>= (- repeat_count (fix repeat_count)) 0.5)
' f  d& l% K$ T9 o               (setq repeat_count (fix repeat_count))
# P0 d/ U, j1 D               (setq repeat_count (1- (fix repeat_count)))( g; K% x* D+ E' l/ W
             ); if
6 c9 d3 u& t; m0 Y3 m6 S: W; |          ); if  P7 s' `7 V; ^: x' k' D* C. `* e
          (repeat repeat_count (command "A" "-100" relative_point))
- d( b" f; }$ ~' G+ {          (command "A" "-100" next_point)1 S, z0 e2 |6 h
          (setq last_point next_point)
4 X* v$ C! i8 b3 [4 R1 B7 D        )
" `+ f9 l, k% C. i        (command "")$ \  @) K- l/ N
        (if (= (type number_rev) 'INT)
' w, w( w- M8 k: y           (prompt (strcat "\n默认的版本号:\"" (itoa number_rev) "\"。"))8 J9 u6 m  F0 E1 t9 o
           (progn
5 t0 E$ {. G9 a: q4 n             (initget 5)* D; _9 H. ]2 Y% x" `5 k% K/ A
             (setq number_rev (getint "\n请输入版本号:"))
2 B5 m% D+ j% u* _. \) c           )* y5 o7 ]7 S: @# v  T
        ); if% I( A+ N/ L1 A* K
        (setvar "OSMODE" 512)
& Q/ l7 K, x5 l( v6 G1 I( g. V        (while (/= (type point_tri) 'LIST)/ e7 m- S' m3 l5 s
          (initget "Number")7 ~8 S$ B/ ?# `! P
          (setq point_tri (getpoint "\n版本号 N / <选择弧上一点>:"))
+ ^' ~; }5 T1 g9 D9 o1 ~7 J          (if (= point_tri "Number")
/ r$ s9 Z% P9 Z; \) h4 N2 h              (progn  J; @1 ~: J1 P9 j% l: A8 B
                (initget 4)
$ l0 B3 x: n8 S) p                (cond
6 T! b" X, `  Q# I0 Z                  ( (not (setq temp number_rev   _# s5 k" K& @3 u+ c6 o  {
                               number_rev
7 O+ b  M. N8 ~1 g' t4 O                      (getint (strcat "\n请输入版本号:<" (itoa number_rev) "> "))))* U8 K$ U- @* D9 k
                    (setq number_rev temp)
$ s9 H8 O  {$ R& B2 h8 q! s* n1 R& D, _                  )6 j6 |+ \1 K9 \: }4 C
                ); cond
' y4 r  F1 d0 B, N1 g& {              ); progn; ?  r# ^1 L3 ^: n8 E
          ); if
, b  M  c# ~3 G        ); while2 `3 ]; v" L* N
        (setvar "OSMODE" 0), ^4 c$ h* V( m' W$ @6 j4 A
        (initget 1)
* y% E/ K- B2 u! [4 l        (setq point_ref (getpoint point_tri "\n请选择方向:"))- t3 t1 @5 O' c$ I& `0 }7 R% P) Z
        (setq dir_tri (if (> (cos (angle point_ref point_tri)) 0) -1 1))2 O3 w* Z* r7 I1 w, a7 c
        (setq corner_1st (polar point_tri
7 T4 u5 g0 y% i# y! z  D                                (+ 1.570796327 (* -1.570796327 dir_tri))- Z# R+ e3 B+ Q2 W9 q1 a
                                length_tri. c( o0 p" Y' \! k  h, D
                         )1 q! B* M( A3 \0 o. n
        )* M' g: q( e! B: X
        (setq corner_2nd (polar point_tri
8 ]6 f0 v( x6 F! ?                                (+ 1.570796327 (* -0.523598775 dir_tri))
/ {" o+ h4 X9 F: I3 j                                length_tri- M: q3 m* y9 S: q" B
                         )) G* S& g5 o1 W: @5 @' L4 N! T
        ): m/ @9 I: }8 N6 G7 Q
        (setvar "CECOLOR" "2")
, k, ]; U8 v8 q: _        (command "_.pline" point_tri corner_1st corner_2nd "c" )/ v7 Y% V4 A6 a3 ]
        (setq textstyle (getvar "TEXTSTYLE"))2 N* z% N- Z6 v0 R: j
        (command "_.style" "stdtext" "simplex" "0" "1.0" "0" "n" "n" "n")
' O; h1 f# S1 K        (setvar "CECOLOR" "7"), Z: ^; v% m* f
        (command "_.text" "j" "mc" (polar corner_2nd 4.71238898 (* 0.576 length_tri))
$ Y% M) d+ E8 U7 y+ J                  (* 0.4 length_tri) "0" (itoa number_rev))/ M( T3 E! q( l4 b* D' m2 l, }
        (layres)
! r3 i* H9 r- {4 @" }* J2 J* N7 k9 W( }        (err_restore)
* F/ q" }! e+ A3 n, a  r( g: L/ U! g        (princ)
8 O# m$ x% P9 m! _' w4 I4 j); defun cloud
7 P& x. Y6 F. D, Z5 ?! ]# m! s
(defun c:cloud () (cloud))
+ D) T; y* q% a& P; W(defun c:cd () (cloud))
 楼主| 发表于 2007-3-13 08:33 | 显示全部楼层

undo.lsp

;;;  UNDO.LSP made by piggy0 M" H5 G) n! A+ s( ]
;;;3 h6 k( j! F8 K# @0 q
;;;  DESCRIPTION
# X% V- g) W5 V;;;     These are general error routines which can be called by $ X% R$ Q" x( p* y
;;;     other routine. See AutoCAD 14 ac_bonus.lsp for reference
- u; O) O' U' y5 ^# N( n) l;;;
# r1 m! J7 T% K6 E& D2 `;;;  SUBROUTINE INCLUDED IN THIS FILE! o. A9 h1 r4 H+ ^3 V) d% D
;;;     UNDO_INIT
5 V$ L/ o1 z* w- q: ~2 |;;;     UNDO_RESTORE4 h! y; c8 P' |5 b, J6 u4 k' q$ \
;;;     VAR_SAVE
- q. X) W; J0 B8 [3 h7 J;;;     VAR_SET  
3 I% ]% v& b6 R9 Y: q  i( i;;;     VAR_RESTORE9 w8 T5 h6 V5 P9 n" [
;;;     ERR_INIT
1 ^, ~) ?+ d4 I2 x9 v;;;     ERR_MAIN 6 X4 R4 z; H3 q' L
;;;     ERR_RESTORE! G# t' ~$ w7 {, M! @3 a
;;;
, Y1 C6 D0 _: o+ Z! m7 w  D;;;  DATE: 10/17/98; 03/31/99. d1 P1 P6 ~" h" @* z* M& R! L
;;;( C# r* K* Q/ E! @" t, ^5 z
;;;  HISTORY: ; D0 H/ r$ y" A3 Z7 F8 S
;;;    Add routine of mod_att* ^' [: ~9 }% @8 ^% @
;;;
1 X( r4 y1 h$ F1 R5 o& [: \;;;  USING METHOD8 A5 y+ }8 p4 y' K( w4 x
;;;    ERR_INIT:
: e+ H! W( X$ u, Y;;;      This routine initialzes the error handler. It should be called as:
! n( u4 B" Z5 e' u; K4 p;;;
2 Y' u7 f' {7 ]/ m9 A  v;;;      (if (and (not undo_init)8 n, S  g$ x- [4 ~( I2 _; I' T
;;;               (equal -1 (load "undo.lsp"  -1)) - g- n0 E) T2 F9 i' A  B: c
;;;          );and1 e; {4 W" n- E* C
;;;        (progn (alert "Error:\n     Cannot find UNDO.LSP.")(exit))& }7 i: R4 l% \! ]7 r! V& l$ s
;;;      ); if2 J/ I; s: w( I3 Z' U; n
;;;
$ c. C0 ^5 m8 {) C# f7 [% x/ H;;;     ARGUMENTS:
: c8 v  d7 }; T0 Z- H1 j+ E1 d+ i;;;       err_init Takes 3 arguments.
8 B& F/ y8 l2 E5 `1 i3 c$ e5 i. U;;;     1. - The first element of the argument:
1 W. I, X6 N0 ]$ y. X; w;;;          This is a list of system variables paired with
/ e# @. p2 {( o8 [;;;          the values you want to set them to. i.e. '("CMDECHO" "ATTMODE")
, A. W) J* q- E4 `;;;     2. - The second element is a flag7 H: G5 y! k+ Y
;;;          If it is true, then in the event of an error # R$ }# q: B0 J9 l4 J9 I* z( Q% M4 T
;;;          the custom *error* routine will utilize UNDO 3 A1 c4 w- t# w( d! S
;;;          as a cleanup mechanism.
/ O% V% _  p/ V;;;     3. - The third element is a quoted function call.+ R7 V; P6 {5 b# F7 H
;;;          You pass a quoted call to the function you
* |! b7 y2 z5 |+ o;;;          wish to execute at the end of nomal routine if an error occurs.
, P' G4 e4 j# l* ]0 c/ L! E4 p8 u6 Z;;;          i.e. '(my_special_stuff arg1 arg2...)8 w6 j8 k* v+ r! ]1 P6 O
;;;          Use this arg if you want to do some specialized clean up ( f. Y2 |6 y' U
;;;          things that are not already done by the standard bonus_error
2 |0 f6 X, \1 O  V/ I4 j;;;          function.
. c) o9 [5 c7 `. _, v& m- ]8 w;;;) b" [) x% x( z' F! H
;;;    ERR_MAIN: Body of error routine! G+ w$ M, `; U
;;;
" `+ Z, S( h2 p0 g3 g7 B7 U) x5 f;;;    ERR_RESTORE: This routine should be called at the end of command to: _: @& B7 _" Q2 X
;;;           restore the VARIABLES, UNDO & *error*.
! X" B( |& _( U+ J* a- J;;;
  I7 l  m. u# S9 A& l& v- K; W7 k;;;    UNDO_INIT: Initialize the UNDO status8 i6 L  E3 Z3 T/ X. ]9 i7 C
;;;% s2 |$ O# T% b& M6 n3 H
;;;    UNDO_RESTORE: Restore the UNDO status
- K2 H& y4 K7 f2 j$ R- };;;
7 \% y" d$ j+ C& \3 ~;;;    VAR_SAVE: Save the variables. the argument is like '("CMDECHO" "ATTMODE")( t$ G( c2 e) Y, v% f* V
;;;- X2 N' C; J# W
;;;    UNDO_set: Set the variables. the argument is like6 C  x" u) @# S) m2 O' |$ _
;;;              '(("CMDECHO" 0) ( "ATTMODE" 0))% I, t% _4 P/ ~: r$ f
;;;
9 O4 N& ~) T# G;;;    UNDO_RESTORE: Restore the variables' E/ |6 X3 d# \5 B- F% v
;;;- e) u; i5 K9 s, E; H0 j. S
;----------------------------------------------------------------------------: J' B: r* ]2 |5 w2 g3 Q& a7 v
;  GLOBALS:$ F, Q- V1 m, ]  Q5 G
;     old_undoctl -- old status of UNDO (voided by UNDO_RESTORE)6 Y' ]  o( s) h) p$ v: ]. {
;     m_lst       -- list of variables (voided by VAR_RESTORE)
% i+ v9 g3 h3 Q0 P0 [;     err_alive   -- indicate error routine is active (voided by ERR_MAIN or) C( O% `8 T; d5 }1 r7 K+ n
;                    ERR_OLD)
6 l7 T. Z3 u4 d' C;     err_old     -- old handler of *error* (voided by ERR_MAIN or ERR_OLD)
* A& i$ r4 V. X;----------------------------------------------------------------------------* l% q& j7 }$ P1 P  Z

- ]1 @' i% f1 k& q2 H;----------------------------------------------------------------------------. [) }0 d/ `0 x- R
; Modify attributes according to entity name, attribute name, dxf_item  O$ f/ X! n+ y9 X. {2 W
;----------------------------------------------------------------------------1 K& Q4 U+ y/ a: B* C
(defun mod_att(ent id dxf_item)        
( C0 w1 b0 t* K5 k# e  (while (and (/= "ATTRIB" (car (entgetf '(0) ent))) (/= id (car (entgetf '(2) ent))))
0 b- {) [/ M% }+ G+ P    (setq ent (entnext ent))& D2 m! ~* X! C9 E6 u
  ); while  1 y' Z! V; p, T! k0 i3 j
  ((lambda (x)2 w" x9 d4 R8 d' E$ \( t; X! B% E
        (mapcar '(lambda (y)
1 o! X% M0 ]0 V" U6 W1 ~                   (setq x (subst y (assoc (car y) x) x))
, f) j1 e0 Q% P9 q  n  e                 ); lambda) @+ e& m" Z, ?1 d/ m
                 dxf_item8 s) n. l: @- m; s2 ?
        ); mapcar
, [6 P, l' h5 Z* }5 U# P% y7 ~     (entmod x)
- K  |1 e# d# L3 i9 h     (entupd ent)# p9 S* p4 V( [4 k8 ?
   ); lambda
. W2 I+ h$ [# u7 o: h   (entget ent)1 r& x3 g8 c+ ^) \: r6 f
)
! W3 x/ x) t' W; e$ v); defun mod_att
; L7 c+ n! E4 k3 |! ^, f  J. k1 h" U% n/ f+ [
;----------------------------------------------------------------------------6 f! S  ?0 i+ V# {% C, n
; Check layer status, return a association list which contains layer information2 d! q+ N7 k7 _! s
;----------------------------------------------------------------------------8 b: E$ f. E* ~6 d& b" N6 I
(defun laychk(lay / l_sta)
$ R! Z/ _0 F; ^/ K. Z4 X2 I  ( (lambda (x); M- Y3 ~/ l3 y* N
      (if (not l_s)# D6 o# c" c' o! K% p2 S+ i
          (setq l_s (list (cons x (logand 5 (cdr (assoc 70 (tblsearch "LAYER" x)))))))
2 Q* T. t2 K. O* t! e& F" t      ); if! P4 p) g$ `0 I
    ); lambda % w5 G6 F1 Y, ?, F: d
    (getvar "CLAYER"). f6 z5 u% @( o) J) p; z
  )
- W6 ]8 b& e3 E0 g( ?. c" r4 E  (if (not (tblsearch "LAYER" lay))
1 b% z) j7 F9 E) _5 w+ a8 b    (progn  + A. I6 k6 D2 W( e2 u0 o! s
      (initget "Yes No")
- m4 G& k8 f) }* j0 E# B0 y' x      (if (= (setq l_sta (getkword "\n图层不存在,是否建立该图层 ?\(Y/N\)")) "Yes")
" T0 G; ^! m# u% D        (progn0 Y0 j$ ^! x* H. F3 k" r! T
          (command "_.layer" "n" lay "")
  @$ z0 Q( e6 f$ X2 E' H  O          (setq l_sta 0), l; ]4 x1 ^6 Y9 @' V7 F
        ); progn* _) v- U+ M3 z; R/ R  Q: s, P
      ); if% b4 x# l% r' a
    ); progn9 f! a5 M3 y) k% W6 P, F7 F
    (progn9 C2 G1 M" i/ S! D
      (setq l_sta (logand 5 (cdr (assoc 70 (tblsearch "LAYER" lay)))))3 T; V* h- N% ~
      (if (= 1 (logand 1 l_sta))
. s, ]% f- q: g- E& \1 [          (progn3 z8 f: F- \; m1 D6 \4 y* E& [
            (initget "Yes No")$ O6 Z/ J( g1 q' x' W' O1 }" n0 e
            (if (= (getkword "\n该图层被冻结,是否解冻 ?\(Y/N\)") "Yes"); e9 n  W# E/ G- e- p9 v
              (command "_.layer" "t" lay "")2 L: s! T7 ]5 k# v* Y
              (setq l_sta "No")- G! W6 Z: X2 K' R/ ^
             ); if# i4 @& P  h) c. A; A
          ); progn
1 A1 I5 H7 n: P      ); if/ {- l- t$ l- |# s9 D
      (if (numberp l_sta) , X1 j9 @$ h+ r5 I5 K9 g; L8 V6 S. c
        (if (= 4 (logand 4 l_sta)) (command "_.layer" "u" lay "")); if
2 g" t4 X- \  N; N- D      ); if, Z3 j7 K5 }- ]! E
    ); progn
: r9 A) {1 L, l, u; {2 d7 [7 x5 v  ); if
& y# C3 `# Q3 q& A  ( (lambda (x)
8 x+ Z/ k* s6 `      (cond
$ @, o# ], [7 K! K9 W        ( (not x)
0 @- t' M) K  ~  @: F1 n          (setq l_s (cons (cons lay l_sta) l_s))! b$ V5 r4 \5 S0 Y
        )+ e/ z/ q5 P0 f6 U. o) P% |" m
        ( (= "No" (cdr x))
- K- ?  }2 i5 [" A          (setq l_s (subst (cons lay l_sta) x l_s))
/ A5 J) h- d$ {, O. s1 Y/ u. h% ?7 v        )
7 T' n' j  S' g7 K        ( T l_s)* J8 {  p* ^2 V
      ); cond
' o3 P8 ~5 R6 t7 Y9 C     ); lambda
7 A; {. k" }1 N$ }8 T, D     (assoc lay l_s)- R8 d9 g7 v# h% t
  )* [5 z+ a) [( ?9 ?5 ^% P: H9 r* g
9 i8 I/ U9 [% t5 t- g3 t! Q7 s
); defun chklay+ D$ Q: E1 n8 C9 z

7 p" _: y1 I, o+ M;----------------------------------------------------------------------------5 b$ n# ?' \- q5 U1 `
; Restore layer status according to association list l_s# q6 t# e; c1 c* j
;----------------------------------------------------------------------------
6 t4 W' i" H) o6 p6 E9 z9 l(defun layres()8 W4 [- [- `( c! q$ V% s
  (setvar "CLAYER" (car (last l_s)))
0 ~! G) j- x. n7 u+ ^+ Q  (repeat (length l_s): }( ?. L' K- k1 M
    ( (lambda(x)  
! `+ R1 J2 G# s5 @( \. E7 }- ^        (if (numberp (cdr x))
  g' q7 i$ X5 ^4 W; @          (progn % ~$ J. H$ D4 H% y9 D3 M" l: ]4 q
            (if (= 4 (logand 4 (cdr x)))
0 q3 U. }% r6 `+ l. \4 U; V! d" U$ Z              (command "_.layer" "lo" (car x) "")/ b+ M$ y8 Q7 x, m7 p( a
            ); if, d3 p5 s3 v9 b* Z
            (if (= 1 (logand 1 (cdr x)))# z/ s2 h) a' R# [2 w( U9 @
              (command "_.layer" "f" (car x) "")
9 k# i4 S" a% G            ); if
" p( O7 m; `+ F  ~! Y          ); progn% n, M$ W9 b$ \* d+ M) t' S1 T" @
       ); if  
5 G5 q; f2 v& ?7 ?  J* I+ G* }# Y7 q      ); lambda
! K+ _  |" R' b0 b/ ^1 k, k      (car l_s)9 X4 T; r: F  k
    )* H8 D  ]# O8 [7 R7 C+ m# S9 l
    (setq l_s (cdr l_s))# i( X/ _+ M2 c6 T- [/ {
  ); repeat
. r; m4 M/ T! |5 p); layres
, g2 {: Q4 `' E, A- V2 }5 Y( t4 c3 S& T
;----------------------------------------------------------------------------
7 Q& D2 P, j( H) C; Get DXF codes+ Q3 b; D4 h" l
;----------------------------------------------------------------------------
( y) Z5 A: r" q! k8 f' `6 }(defun entgetf (index ent)0 W( S' l$ ]- x% S9 r# ^& P
  ((lambda (e)
3 ^5 x* t$ [2 {3 ~( |4 S8 I3 O      (mapcar '(lambda (x)
" c6 m. B; d2 O7 k! u                 (cdr (assoc x e))3 K2 a4 N( |0 P$ H
               ); lambda( p8 ]) ]4 @; L# s; J
               index) ; internal lambda function8 f4 m. S0 N6 q  }2 g; p) q8 j
    ); lambda
) N0 B0 I' y7 O! F# o    (entget ent) 9 O: z' ?6 f" h
  )# E6 d$ n: U9 \2 s- B5 x) L
); defun entgetf& V; W( _* }6 K, N4 e! e# D
+ Z. b7 ]  I6 n1 E. f
;----------------------------------------------------------------------------- O/ f9 [) R7 u! V$ n
; Save UNDO status
2 |; `/ F" I: i$ p. {! R;----------------------------------------------------------------------------5 Y) H3 z! Z; `3 z
(defun undo_init (/ cmdecho undo_ctl)   
* M. ]( e: K# v+ k! X. J9 A1 B  (setq cmdecho (getvar "CMDECHO") undo_ctl (getvar "UNDOCTL")) ; Save the value$ l% f- r, I. }  d$ f* Q9 `
  (setvar "CMDECHO" 0)3 p" Y# _# P6 A
4 }& d5 X2 y" [( q, ]
  (if (equal 0 undo_ctl)                ; Make sure undo is fully enable
: A4 ]: p' G3 O  H" V5 E1 \    (command "_.undo" "_all")7 B" X+ v3 `% O5 ~* B1 R
    (command "_.undo" "_control" "_all")
1 J! N/ x& {" s6 G. w6 }7 E  )( ?. z" C# ^5 d% C7 H7 k- @

( G" F6 z/ o, Q/ R# v  (if (equal 4 (logand 4 (getvar "UNDOCTL")))   ; Ensure undo auto is off
) F1 r( q8 }% M# f  h( M  C    (command "_.undo" "_auto" "_off")! _+ w) E2 e8 B9 n: g( d& u
  )
( y0 X( C1 ], Y! D
. p6 I/ S# O5 P% P6 W  ^( G/ C7 ^  (while (equal 8 (logand 8 (getvar "UNDOCTL"))) ; Place an end mark here
' T$ c! @4 ?3 q    (command "_.undo" "_end")' w+ ]4 a) d5 _* ]1 c
  )  P1 a, n7 B* }1 b1 I2 \; N8 Z+ d

6 `# ^2 _+ h" c- q. a  q/ s2 h  (while (not (equal 8 (logand 8 (getvar "UNDOCTL"))))
. W0 t5 E2 C! S5 Y; J6 H! L# n( ?    (command "_.undo" "_group")
; I# |! k8 N' l# P  )
9 A  ?# J* h+ q" i. j+ x# K$ A  y. ~
, X/ o. r5 |) h* q) r' T  (setvar "CMDECHO" cmdecho)3 U, i+ P1 `3 t- ?# b
  undo_ctl
1 W4 r( |2 J% l2 d* c0 F); defun undo_init2 J( ?1 W2 H; ]  h) N9 K  n" b! j

" |1 [% D. b2 c5 h( R;----------------------------------------------------------------------------
0 W: F2 K8 [; M$ B3 h7 s: v4 k; Restore UNDO status
4 G/ f" _$ p1 d  K$ j! V;----------------------------------------------------------------------------
, }% z9 E6 h5 S/ N3 a( J; E(defun undo_restore (/ cmdecho)
. _) s0 _# ]' Z% G3 R& o  (if old_undoctl
4 ~8 e. ^4 L6 _7 b    (progn
8 u* W$ Y2 N7 |) b* y' R      (setq cmdecho (getvar "CMDECHO"))
0 V' U8 U0 [9 {7 A" i* k' ^      (setvar "CMDECHO" 0)# H7 m3 _* I/ n9 O$ [/ |8 S* j

# T" X& J% e( O$ j; ?9 f. w2 T      (if (equal 0 (getvar "UNDOCTL")) (command "_.undo" "_all"))
" r* D; a0 |& i6 z      (while (equal 8 (logand 8 (getvar "UNDOCTL")))
/ b; z5 E; i  ?  W        (command "_.undo" "_end")9 p1 t! s  G. O8 _! Q' W+ X& S: E
      ); while4 Q  F/ V( q" \7 L$ N
9 A8 b! `: S4 L, B5 R1 ~" C: W
+ @( s+ X% k1 P3 ~5 i4 E
      (if (not (equal old_undoctl (getvar "UNDOCTL")))
+ q9 e& v7 ?  a! `: S9 Y, q* h        (progn
, D3 B5 }) v' l- C7 U8 n& ?6 {          (cond4 n, Y: m) h- A7 C
            ((equal 0 old_undoctl)
- _4 @, N4 ^! [+ y3 {; _# }              (command "_.undo" "_control" "_none")
( P+ ~: I9 w1 ?7 M; {2 [0 l. p+ L            ). e; M# n- V5 t/ p+ {
            ((equal 2 (logand 2 old_undoctl))
0 F5 |8 Q9 v) T0 T  N9 n              (command "_.undo" "_control" "_one")
" n. l7 ^; D, o+ H) S  r3 u            ). r' n0 R) f$ |% |4 Y  d7 F- Z
          )
0 l! g. _+ t6 L2 Y# \  C          (if (equal 4 (logand 4 old_undoctl))
! H- U- c/ L. `; ]8 ~              (command "_.undo" "_auto" "_on")
1 F* n9 J# [0 O3 b( P              (command "_.undo" "_auto" "_off")4 u( S( L/ V8 L9 d5 e  e# K
          )5 y4 ?# @& A8 Y+ T, ?7 n5 h
        )6 `( ^. E& M6 G' W4 y" |7 R
      )
! ^6 A! Z9 n# g* S% g: W      (setq old_undoctl nil)5 p5 l  v0 Y5 A2 U5 L* ~
      (setvar "CMDECHO" cmdecho)8 K) r/ l0 t1 x. E6 o* Q
    )
" w8 k" f5 R* [$ `9 `) v  )  _4 r- j( k- D) L  `# j
); defun undo_restore
2 S8 w7 {: I* j+ o& j: c4 }) z, \+ r( y/ X/ w6 }! a2 ?
;----------------------------------------------------------------------------+ t7 l9 S+ k% o/ D/ n1 G$ H
; Save variables1 j/ v2 P+ u1 J  I: Y# [) r2 z
;----------------------------------------------------------------------------0 L( u4 J4 f6 C
(defun var_save (a)
% M& L8 ], i7 z5 o; e  (setq m_lst '())
- D9 ?: L. l& V0 A9 ?5 X: E  (repeat (length a)! _) f5 Y2 X6 z7 l
    (setq m_lst (append m_lst (list (list (car a) (getvar (car a))))))) j( ^& Z: f$ f" e7 x$ g
    (setq a (cdr a))
0 ~$ B5 x, ^3 H& [2 L+ e  )& G1 E. f7 |7 L1 w/ i* b
); defun var_save
2 @% p; E' M2 t8 E7 g0 f( v, r  l# ~' F3 M+ g) ]! V& A  L
;----------------------------------------------------------------------------, ^$ K4 S: G; r% B% O, U  W, \
; Set variables
" Z& ^( i) X9 j;----------------------------------------------------------------------------8 _* f* s" p1 F6 v! m: a
(defun var_set (m_lst). }+ B0 I9 a9 `1 }4 d
  (repeat (length m_lst)' Z8 P4 t9 `" i/ J) m' J$ {0 D
    (setvar (caar m_lst) (cadar m_lst))
2 A) p: B7 Y7 v    (setq m_lst (cdr m_lst))
" ]# M% }5 B. X0 q: G0 g2 {9 b, d  )$ ~5 j  R( W; `
); defun var_set
, n1 c, t" C! Q/ X- [
* G& `2 S! W  W8 y;----------------------------------------------------------------------------4 `: N9 P8 S7 J3 O- ?
; Restore variables' k, I9 L. m% B5 m1 f: H: x2 x
;----------------------------------------------------------------------------
1 I" f0 k  z1 W% x$ d6 k* T(defun var_restore ()
! Q/ c2 C7 P5 o+ D. L4 o  (repeat (length m_lst), Q% {; X: w7 ]1 g
    (setvar (caar m_lst) (cadar m_lst))
* V2 L1 [  q+ [    (setq m_lst (cdr m_lst))
" U# d' A4 i1 M4 G- h% C  )5 {' {7 u/ R& W1 D" q* J5 f
); defun var_restore* V) A# h6 m" L. k7 o
& a' |  |3 v' B' t. S( X
;----------------------------------------------------------------------------
5 X9 n2 A5 Y. @0 c# O0 q: v; Initialize routine 1 @: H3 y& ~+ t+ W
;----------------------------------------------------------------------------
. B: X: p/ X6 a(defun err_init(e_lst u_enable add_fun)
% M2 M5 x- x1 g! H) w* Z* U  (if err_alive (err_restore))          ; To avoid nested call+ J5 I$ D8 |/ ^( y9 O
  (setq err_alive T)
" r2 v- H/ }6 G" @, }3 j  (var_save e_lst)                      ; Save the modes
4 u% m: b- A5 p5 V4 [8 x  (if u_enable (setq old_undoctl (undo_init))) ; Initialize UNDO status
$ n; z8 X9 O. p% Z( T  (setq err_old *error* *error* err_main) ; Save the handle of *error*7 d. o% ^+ R3 O$ f/ D% F
  (if add_fun                           ; Add the user cleaner( [6 E' Z& c) T+ B/ C
    (setq *error* (append (reverse (cdr (reverse *error*)))+ K# Q5 F0 l6 P4 q$ F2 Q
                          (list add_fun (last *error*))) M' \- c5 @: e3 d# s: i
                  ); append0 h$ `# b8 n& }
    )
- A) E8 g# V) g5 O5 X; m  ): a) o, b  C% W  N# p1 X
); defun err_init
 楼主| 发表于 2007-3-13 08:34 | 显示全部楼层

undo.lsp(续)

;----------------------------------------------------------------------------
2 @0 w" X/ r+ B; Error routine body
8 H+ O; V% P' H- @  l  b;----------------------------------------------------------------------------7 y$ a3 u- N6 w6 X4 }  ~5 {. f& }. E
(defun err_main( msg / )                ; Body of error routine5 T4 N' e7 S6 `2 D
  (if (/= msg "Function cancelled")     ;If an error (such as CTRL-C) occurs
' Q! o; M2 e1 X    (princ (strcat "\nError: " s))      ;while this command is active...
% X. O7 V$ W% b& z  )
* k' {5 x" |2 U/ L7 _" x  (while (not (equal (getvar "CMDNAMES") "")) (command nil)) ; Get out of any active command
' t5 p* }# _( M8 L
, e3 ?( @( d% l* e: p6 [" Z  (if old_undoctl* J4 ]9 n$ ~8 I4 t# ?6 }2 [
    (progn
9 j4 k/ f. k$ d  T8 c      (while (not (wcmatch (getvar "CMDNAMES") "*UNDO*")) ; See) Z6 w; }- h( u; Y
        (command "_.undo")              ; if it's in UNOD command, b# D& ?" e) Y  q
      )3 ]$ k6 b  j! W
      (command "_end")
4 q- c- B3 b" {% `* D* E% u$ e5 K( i      (command "_.undo" "1"), f$ `$ E) d/ t
      (while (not (equal (getvar "CMDNAMES") "")) (command nil))
/ o' G% |6 Q" `& j8 y# k# ]      (undo_restore)                    ; Restore the status of UNDO1 X- T$ A) v+ z4 U
    )% ]' b6 B) K! _  v+ [0 r
  )& N$ c) _5 w: o

4 \1 r9 A1 f8 w& E* T- @  (var_restore)                         ; Restore the variables
. k, @# d% z0 G4 r, P# U1 j# h7 i, l  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error% H3 k6 o3 m" V1 R$ o
  (setq err_alive nil)$ N0 X5 T$ t$ e5 I* G
  (princ)1 o( p* d5 C4 x% I4 T" p
); defun err_main. K: q6 n9 @6 f- J2 W; ]

' r8 q5 U0 z. _8 m, n;----------------------------------------------------------------------------
. q/ `; S  V+ p5 s, E4 q; Restore error status2 L. F$ A) Q- s0 ?* B
;----------------------------------------------------------------------------2 |' c" n, F/ j* \/ E$ u7 B5 [+ \
(defun err_restore()& G0 a9 S9 g( r. O
  (undo_restore)                        ; Restore the status of UNDO
, y) a. I& k  L& u- E( B9 M  (var_restore)                         ; Restore the variables% u% o( G+ |  U& D; W% @
  (if err_old (setq *error* err_old err_old nil)) ; Restore the handle of error; Q) B# x' r; _: g
  (setq err_alive nil)! n  L% l* c( A7 S% g2 u
  (princ)
& g! R3 U) E* R4 m5 L$ ^& A- H); 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-30 03:24

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

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

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