代码已修改并发布到该线程的第一个帖子。所有更改的详细信息以及保存为2000格式的样例图形已提供给您以测试代码。
享受这个节目,
秃鹰 Buzzard,我建议您看看代码中突出显示的部分,您有一个小错误
;///////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////
;/// ///
;/// Program: Attribute Value Rotate Lisp - AVR.lsp ///
;/// Date: July 03, 2009 ///
;/// Author:Angelo M. Bozzone aka The Buzzard ///
;/// Contact: The Buzzard at http://www.cadtutor.net/forum/index.php ///
;/// ///
;/// Program Description: Globally rotates block attributes with a ///
;/// specified tag by specifying an angle. ///
;/// ///
;/// Program Features: ///
;/// ///
;/// 1. Program has variable save, restore and error trapping. ///
;/// 2. Saves last entered attribute rotation angle for drawing ///
;/// session. ///
;/// ///
;/// ///
;/// Function Syntax: AVR ///
;/// ///
;///////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////
; Main Function - Attribute Value Rotate.
(defun C:AVR (/ ATROT INDEX ENAME ELIST SUCE SUAB SUAD) ;Define function, Declare local variables
(setq SUCE (getvar "cmdecho")) ;Save user cmdecho
(setq SUAB (getvar "angbase")) ;Save user angbase
(setq SUAD (getvar "angdir")) ;Save user angdir
(setq temperr *error*) ;Save error in variable temperr
(setq *error* AVR_ET) ;When error occurs goto Start Error Trap Function
(setvar "cmdecho"0) ;Turn off cmdecho
(setvar "angbase"0.000) ;Set variable angbase to 0 with respect to the current UCS
(setvar "angdir" 0) ;Set variable angdirto 0 Counterclockwise direction
(or A:ANG# (setq A:ANG# 0.0)) ;Set default attribute angle ~ (real)
(setq A:ANG$ (rtos A:ANG# 2 1)) ;Convert A:ANG# ~ (real) to A:ANG$ ~ (string) (setq A:ANG# ;Set attribute angle ~ (real)
(cond ;Conditional
((getreal (strcat "\nSpecify attribute angle < "A:ANG$" >:"))) ;Concatenate string, Get attribute angle, Display default ~ (string)
(T (setq A:ANG# A:ANG#)) ;Attribute angle default ~ (real)
) ;End cond
) ;End setq
(setq ATROT ;Set attribute rotation
(ssget "_x" ;Creates a selection set from the selected objects
(list ;Start list
(cons 0 "INSERT") ;Filter for insertion
(cons 66 1) ;Filter for attribute
) ;End list
) ;End selection set
) ;End setq
(if ;If the following returns true
(/= ATROT nil) ;Selected blocks are not found
(progn ;Then do the following
(setq INDEX 0) ;Set INDEX to 0
(repeat ;Evaluate expression a specified number of times and return the last
(sslength ATROT) ;Return number of entities in the selection set
(setq ENAME (ssname ATROT INDEX)) ;Return the entity name of the indexed element of the selection set
(setq ELIST (entget ENAME)) ;Retrieve list of entities data
(while ;Continue to evaluate expression till nil
(/= (cdr (assoc 0 ELIST)) "SEQEND") ;Look for assoc list element, 0 entity type, If not =, End sequence
(setq ELIST (entget ENAME)) ;Retrieve entity's data
(if ;If the following returns true
(= "TAP-VAL" (cdr (assoc 2 ELIST))) ;If attribute tag is found ~ (Change the attribute tag value here.)
(progn ;Then do the following
(entmod ;Modify the definition data of an object (entity)
(subst ;Then substitute
(cons 50 (AVR_DTR A:ANG#)) ;New attribute angle
(assoc 50 ELIST) ELIST ;Replace old attribute angle
) ;End subst
) ;End entmod
(entupd ENAME) ;Update the attribute
) ;End progn
) ;End if
(setq ENAME (entnext ENAME)) ;Get the next attribute
) ;End while
(setq INDEX (1+ INDEX)) ;Add one to INDEX
) ;End repeat
) ;End progn
(ALERT "\nNo blocks were not found.") ;Display ALERT if selected blocks are not found
) ;End if
(setq *error* temperr) ;Restore error
(setvar "cmdecho" SUCE) ;Restore saved user cmdecho
(setvar "angbase" SUAB) ;Restore saved user angbase
(setvar "angdir" SUAD) ;Restore saved user angdir
(princ) ;Exit quietly
) ;End define function
(princ "\nAttribute Value Rotate Lisp, AVR.lsp Loaded....") ;Print Expression to command line
(princ "\nType AVR to start program.") ;Print Expression to command line
;///////////////////////////////////////////////////////////////////////
; Conversion Function - Degrees to Radians.
(defun AVR_DTR (a) ;Define function
(* pi (/ a 180.0)) ;Calculate degrees to radians
) ;End of define function
;///////////////////////////////////////////////////////////////////////
; Error Trap Function.
(defun AVR_ET (ERRORMSG) ;Define function, ERRORMSG ~ (Error Message) is the argument
(command nil nil nil) ;When escape selected
(if ;If the following returns true
(not ;And does not evalute to nil
(member ERRORMSG ;Search list for an occurence of an expression
'("console break" "Function Cancelled") ;Start list
) ;End member
) ;End not
(princ (strcat "\nError:" ERRORMSG)) ;Concatenate string, Show the error message
) ;End if
(setvar "cmdecho" SUCE) ;Restore saved user cmdecho
(setvar "angbase" SUAB) ;Restore saved user angbase
(setvar "angdir" SUAD) ;Restore saved user angdir
(princ"\nAttention! An error has occurred!") ;Inform user there has been an error
(princ"\nProgram now restoring the user enviroment.") ;Inform user original enviorment is being restored
(terpri) ;Terminate print
(setq *error* temperr) ;Restore error
(princ) ;Exit quietly
) ;End of define function
(princ) ;Exit quietly
;///////////////////////////////////////////////////////////////////////
不确定,它似乎有效。
怎么了? 尝试绘制没有块的图形
我明白了,没有错误捕获。
我会努力的,谢谢。
李,
我只是在没有块的情况下尝试了一下,它报告说没有找到块。
它做它应该做的事。
有什么好处? 看一看我强调的部分。
注意括号平衡-
代码将在加载时运行,而不是在调用时运行,并且您在尝试重置cmdecho等时将收到错误,因为相关变量将为零。
对不起,我在电脑上测试版本。我将另一个副本重新粘贴到该线程。不知道发生了什么事。
据我所知是同一个版本。
但是谢谢你 此外,只需一个指针,您就可以更改以下内容:
对此:
6
李
谢谢李,
有些人认为发布的代码与我存储的代码不同。我不知道这是怎么发生的,但谢谢你发现了它。
页:
1
[2]