- 积分
- 1317
- 明经币
- 个
- 注册时间
- 2003-3-11
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
以下是一個作螺旋線的程序.我一點語法都不懂.想作如下改動:
1: 當用戶輸入水平每圈增加的距离為0時.程序把它設為1!
2: 作圖前設置OSMODE為0,事後取消.
//代碼
;;; 3DSPIRAL.LSP
; Copyright (C) 1992 by Autodesk, Inc.
; modified by CAD Studio, 2001 (globalization)
; 修改者:明經通道 http://www.mccad.net 2001 (中文化)
;
; Permission to use, copy, modify, and distribute this software
; for any purpose and without fee is hereby granted, provided
; that the above copyright notice appears in all copies and that
; both that copyright notice and this permission notice appear in
; all supporting documentation.
;
; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
; PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;; --------------------------------------------------------------------------;
;;; DESCRIPTION
;;;
;;; 這是一個程序實例。
;;;
;;; 由 Kelvin R. Throop 于 1985 年 1 月設計編制。
;;;
;;; 該程序生成一螺旋線。它可通過輸入“spiral”、“3dspiral”來加載及調用,
;;; 也可以通過以下表達式調用:
;;; (cspiral <# 旋轉圈數> <基點> <每圈的水平增加距离>
;;; <每圈的點數> <起始半徑>
;;; <每圈的垂直上升距离>).
;;;
;;; --------------------------------------------------------------------------;
(defun myerror (s) ; 如果出錯 (如按 CTRL-C)
; 將激活該命令...
(if (/= s "Function cancelled")
(princ (strcat "\n出錯: " s))
)
(setvar "cmdecho" ocmd) ; 恢复保存的模式
(setvar "blipmode" oblp)
(setq *error* olderr) ; 恢复舊的 *error* 處理
(princ)
)
(defun cspiral (ntimes bpoint hfac lppass strad vfac
/ ang dist tp ainc dhinc dvinc circle dv)
(setvar "blipmode" 0) ; 關閉亮顯
(setvar "cmdecho" 0) ; 關閉命令行提示
(setvar "osmode" 0) ; 關閉命令行提示
(setq circle (* 3.141596235 2))
(setq ainc (/ circle lppass))
(setq dhinc (/ hfac lppass))
(if vfac (setq dvinc (/ vfac lppass)))
(setq ang 0.0)
(if vfac
(setq dist strad dv 0.0)
(setq dist 0.0)
)
(if vfac
(command "_3dpoly") ; 開始螺旋 ...
(command "_pline" bpoint) ; 由基點開始螺旋...
)
(repeat ntimes
(repeat lppass
(setq tp (polar bpoint (setq ang (+ ang ainc))
(setq dist (+ dist dhinc))
)
)
(if vfac
(setq tp (list (car tp) (cadr tp) (+ dv (caddr tp)))
dv (+ dv dvinc)
)
)
(command tp) ; 繼續繪制下個點...
)
)
(command "") ; 直到完成。
(princ)
)
;;;
;;; 交互螺旋生成
;;;
(defun C:SPIRAL (/ olderr ocmd oblp nt bp cf lp)
;;;;(setq olderr *error*
;;;; *error* myerror)
(setq ocmd (getvar "cmdecho"))
(setq oblp (getvar "blipmode"))
(setvar "cmdecho" 0)
(initget 1) ; bp 必須為非空值
(setq bp (getpoint "\n中心點: "))
(initget 7) ; nt 必須為非零正數或非空值
(setq nt (getint "\n螺旋圈數: "))
(initget 3) ; cf 必須為非零或非空值
(setq cf (getdist "\n每圈增加距离: "))
(initget 6) ; lp 必須為非零正數
(setq lp (getint "\n每圈的點數<30>: "))
(cond ((null lp) (setq lp 30)))
(cspiral nt bp cf lp nil nil)
(setvar "cmdecho" ocmd)
(setvar "blipmode" oblp)
(setq *error* olderr) ; 恢复舊的 *error* 處理
(princ)
)
;;;
;;; Interactive spiral generation
;;;
(defun C:3DSPIRAL (/ olderr ocmd oblp nt bp hg vg sr lp)
;;;;(setq olderr *error*
;;;; *error* myerror)
(setq ocmd (getvar "cmdecho"))
(setq oblp (getvar "blipmode"))
(setvar "cmdecho" 0)
(initget 1) ; bp 必須為非空值
(setq bp (getpoint "\n中心點: "))
(initget 7) ; nt 必須為非零正數或非空值
(setq nt (getint "\n螺旋圈數: "))
(initget 7) ; sr 必須為非零正數或非空值
(setq sr (getdist bp "\n起點半徑: "))
(initget 1) ; hg 必須為非空值
(setq hg (getdist "\n水平每圈增加距离: "))
(initget 3) ; vg 必須為非零或非空值
(setq vg (getdist "\n垂直每圈上升距离: "))
(initget 6) ; lp 必須為非零正數
(setq lp (getint "\n每圈的點數 <30>: "))
(cond ((null lp) (setq lp 30)))
(cspiral nt bp hg lp sr vg)
(setvar "cmdecho" ocmd)
(setvar "blipmode" oblp)
(setq *error* olderr) ; 恢复舊的 *error* 處理
(princ)
)
;;; --------------------------------------------------------------------------;
(princ "\n\tC:SPIRAL 和 C:3DSPIRAL 已加載。 ")
(princ) |
|