LISP开发
常用的CAD二次开发语言

常用的CAD二次开发语言:1 AutoLISP全名是LIST Processing Language,LISP是List Processor(表处理程序)的缩写,cad系统的第一代开发工具,是一种嵌入在AutoCAD内部的编程语言,是低版本AutoCAD的首选编程语言。
它是一种表处理语言,是被解释执行的,任何一个语句键入后就能马上执行。
其缺点是继承了LISP语言的编程规则而导致繁多的括号。
2 ADS 全名是AutoCAD Development System,它是AutoCAD的C语言开发系统,丰富和保留了autolisp语言的功能,是一组可以用C语言编写AutoCAD应用程序的头文件和目标库,不包含于cad内部,包含c语言的全部功能。
ADS速度快,又采用结构化的编程体系,因而很适合于高强度的数据处理。
3 ObjectARX 崭新面向对象的开发AutoCAD应用程序的工具,以为编程语言,提供可与AutoCAD直接交互的开发环境。
可以与autolisp和ADS应用程序协同工作。
ObjectARX也没有包含在AutoCAD中,可在AutoDESK公司网站中去下载。
二次开发者可以充分利用AutoCAD的开放结构,直接访问AutoCAD数据库结构、图形系统以及CAD几何造型核心,以便能在运行期间实时扩展AutoCAD的功能,创建能全面享受AutoCAD固有命令的新命令。
ObjectARX的核心是两组关键的API,即AcDb(Auto CAD数据库)和AcEd(Auto CAD编译器),另外还有一些重要组件,如AcRX(Auto CAD实时扩展)、AcGi(Auto CAD图形接口)、AcGe(Auto CAD几何库)、ADSRX(Auto CAD开发系统实时扩展。
ObjectARX还可以按需要加载应用程序;使用ObjectARX进行应用开发还可以在同一水平上与Windows系统集成,并与其它Windows应用程序实现交互操作。
LISP编程在管线制图中的开发应用

当外 业 测 量 数 据 的 sf 据 格 式 时 . lp程 序 如 d数 其 i s
下:
( t a e(e l 管 线 点 数 据 文 件 S F输 入 框 … … ” s qf m gt e e n i f d” D
sf 2 ) d; )
围内尤其是勘察设计行业 中越来越普遍地在 得到推广
面 的开 发 运 用 A t IP语 言 。 编 写 出 适 用 于 广 州 uo S L 可 市 地 下 管 线 图 内容 的处 理 的程 序 和 函数 .下 面介 绍 几 个 典 型示 例
22 图层 及 颜 色的 设 置 . 图形 文件 的设 有 JX 、 I T T P G等 图层 . T T P’ 、O O X 颜
LS IP编程在 管线制图 中的开发应用
廖 宇宏 . 张 汉春
广州 5 0 6 ) 10 0
(. 东 省 科技 咨询 服务 中心 , 州 5 0 4 1 2 广州 市 城 市 规 划 勘 测 设 计 研 究 院 1广 广 10 0 ; .
摘
.
要 :A tC D 在 管线 工程 制 图起 十 分 重 要 的 作 用 。介绍 由 A t IP语 言编 写 的地 下 管线 图处 uo A uo S L
作 者 简介 : 宇宏 (92 , , 东人 , 理 工程 师 , 士 , 究方 向计 算 机 信 息技 术 廖 18 一) 男 广 助 学 研
现代计算机
2 1 .9 0 00
(eu erh ly(a n mec lra ) d fns ac _a 1y a oon me (eq tc tle rh”a e”ly a ) st u h(bsac lyr a n me ) (f( ul u h) i n ltc ( rg po n
CAD二次开发lisp教程《第四章》

(2)工具栏 Visual LISP提供了 提供了Standard,View,Debug,Tools和Search五 提供了 , , , 和 五 个工具栏 .
① Standard工具栏 工具栏
建立一个新文件 存盘 剪切 粘贴 恢复 打开一个已有的文件 打印输出 复制 取消 完词功能
Tools工具栏 ② Tools工具栏
删除被选中的文本并将其移到Windows剪贴板 剪贴板 删除被选中的文本并将其移到 将选中的文本复制到剪贴板中 将剪贴板内容粘贴到光标位置 清空控制台窗口 在控制台窗口中查找指定文本 打开"检验" 打开"检验"对话框 打开"监视" 打开"监视"窗口 打开"自动匹配选项" 打开"自动匹配选项"窗口 打开"符号服务" 打开"符号服务"对话框 放弃最近的操作 重新执行上次放弃的操作 将所有输入传送到 AutoCAD 命令行以供求值 切换是否将控制台窗口的输出复制到日志文件
Hale Waihona Puke 2. 使用控制台窗口的历史记录
提示下, 在_$提示下,每按一次 提示下 每按一次Tab键,回溯前一次输入的字符串,作为当前输入. 键 回溯前一次输入的字符串,作为当前输入. 到了第一次输入的字符串时,再按Tab键,返回最后一次输入的字符串,周 到了第一次输入的字符串时,再按 键 返回最后一次输入的字符串, 而复始.每按一次Shift+Tab键时,将进行反向回溯. 键时, 而复始.每按一次 键时 将进行反向回溯.
控制台快捷菜单
4. 记录控制台窗口的活动
日志文件的文件类型为" 日志文件的文件类型为 " .log", , 它记录了控制台窗口的所有活动, 它记录了控制台窗口的所有活动 , 通 过浏览该文件可以回顾控制台窗口中 执行的命令. 执行的命令. 在控制台窗口通过下拉菜单 File→Toggle Console Log或快捷菜单 → 或快捷菜单 Toggle Console Log可以建立日志文件. 可以建立日志文件. 可以建立日志文件
应用Visual Lisp编程开发配管加工设计工具

2 1 年 2月 01
化
工
设
备
与
管
道
Vo. No 1 48 .1 F b 01 e .2 1
P O E SE U P N & PPN R C S Q IME T IIG
・
管 道 与 管 件
・
应 用 V sa L s i l i u p编 程 开 发 配 管 加 工 设 计 工 具
能 化 , 大程 度 地 减 少人 工 操 作 , 而 缩 短 加 工 设 计 周 期 , 高加 工设 计 质 量 和 效 率 。 开 发 的 工 具 已成 功 地 用 于 多 最 从 提
个 工 程 项 目的 配 管加 工设 计 , 得 了很 好 的 效 果 。 取 关键 词 : i a Ls ; 配 管 三 维 图 ; 加 工设 计 ; A tC D二 次开 发 Vs l i u p uo A 中 图 分 类 号 :Q0 0 2 T 5 . 文献标识码 : A 文章 编 号 : 093 8 ( 0 ) l04 —3 10 —2 12 1 O -0 20 1
对 于规 模庞大 、 间密集 、 空 系统 复杂 的海 洋平 台 和FS P O上 部 工 艺 配 管 工 程 , 般 使 用 P S P MS 一 D 、D 等配管 软件建 立三 维 模 型 , 后从 模 型 中抽 出 配管 然 三维 图进行 加工设 计 。 由于 管线 系统多 、 种类 多 、 数 量 多 , 了便 于施 工 管 理 、 高工 作 效 率 , 要 添加 为 提 需 流水号 、 管号 、 场连 接 E号和预 制连 接 E号 。 单 现 l l A tC D软件 固然能完 成流水 号 、 uo A 单管号 、 场 现 连接 口号和 预制 连接 口号 的添加 , 其 操 作 过 于繁 但
Java、Lisp和Prolog三种编程语言的区别是什么?

人工智能需要用编程语言来开发。
今天我们就来给大家介绍3种人工智能的开发语言,Java、Lisp和Prolog。
JavaJava也是一种多范式语言,遵循面向对象开发与一次写入读取,随处运行(WORA)的原则。
它也是一种AI编程语言,可以在任何支持Java的平台上运行,无需重新编译。
Java是常见的语言之一,不仅仅是在AI开发领域。
它从C和C++中派生出它的大量语法。
Java不仅适用于NLP和搜索算法,还适用于神经网络。
Lisp优点Lisp是计算机编程语言家族继Fortran之后第二个古老的编程语言。
随着时间的推移,LISP 已经发展成为一门强大且动态的编码语言。
有些人认为Lisp是好的AI编程语言,它为开发者提供了大限度的自由。
人工智能使用Lisp 是因为它的灵活性,这使原型快速设计和实验成为可能,反过来促进了Lisp在AI开发中的发展。
比如,Lisp有一个独特的微系统,可以探索和实现不同层次的智能。
与大多数AI语言不同,Lisp在解决特定问题方面更高效,它能适应开发人员编写的解决方案的全部需求。
它也非常适合于归纳逻辑项目与机器学习。
缺点熟悉Lisp编程的开发人员很少。
作为一种复古的编程语言,Lisp需要配置新的软件和硬件以适配其使用。
PrologProlog也是古老的编程语言之一,它也适用于编程AI的开发。
像Lisp一样,也是一种人工智能的主要开发语言,它有开发者喜欢的灵活框架的独特机制。
Prolog是一种基于规则和声明的语言,包含着规定人工智能语言编码的事实和规则。
Prolog 支持人工智能的基本机制,例如模式匹配,基于树型数型结构以及AI编程所必需的自动回溯机制。
Prolog除了广泛被应用于AI项目,另外它还适用于构建医疗软件系统。
CAD二次开发Visual_LISP指南

CAD二次开发Visual_LISP指南CAD二次开发是指在CAD软件平台上进行个性化开发和定制化编程,以满足用户特定需求Visual LISP是AutoCAD软件的一种编程语言,通过使用Visual LISP语言可以对AutoCAD进行二次开发。
下面是CAD二次开发Visual LISP的指南,希望对开发人员有所帮助。
一、入门准备1.学习基础知识在开始进行CAD二次开发前,需要充分了解AutoCAD软件的基本功能和特点,熟悉CAD软件的界面、命令、对象模型以及常用API(应用程序接口)等。
2.掌握Visual LISP语言Visual LISP是CAD软件平台上的一种编程语言,与AutoLISP类似。
学习和掌握Visual LISP语言是进行CAD二次开发的基础。
可以通过学习书籍、在线教程和参考文档等途径来提高自己的编程能力。
3.安装开发工具需要安装CAD软件的开发工具,例如AutoCAD自带的AutoCAD Developer Tools或者Visual LISP IDE等。
这些工具提供了编写、调试和管理二次开发项目的必要环境。
二、开始二次开发1.确定需求在进行CAD二次开发前,需要明确开发的具体需求和目的。
这可以包括添加自定义命令、修改现有功能、创建用户界面等等。
确保清晰地定义需求和目标,以便更好地进行开发工作。
2.编写代码通过Visual LISP语言编写代码来实现二次开发的需求。
VisualLISP提供了一系列的函数和命令,可以对AutoCAD的对象模型进行访问和操作。
根据需求,编写相应的函数、宏和命令,实现具体的功能。
3.调试和测试在编写代码后,进行调试和测试是不可或缺的步骤。
通过运行调试器、打印日志、进行单元测试等方式来验证代码的正确性和稳定性。
及时修复和调整代码中的问题,确保其能够正常运行。
4.文档和发布完成开发工作后,建议对代码进行适当的文档整理和注释,方便后续的维护和管理。
基于VisualLISP二次开发的自动安装处理程序

t h r o t a e l o Se u wa n r du e . T h t uc u e o u o he t id s fw r nn t p sito c d e s r t r f A t CA D e i ty w a n l z d The s s e rgsr sa ay e . y t m v ra l s w e e a i b e r a c r ane n r gity. I a l z d nno e u s rp a d us o ie t pr se ti di e sr t na y e I S t p c i t n c t m z d he ogr m s rpt a c i by V iu l SP n s a LI i A ut CAD . I o t Pr v d d a m e ho o s rt e l pm e ns al to pr c du ew ih iuaLI o i e t d f r u e o d veo nti tla in o e r t V s l SP.
Pr gr m ns a l d a d Pr c s e u o a i a l s d on o a I t le n o e s d A t m tc ly Ba e
V iu l SP Se o a y De eo s a II c nd r v l pm e t n
第二 , 在重 装 Auo AD时需 要 重新 复 制 用户 程 序 。 tC 而对 于应 用程 序 的使 用者来 说 这种安 装方 式过 于专 业 和繁杂 。第 三 , 便 于用 户开 发 的应 用程 序 的推 不
第3 卷第 2 2 期
21 0 2年 6月
辽
宁
石
LISP语言教程(1)

(quote x)返回x.为了可读性我们把(quote x)简记为'x.
> (quote a)
a
> 'a
a
> (quote (a b c))
(a b c)
atom
(atom x)返回原子t如果x的值是一个原子或是空表,否则返回().在Lisp中我们按惯例用原子t表示真,而用空表表示假.
> (atom 'a)
(cond ((atom z)
(cond ((eq z y) x)
('t z)))
('t (cons (subst x y (car z))
(subst x y (cdr z))))))
偶然地我们在这儿看到如何写cond表达式的缺省子句.第一个元素是't的子句总是会成功的.于是
(cond (x y) ('t z))
等同于我们在某些语言中写的
if x then y else z
一些函数
既然我们有了表示函数的方法,我们根据七个原始操作符来定义一些新的函数.为了方便我们引进一些常见模式的简记法.我们用cxr,其中x是a或d的序列,来简记相应的car和cdr的组合.比如(cadr e)是(car(cdr e))的简记,它返回e的第二个元素.
示例
假设我们要定义函数(subst x y z),它取表达式x,原子y和表z做参数,返回一个象z那样的表,不过z中出现的y(在任何嵌套层次上)被x代替.
> (subst 'm 'b '(a b (a b c) d))
(a m (a m c) d)
我们可以这样表示此函数
(label subst (lambda (x y z)
Lisp语言的基本语法与应用

Lisp语言的基本语法与应用Lisp(List Processing)是一种函数式编程语言,它以列表为基础数据结构并使用S表达式(S-expression)进行编程。
本文将介绍Lisp语言的基本语法和应用。
一、基本语法1. 原子(Atom):Lisp的基本数据单位,可以是数字、字符串或符号。
例如,数字1、字符串"Hello, World!"和符号'hello都是Lisp的原子。
2. 列表(List):Lisp的核心数据结构,由左括号、元素列表和右括号组成。
列表中的元素可以是原子,也可以是嵌套的列表。
例如,(12 3)和('a ('b 'c))都是合法的Lisp列表。
3. 函数调用:Lisp通过括号表示函数调用,函数名位于第一个元素位置,后跟参数列表。
例如,(+ 1 2)表示调用加法函数,将1和2相加。
4. 定义变量:Lisp使用defvar或setq关键字用于定义变量。
defvar用于定义全局变量,setq用于定义局部变量。
例如,(defvar *pi* 3.14)定义了一个全局变量*pi*,(setq x 10)定义了一个局部变量x并赋值为10。
二、基本应用1. 计算器:Lisp提供了基本的数学运算函数,例如加法(+),减法(-),乘法(*)和除法(/)等。
可以通过使用这些函数进行算术计算。
2. 条件判断:Lisp中的条件判断使用if函数,语法形式为(if condition then else)。
当condition为真时,执行then部分的代码,否则执行else部分的代码。
例如,(if (> x 0) (print "x is positive") (print "x is negative"))根据变量x的值输出不同的结果。
3. 循环:Lisp的循环结构通过使用循环宏(loop macro)实现。
LISP编程语言教学手册说明书

1About the T utorialLISP is the second-oldest high-level programming language after Fortran and has changed a great deal since its early days, and a number of dialects have existed over its history. Today, the most widely known general-purpose LISP dialects are Common LISP and Scheme.This tutorial takes you through features of LISP Programming language by simple and practical approach of learning.AudienceThis reference has been prepared for the beginners to help them understand the basic to advanced concepts related to LISP Programming language.PrerequisitesBefore you start doing practice with various types of examples given in this reference, we assume that you are already aware of the fundamentals of computer programming and programming languages.Copyright & DisclaimerCopyright 2014 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher.You strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at **************************iT able of ContentsAbout the Tutorial (i)Audience (i)Prerequisites (i)Copyright & Disclaimer (i)Table of Contents (ii)1.OVERVIEW (1)Features of Common LISP (1)Applications Developed in LISP (1)2.ENVIRONMENT SETUP (3)How to Use CLISP (3)3.PROGRAM STRUCTURE (4)A Simple LISP Program (4)LISP Uses Prefix Notation (5)Evaluation of LISP Programs (5)The 'Hello World' Program (6)4.BASIC SYNTAX (7)Basic Elements in LISP (7)Adding Comments (8)Notable Points (8)LISP Forms (8)Naming Conventions in LISP (9)Use of Single Quotation Mark (9)5.DATA TYPES (11)Type Specifiers in LISP (11)6.MACROS (14)Defining a Macro (14)7.VARIABLES (15)Global Variables (15)Local Variables (16)8.CONSTANTS (18)9.OPERATORS (19)Arithmetic Operations (19)Comparison Operations (20)Logical Operations on Boolean Values (22)Bitwise Operations on Numbers (24)10.DECISION MAKING (27)The cond Construct in LISP (28)The if Construct (29)The when Construct (30)The case Construct (31)11.LOOPS (32)The loop Construct (33)The loop for Construct (33)The do Construct (35)The dotimes Construct (36)The dolist Construct (37)Exiting Gracefully from a Block (38)12.FUNCTIONS (40)Defining Functions in LISP (40)Optional Parameters (41)Keyword Parameters (43)Returning Values from a Function (43)Lambda Functions (45)Mapping Functions (45)13.PREDICATES (47)14.NUMBERS (51)Various Numeric Types in LISP (52)Number Functions (53)15.CHARACTERS (56)Special Characters (56)Character Comparison Functions (57)16.ARRAYS (59)17.STRINGS (66)String Comparison Functions (66)Case Controlling Functions (68)Trimming Strings (69)Other String Functions (70)18.SEQUENCES (73)Creating a Sequence (73)Generic Functions on Sequences (73)Standard Sequence Function Keyword Arguments (76)Finding Length and Element (76)Modifying Sequences (77)Sorting and Merging Sequences (78)Sequence Predicates (79)19.LISTS (81)The Cons Record Structure (81)Creating Lists with list Function in LISP (82)List Manipulating Functions (83)Concatenation of car and cdr Functions (85)20.SYMBOLS (86)Property Lists (86)21.VECTORS (89)Creating Vectors (89)Fill Pointer Argument (90)22.SET (92)Implementing Sets in LISP (92)Checking Membership (93)Set Union (94)Set Intersection (95)Set Difference (96)23.TREE (98)Tree as List of Lists (98)Tree Functions in LISP (98)Building Your Own Tree (100)Adding a Child Node into a Tree (100)24.HASH TABLE (103)Creating Hash Table in LISP (103)Retrieving Items from Hash Table (104)Adding Items into Hash Table (104)Applying a Specified Function on Hash Table (106)25.INPUT & OUTPUT (107)Input Functions (107)Reading Input from Keyboard (108)Output Functions (110)Formatted Output (113)26.FILE I/O (115)Opening Files (115)Writing to and Reading from Files (116)Closing a File (118)27.STRUCTURES (119)Defining a Structure (119)28.PACKAGES (122)Package Functions in LISP (122)Creating a Package (123)Using a Package (123)Deleting a Package (125)29.ERROR HANDLING (127)Signaling a Condition (127)Handling a Condition (127)Restarting or Continuing the Program Execution (128)Error Signaling Functions in LISP (131)MON LISP OBJECT SYSTEMS (133)Defining Classes (133)Providing Access and Read/Write Control to a Slot (133)Defining a Class Method (135)Inheritance (136)LISP8LISP stands for LIS t P rogramming. John McCarthy invented LISP in 1958, shortly after the development of FORTRAN. It was first implemented by Steve Russell on an IBM 704 computer. It is particularly suitable for Artificial Intelligence programs, as it processes symbolic information efficiently.Common LISP originated during the decade of 1980 to 1990, in an attempt to unify the work of several implementation groups, as a successor of Maclisp like ZetaLisp and New Implementation of LISP (NIL) etc.It serves as a common language, which can be easily extended for specific implementation. Programs written in Common LISP do not depend on machine-specific characteristics, such as word length etc.Features of Common LISP∙ It is machine-independent∙ It uses iterative design methodology∙ It has easy extensibility∙ It allows to update the programs dynamically∙ It provides high level debugging.∙ It provides advanced object-oriented programming.∙ It provides convenient macro system.∙ It provides wide-ranging data types like, objects, structures, lists, vectors, adjustable arrays, hash-tables, and symbols.∙ It is expression-based.∙ It provides an object-oriented condition system.∙ It provides complete I/O library.∙ It provides extensive control structures.1. OVERVIEWLISPApplications Developed in LISPThe following applications are developed in LISP: Large successful applications built in LISP.∙Emacs: It is a cross platform editor with the features of extensibility, customizability, self-document ability, and real-time display.∙G2∙AutoCad∙Igor Engraver∙Yahoo Store9LISP10CLISP is the GNU Common LISP multi-architechtural compiler used for setting up LISP in Windows. The Windows version emulates Unix environment using MingW under Windows. The installer takes care of this and automatically adds CLISP to the Windows PATH variable.You can get the latest CLISP for Windows at:/projects/clisp/files/latest/downloadIt creates a shortcut in the Start Menu by default, for the line-by-line interpreter.How to Use CLISPDuring installation, CLISP is automatically added to your PATH variable if you select the option (RECOMMENDED). It means that you can simply open a new Command window and type "clisp" to bring up the compiler. To run a *.lisp or *.lsp file, simply use: clisp hello.lisp2. ENVIRONMENT SETUPLISP11LISP expressions are called symbolic expressions or S-expressions. The S-expressions are composed of three valid objects:∙ Atoms ∙ Lists ∙StringsAny S-expression is a valid program. LISP programs run either on an interpreter or as compiled code.The interpreter checks the source code in a repeated loop, which is also called the Read-Evaluate-Print Loop (REPL). It reads the program code, evaluates it, and prints the values returned by the program.A Simple LISP ProgramLet us write an s-expression to find the sum of three numbers 7, 9 and 11. To do this, we can type at the interpreter prompt ->: (+7911)LISP returns the following result: 27If you would like to execute the same program as a compiled code, then create a LISP source code file named myprog.lisp and type the following code in it: (write(+7911))When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result is: 273. PROGRAM STRUCTURELISP Uses Prefix NotationIn prefix notation, operators are written before their operands. You might have noted that LISP uses prefix notation. In the above program, the ‘+’ symbol works as a function name for the process of summation of the numbers.For example, the following expression,a * (b +c ) / dis written in LISP as:(/ (* a (+ b c) ) d)Let us take another example. Let us write code for converting Fahrenheit temperature of 60o F to the centigrade scale:The mathematical expression for this conversion is:(60 * 9 / 5) + 32Create a source code file named main.lisp and type the following code in it:(write(+ (* (/ 9 5) 60) 32))When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result is:140Evaluation of LISP ProgramsThe LISP program has two parts:∙Translation of program text into LISP objects by a reader program.∙Implementation of the semantics of the language in terms of LSIP objects by an evaluator program.The evaluation program takes the following steps:∙The reader translates the strings of characters to LISP objects or s-expressions.12∙The evaluator defines syntax of LISP forms that are built from s-expressions.∙This second level of evaluation defines a syntax that determines which s-expressions are LISP forms.∙The evaluator works as a function that takes a valid LISP form as an argument and returns a value. This is the reason why we put the LISP expression in parenthesis, because we are sending the entire expression/form to the evaluator as argument.The 'Hello World' ProgramLearning a new programming language does not really take off until you learn how to greet the entire world in that language, right ?Let us create new source code file named main.lisp and type the following code in it:(write-line "Hello World")(write-line "I am at 'Tutorials Point'! Learning LISP")When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result is:Hello WorldI am at 'Tutorials Point'! Learning LISP13LISP14This chapter introduces you to basic syntax structure in LISP.Basic Elements in LISPLISP programs are made up of three basic elements:∙ atom ∙ list ∙stringAn atom is a number or string of contiguous characters. It includes numbers and special characters. The following examples show some valid atoms: hello-from-tutorials-point name 123008907 *hello* Block#221 abc123A list is a sequence of atoms and/or other lists enclosed in parentheses. The following examples show some valid lists: ( i am a list) (a ( a b c) d e fgh)(father tom ( susan bill joe)) (sun mon tue wed thur fri sat) ( )A string is a group of characters enclosed in double quotation marks. The following examples show some valid strings:4. BASIC SYNTAX" I am a string""a ba c d efg #$%^&!""Please enter the following details:""Hello from 'Tutorials Point'! "Adding CommentsThe semicolon symbol (;) is used for indicating a comment line.Example(write-line "Hello World") ; greet the world; tell them your whereabouts(write-line "I am at 'Tutorials Point'! Learning LISP")When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is:Hello WorldI am at 'Tutorials Point'! Learning LISPNotable PointsThe following important points are notable:∙The basic numeric operations in LISP are +, -, *, and /∙LISP represents a function call f(x) as (f x), for example cos(45) is written as cos 45∙LISP expressions are not case-sensitive. Means, cos 45 or COS 45 are same.∙LISP tries to evaluate everything, including the arguments of a function. Only three types of elements are constants and always return their own value:o Numberso The letter t, that stands for logical trueo The value nil, that stands for logical false, as well as an empty list.15LISP FormsIn the previous chapter, we mentioned that the evaluation process of LISP code takes the following steps:∙The reader translates the strings of characters to LISP objects or s-expressions.∙The evaluator defines syntax of LISP forms that are built from s-expressions.This second level of evaluation defines a syntax that determines which s-expressions are LISP forms.A LISP form can be:∙An atom∙An empty list or non-list∙Any list that has a symbol as its first elementThe evaluator works as a function that takes a valid LISP form as an argument and returns a value.This is the reason why we put the LISP expression in parenthesis,because we are sending the entire expression/form to the evaluator as argument.Naming Conventions in LISPName or symbols can consist of any number of alphanumeric characters other than whitespace, open and closing parentheses, double and single quotes, backslash, comma, colon, semicolon and vertical bar. To use these characters in a name, you need to use escape character (\).A name can have digits but must not be made of only digits, because then it would be read as a number. Similarly a name can have periods, but cannot be entirely made of periods.Use of Single Quotation MarkLISP evaluates everything including the function arguments and list members.At times, we need to take atoms or lists literally and do not want them evaluated or treated as function calls. To do this, we need to precede the atom or the list with a single quotation mark.16The following example demonstrates this:Create a file named main.lisp and type the following code into it:(write-line "single quote used, it inhibits evaluation")(write '(* 2 3))(write-line " ")(write-line "single quote not used, so expression evaluated")(write (* 2 3))When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result is:single quote used, it inhibits evaluation(* 2 3)single quote not used, so expression evaluated617LISP18LISP data types can be categorized as:Scalar types - numbers, characters, symbols etc. Data structures - lists, vectors, bit-vectors, and strings.Any variable can take any LISP object as its value, unless you declare it explicitly. Although, it is not necessary to specify a data type for a LISP variable, however, it helps in certain loop expansions, in method declarations and some other situations that we will discuss in later chapters.The data types are arranged into a hierarchy. A data type is a set of LISP objects and many objects may belong to one such set.The typep predicate is used for finding whether an object belongs to a specific type. The type-of function returns the data type of a given object.T ype Specifiers in LISPType specifiers are system-defined symbols for data types.Array fixnum package simple-string Atom float pathname simple-vector Bignum function random-state single-float Bit hash-table Ratio standard-char bit-vector integer Rational stream Character keyword readtable string [common]listsequence[string-char]5. DATA TYPESLISP compiled-function long-float short-float symbolComplex nill signed-byte tCons null simple-array unsigned-bytedouble-float number simple-bit-vector vectorApart from these system-defined types, you can create your own data types. When a structure type is defined using defstruct function, the name of the structure type becomes a valid type symbol.>/p>Example 1Create new source code file named main.lisp and type the following code in it:(setq x 10)(setq y 34.567)(setq ch nil)(setq n 123.78)(setq bg 11.0e+4)(setq r 124/2)(print x)(print y)(print n)(print ch)(print bg)(print r)When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is:1034.567123.78NIL19LISP110000.062Example 2Next let us check the types of the variables used in the previous example. Create new source code file named main.lisp and type the following code in it:(setq x 10)(setq y 34.567)(setq ch nil)(setq n 123.78)(setq bg 11.0e+4)(setq r 124/2)(print (type-of x))(print (type-of y))(print (type-of n))(print (type-of ch))(print (type-of bg))(print (type-of r))When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result is:(INTEGER 0 281474976710655)SINGLE-FLOATSINGLE-FLOATNULLSINGLE-FLOAT(INTEGER 0 281474976710655)20LISP 21LISP22This chapter introduces you about macros in LISP.A macro is a function that takes an s-expression as arguments and returns a LISP form, which is then evaluated. Macros allow you to extend the syntax of standard LISP.Defining a MacroIn LISP, a named macro is defined using another macro named defmacro. Syntax for defining a macro is:(defmacro macro-name (parameter-list)"Optional documentation string."body-form)The macro definition consists of the name of the macro, a parameter list, an optional documentation string, and a body of LISP expressions that defines the job to be performed by the macro.ExampleLet us write a simple macro named setTo10, which takes a number and sets its value to 10.Create new source code file named main.lisp and type the following code in it: defmacro setTo10(num)(setq num 10)(print num))(setq x 25)(print x)(setTo10 x)When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result is:6. MACROSLISP251023LISP24In LISP, each variable is represented by a symbol. The name of the variable is the name of the symbol and it is stored in the storage cell of the symbol. Global V ariablesGlobal variables are generally declared using the defvar construct. Global variables have permanent values throughout the LISP system and remain in effect until new values are specified.Example(defvar x 234)(write x)When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result is:234As there is no type declaration for variables in LISP, you need to specify a value for a symbol directly with the setq construct.Example->(setq x 10)The above expression assigns the value 10 to the variable x. You can refer to the variable using the symbol itself as an expression.The symbol-value function allows you to extract the value stored at the symbol storage place.ExampleCreate new source code file named main.lisp and type the following code in it: (setq x 10)(setq y 20)7. VARIABLES(format t "x = ~2d y = ~2d ~%" x y)(setq x 100)(setq y 200)(format t "x = ~2d y = ~2d" x y)When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result is:x = 10 y = 20x = 100 y = 200Local V ariablesLocal variables are defined within a given procedure. The parameters named as arguments within a function definition are also local variables. Local variables are accessible only within the respective function.Like the global variables, local variables can also be created using the setq construct. There are two other constructs - let and prog for creating local variables.The let construct has the following syntax:(let ((var1 val1) (var2 val2).. (varn valn))<s-expressions>)Where var1, var2,…,varn are variable names and val1, val2,…, valn are the initial values assigned to the respective variables.When let is executed, each variable is assigned the respective value and at last, the s-expression is evaluated. The value of the last expression evaluated is returned.If you do not include an initial value for a variable, the variable is assigned to nil. ExampleCreate new source code file named main.lisp and type the following code in it:(let ((x 'a)(y 'b)(z 'c))(format t "x = ~a y = ~a z = ~a" x y z))25When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result is:x = A y = B z = CThe prog construct also has the list of local variables as its first argument, which is followed by the body of the prog,and any number of s-expressions.26End of ebook previewIf you liked what you saw…Buy it from our store @ https://27。
visual LISP语言及编程资料

(c:ls)
2018/11/27
8
xhm
6.3.2 在AutoCAD环境中加载、运行AutoLISP程序 1、加载 工具 →AutoLISP→加载应用程序… “管理”选项卡→“应用程序”面板→ 加载应用程序 2、运行 (1)AutoLISP程序中以“defun c:<函数名>”格式定义,在命令窗 口直接输入函数名(当作Autocad新命令) (2) AutoLISP程序中以“defun<函数名>”格式定义,在命令窗口 输入用括号括起来的函数名
xhm
主要内容: 1、Visual LISP集成开发环境 2、加载、运行AutoLISP程序 3、 AutoLISP编程、函数 4、应用举例
2018/11/27
1
xhm
AutoCAD 具有开放的体系结构,可对其进行二次开发 开发工具:Auto LISP Visual Basic VBA Visual C++等 Visual LISP 是 开 发 AutoCAD 最 主 要 的 工 具 。 用 户 可 以 利 用 Visual LISP 语 言 实 现 对 AutoCAD 当 前 图 形 数 据 库 的 直 接 访 问 和 修 改 , 增 加
4、赋值函数 (setq <符号1> <表达式> [符号2] [表达式2]…) (setq a 45 c 56 d 78) (setq h1 (* h 1.61658) (setq p1 (getpoint “\n 输入第一点:”)) 5、禁止求值函数 (quote <表达式>) 或 ‘(<表达式>) (setq pt1 (quote (4.5 7.5))) (4.5 7.5) (setq pt1 '(4.5 7.5)) (4.5 7.5) (command “line” ‘(100 120) ‘(23 116) “”)
实现CAD绘图与LISP编程的自动化技巧

实现CAD绘图与LISP编程的自动化技巧CAD(计算机辅助设计)是一种广泛应用于工程和建筑行业的软件工具,而LISP(LISt Processing)则是一种编程语言,经常用于CAD 软件中进行自动化任务和定制。
在CAD绘图中,使用LISP编程可以极大提高工作效率,加快绘图速度并减少出错概率。
下面,我们将介绍一些实现CAD绘图与LISP编程的自动化技巧。
1. 使用LISP编写简单命令LISP语言在CAD软件中被广泛应用,因其简洁、灵活和强大的功能而备受赞誉。
可以利用LISP编写一些简单的命令,以自动完成一些常见的绘图任务。
例如,我们可以编写一段LISP代码,用于创建一个特定大小和形状的矩形或圆形,并将其放置在指定位置。
2. 利用LISP实现参数化绘图参数化绘图是CAD绘图中常见的需求,它可以根据一组参数值自动生成特定形状和尺寸的图形。
利用LISP编程可以方便地实现参数化绘图。
通过定义参数,并使用LISP代码控制参数值,可以在绘图过程中灵活地调整形状和尺寸,提高工作效率。
3. 利用LISP编写循环和逻辑语句LISP编程强大之处在于其循环和逻辑语句的灵活性。
通过编写循环和逻辑语句,可以实现复杂的绘图任务,如图形的重复、数组的生成等。
例如,我们可以使用循环语句自动生成一系列具有相同属性但位置不同的图形。
4. 利用LISP批处理CAD命令CAD软件中的批处理命令可以用于自动执行一系列CAD操作,如创建图层、更改对象属性等。
利用LISP编程可以轻松地实现批处理CAD命令。
通过编写LISP代码,将多个CAD命令组合在一起,可以以一次性的方式自动执行这些命令,从而减少人为干预。
5. 利用LISP创建自定义CAD函数和命令除了使用CAD软件中已有的命令,我们还可以通过LISP编程自定义CAD函数和命令,以满足特定的需求。
通过编写LISP代码,可以根据自己的需要定义函数和命令,从而实现更高级和复杂的CAD绘图操作。
CAD二次开发(LISP)

第5行:(defun C: triang1() 本行中,defun为一个AutoLISP函数,它定义了函数TRIANG1。TRIANG1 为该函数的函数名。由于此函数名前带有C:,因此该函数可以像AutoCAD 命令一样被执行。若没有C:, TRIANG1命令只能置于圆括号中执行(TRIANG1)。此函数带有三个全 局变量( P1,P2,P3)。第一次编写AutoLISP程序时,保持变量为全局变量是个好 习惯。这是因为装入并运行程序后,可以通过在AutoCAD命令提示行中输人 感叹号(!)并在其后输入变量名来检查变量的值(Command:!P1)。一 旦程序通过测试并运行正常,就应该使它们成为局部变量(defun c:TRIANG1(/P1 P2 P3) 第6行:(setq P1(getpoint“\n Enter first Point of triangle:")) 本行中,getpoint函数暂停程序的运行,允许用户输入三角形的第一个点。 提示信息Enter first Point of triangle显示在屏幕的提示区内。可以通过键盘输入该点的坐标,也可以用 屏幕光标选择该点。随后setq函数将这些坐标赋予变量P1。\n的作用是回车, 其后的表达式将被打印在下一行上(“n”代表“newline")
说明
1 2 3 4 5 6 7 8 9
10
第1-3行 前三行为注释行,用于描述程序中的函数。这几行很重要因为有它们,编 辑程序会变得简单一些。可以在任何必要的时候使用注释。所有的注释行都 必须以分号(;)开头,当程序装入时这些行会被忽略。 第4行:行为空行,用于分隔程序与注释部分。空行还可以用来分隔程序 的不同模块。这样便于区分程序的不同部分。空行对程序没有影响。再 Nhomakorabea加几个函数
LISP语言在计算机科学中的应用研究

LISP语言在计算机科学中的应用研究在计算机科学领域中,各种不同的编程语言被用于开发和构建各类软件和系统,其中LISP语言也是一种非常重要的语言。
LISP语言是一种特殊的编程语言,它的设计原则被广泛应用于许多现代编程语言中。
通过对LISP语言在计算机科学领域中的应用研究,我们可以深入了解该语言的独特之处以及它为我们所带来的好处。
LISP语言的历史LISP语言是由约翰·麦卡锡(John McCarthy)在20世纪50年代初期首次开发的。
LISP是“LISt Processor”(列表处理器)的缩写,它最初的设计是为了能够处理复杂的符号运算。
该语言本质上是基于Lambda演算(Lambda calculus)的,它具有一些非常有趣的特性,例如多态性和动态类型等。
LISP语言的特点LISP语言的一个重要特点是它具有高度的表达能力和灵活性。
它可以很容易地表达复杂的数学公式和算法。
而且,LISP代码非常容易调试和修改,这使得它在计算机科学领域中非常受欢迎。
此外,LISP语言还具有丰富的数据结构和内建函数,这些功能使得它可以被用于各种不同的应用场景。
LISP语言的应用领域LISP语言可以被用于各种不同的应用领域,例如:人工智能、自然语言处理、算法设计等。
在人工智能领域中,LISP语言被广泛应用于开发专家系统、规则引擎和机器学习算法等方面。
此外,LISP语言也被用于开发其他类型的程序,例如:文本编辑器、数据库和操作系统等。
LISP语言的优势LISP语言有许多优点,这些优点使得它在计算机科学领域中被广泛使用。
LISP语言具有高级别的抽象性,这使得程序员可以在理论水平上思考和设计问题,而不是只关注具体的细节。
此外,LISP语言还具有强大的元编程能力,这意味着程序员可以用LISP语言去编写其他编程语言。
最后,LISP语言具有动态类型,这也就意味着更容易编写灵活的代码。
总结LISP语言虽然在项目中并未像其他流行语言那样常用,但它无疑是计算机科学中最重要的语言之一。
7.5VisualLisp语言窗体开发与数据传递

jxfl:dialog{ label="甲型法兰"; :row{ :boxed_column{ label="法兰参数"; :edit_box{ label="法兰直径DN:"; key="dn"; edit_limit=15; edit_width=10; value=100; } :edit_box{ label="D3:"; key="db"; edit_limit=15; edit_width=10; value=155; } : :
序中; 对话框中的图像一般采用*.sld文件形式,通过关键词在主程序中调用。
? 小思考(是非判断)
1、 对话框文件不能在visual lisp 语言环境下编写 (
)
2、对话框文件必须以dcl为文件后缀名保存(
)
3、对话文件中调用控件必须先用“:”(
)
4、对话框可以实现嵌套(
)
方法2
:spacer{width=2;}
控件名;
方法3
ok_only; ok_cancel; ok_cancel_help;
如何确定对话框控件的逻辑结构?
结构分析:从大范围来看,是一个大列,列中共有5大行组成,其中第二行 又是一个框型列,而第三行是一个框型行,需要进行重新定义。另外在第 一大行和第二大行之间留一个空白。
label="显示技术说明";
}
} //全列结束
} //全局结束
如何编写有图像的对话框?
绘制圆对话框
绘制圆对话框的结构分析
对话框是一个树型结构,对话框是这棵树的树根,行、列组件是树 枝,基本控件和组合控件是树叶。
lisp教程

lisp教程Lisp 是一种编程语言,源自于Lambda演算,并且被广泛应用于人工智能领域。
本教程将介绍Lisp的基本概念和语法,帮助初学者快速入门。
1. 表达式和函数调用在Lisp中,所有的计算都是通过表达式和函数调用完成的。
表达式由一个或多个函数和参数组成,并用括号括起来。
例如,(加 2 3) 表示将2和3相加。
2. 变量和赋值在Lisp中,可以使用变量来存储数据,并使用赋值操作符将一个值赋给一个变量。
例如,(setq x 5) 表示将5赋给变量x。
3. 条件语句Lisp提供了条件语句来根据不同的条件执行不同的代码块。
最常用的条件语句是(if-else)语句,它根据一个条件判断是否执行某个代码块。
例如,(if (= x 5) (print "x是5") (print "x不是5")) 表示当x等于5时输出"x是5",否则输出"x不是5"。
4. 循环Lisp提供了多种循环结构来重复执行一段代码。
最常用的循环结构是(do)循环,它可以设置一个计数器,并执行一段代码块指定的次数。
例如,(do ((i 0 (+ i 1))) ((= i 10)) (print i)) 表示从0到9输出i的值。
5. 函数定义和调用在Lisp中,可以使用(define)关键字来定义一个函数,并使用函数名和参数列表来调用这个函数。
例如,(defun square (x) (* x x)) 定义了一个计算平方的函数,并可以使用(square 5)来调用这个函数。
6. 列表和操作Lisp中的列表是一种特殊的数据结构,可以包含多个元素。
可以使用(list)函数创建一个列表,并使用(car)和(cdr)函数来获取列表的第一个元素和剩余元素。
例如,(setq numbers (list 1 2 3)) 定义了一个包含三个元素的列表,并可以使用(car numbers)获取第一个元素。
visualLISP语言及编程

2019/11/13
4
xhm
2019/11/13
5
xhm
2019/11/13
6
菜单栏
文本编辑器
xhm
工具栏
跟踪窗口 状态栏
控制台窗口
2019/11/13
7
xhm
6.3 加载Leabharlann 运行AutoLISP程序10、表处理函数
(car <表>) (car ‘(a b c)) 返回a
11、交互式输入函数 (setq d (getreal “\n 输入螺栓直径:”))
12、条件函数
(if <条件> <表达式1> <表达式2>)
(if (> ld (* 2 d)) ;若螺栓长度大于2倍直径,按实际值绘制
(princ "OK")
(c:my-circle) AutoCAD——在命令窗口直接输入函数名 my-circle
2019/11/13
16
xhm
6.6 在Visual LISP集成开发环境中调试程序
1、启动Visual LISP 2、输入程序代码并设置其格式 3、保存程序 4、在Visual LISP环境中加载、运行程序 5、设置断点 6、单步执行程序 7、跟踪变量 8、跟踪表达式的运行结果 调试→监视最新结果
2
xhm
6.1 LISP、Auto LISP及Visual LISP
LISP诞生于20世纪50年代末期,是人工智能学科领域广泛应用的程 序设计语言
AutoLISP嵌套于AutoCAD内部,是LISP语言与AutoCAD有机结合 的产物
lisp编程实例 )

Visual LISP 编程应用实例集一、 计算类程序1.计算阶剩值n! (注意:采用了递归方式)(defun jsen (n)(if (= n 0) 1 (* n (jsen (1- n)))));2.迭代计算(013=--x x)(defun ddai (x) (setq x1 0 x2 x e 1.0e-5 i 0)(while (> (abs (- x2 x1)) e) (setq x1 x2) (setq x2 (expt (+ x1 1) (/ 1 3.0))) (setq i (1+ i)));while (print "x=") (princ x2) (print "i=") (princ i)(princ));end3.一元二次方程求解(02=++c bx ax )(defun px2 (a b c)(setq d (- (expt b 2.0) (* 4 a c)))(cond ((< d 0) (prompt "\nNo root!"))((= d 0) (progn (setq x (/ b (* -2.0 a))) (prompt "\nOne root! x=") (princ x))) ((> d 0) (progn (setq x1 (/ (- (sqrt d) b) (* 2.0 a)) x2 (/ (+ (sqrt d) b) (* -2.0 a))) (prompt "\nTwo root! x1=") (princ x1) (prompt " x2=") (princ x2))));cond (princ));end4.成绩分析统计注意:使用该程序前须将全班成绩输入一个数据文件中保存,格式为(78 89 67 ….) (defun sjfx (fname)(setq f (open fname "r")) (setq lb nil) (while (setq sd (read-line f)) (setq lb (append lb (read sd)))) (close f) (setq xsum 0) (foreach x lb (setq xsum (+ x xsum))) (setq n (length lb) xb 0) (setq xbar (/ xsum (* 1.0 n))) (foreach x lb (setq xb (+ xb (* (- x xbar) (- x xbar))))) (setq xbzc (sqrt (/ xb (* 1.0 n)))) (repeat 18 (terpri))(prompt "************ 统计结果 ******************") (terpri)(prompt (strcat " 全班总平均分数 X=" (rtos xbar 2 3))) (terpri)(prompt (strcat " 标准差 δ=" (rtos xbzc 2 3))) (terpri)(prompt (strcat " Total number: N=" (rtos n 2 0))) (terpri)(prompt "****************************************") (terpri)(princ));end二、数据检索类1.根据计算模数检索标准模数值(假定mc 为1~10之间的任意值,以实参代入) (defun jsm (mc)(setq ml '(1 1.25 1.5 2 2.5 3 4 5 6 8 10)) (setq m 0 n 0)(while (< m mc) (setq m (nth n ml) n (1+ n)));while(prompt (strcat "\nm=" (rtos m 2 1)))(princ));end2.检索一类数据文件(一类数据文件必须存在,且数据格式必须统一) (defun js1 (fname kd / ft nt j x)(setq f (open fname "r")) (setq ft (read (read-line f)) nt (read (read-line f)))(while (/= kd (car nt)) (setq nt (read (read-line f)))) ;while(setq j -1) (repeat (length nt) (setq j (1+ j) x (nth j ft)) (set x (nth j nt)));reapeat(close f) nt);end3.检索二类数据文件(二类数据文件必须存在,且数据格式必须统一)(defun js2 (fname kd / ft nt j x)(setq f (open fname "r")) (setq ft (read (read-line f)) nt (read (read-line f)))(while (or (<= kd (car nt)) (> kd (cadr nt))) (setq nt (read (read-line f))));while(setq j -1) (repeat (length nt) (setq j (1+ j) x (nth j ft)) (set x (nth j nt)));repeat(close f) nt);end三、参数化绘图类1.绘制正弦曲线函数y=sinx (注意:计算数据存放在表变量lpt中)(defun ds (/ x0 xe x y pt)(setq bp (getpoint "\n给出基点:"))(command "ucs" "o" bp) (setq scx 10 scy 20) (setq x0 0 xe (* pi 2) x 0 y 0) (setq step (/ xe 180.0)) (while (<= x0 (* scx xe)) (setq y (* scy (sin x))) (setq lpt (append lpt (list (list x0 y))))(setq x0 (+ x0 (* scx step)) x (+ x step)));while(setq lpt (append lpt (list (list (* scx xe) 0))))(command "leader" (list (+ (* scx xe) 10) 0) "0,0" "" "" "n")(command "leader" (list 0 (+ scy 10)) "0,0" "" "" "n")(command "pline") (foreach pt lpt (command pt)) (command "")(princ));end2.装有键的轴或孔的图形绘制(注:平键数据存于二类数据文件jc.dat中)(defun jcz (d flag / x1 x2 x cp pt1 pt2 pt3 pt4 t1)(if (not js2) (load "d:/cad_1/js2")) (js2 "d:/cad_1/jc.dat" d)(initget 6) (setq cp (getpoint "\nCenter point:")) (command "ucs" "o" cp)(setq x1 (expt (* 0.5 d) 2.0) x2 (expt (* 0.5 b) 2.0)) (setq x (sqrt (- x1 x2)))(if (= flag 1) (setq t1 tz) (setq t1 (* -1 tk)))(setq pt1 (list x (* 0.5 b)) pt2 (list (- (* 0.5 d) t1) (* 0.5 b))pt3 (polar pt2 (* 1.5 pi) b) pt4 (polar pt1 (* 1.5 pi) b))(command "pline" pt1 "a" "ce" "0,0" pt4 "l" pt3 pt2 pt1 "")(if (= flag 1) (command "hatch" "u" 45 4 "" "l" "")) (command "layer" "s" "center" "" "" "") (command "line" (polar '(0 0) pi (+ 3 (* 0.5 d))) (polar '(0 0) 0 (+ 3 (* 0.5 d))) "")(command "line" (polar '(0 0) (* 0.5 pi) (+ 3 (* 0.5 d))) (polar '(0 0) (* 1.5 pi) (+ 3 (* 0.5 d))) "") (command "layer" "s" 0 "" "" "") (princ));end3.绘制阴阳图形(defun yinyang (r)(setq bp (getpoint "\nEnter center point:")) (command "color" 2) (command "circle" bp r) (command "pline" (polar bp (* 0.5 pi) r) "a" bp (polar bp (* 1.5 pi) r) "")(command "bhatch" "p" "s" (polar bp (* 0.5 pi) (* 0.5 r)) "") (command "color" 1) (command "bhatch" "p" "s" (polar bp (* 1.5 pi) (* 0.5 r)) ""));end4.绘制一个五角星图案(defun star_5 (r)(command "color" 1) (setq cp (getpoint "\nCenter point:"))(setq p t1 (polar cp (* 0.017453 18) r) pt2 (polar cp (* 0.017453 54) r) p2 (polar cp (* 0.5 pi) r)) (setq p1 (inters cp pt2 pt1 (polar pt1 pi r)) p3 (polar cp (* 0.017453 126) (distance cp p1))) (command "pline" cp p1 p2 p3 cp p2 "") (setq s (ssadd (entlast)))(command "bhatch" "p" "s" (polar cp (* 0.017453 70) (* 0.2 r)) "") (setq s (ssadd (entlast) s)) (command "color" 2) (command "bhatch" "p" "s" (polar cp (* 0.017453 95) (* 0.2 r)) "") (setq s (ssadd (entlast) s))(command "array" s "" "p" cp 5 "" "")(princ));end5.绘制图框(n=0,1~5)(defun tk (n)(setq lpt '(1189 841 594 420 297 210 148))(setq l (nth n lpt) b (nth (+ n 1) lpt))(if (< n 3) (setq c 10) (setq c 5))(command "rectangle" '(0 0) (list l b))(command "rectangle" (list 25 c) (list (- l c) (- b c))));end6.绘制参数曲线x=sin2a, y=sin5a [0~2pi](注意:采用了递归方式)(defun draw_xy ()(setq bp (getpoint "\nEnter base point:"))(command "ucs" "o" bp)(command "pline" (draw_xy_aux 0)));main;--------------------------------------------------(defun draw_xy_aux (a)(cond ((> a (* 2 pi)) (command "0,0" "" "ucs" "w"))(t (command (list (sin (* 2.0 a)) (sin (* 5.0 a))))(draw_xy_aux (+ a 0.05))));cond);end7.绘制参数曲线x=sin5a.cosa, y=sin5a.sin4a(注意:采用了数据文件读、写方式)(defun qx_xy ()(setq f (open "qx.dat" "w")) (setq a 0)(while (< a (* 2 pi)) (setq x (* (sin (* 5 a)) (cos a)) y (* (sin (* 5 a)) (sin (* 4 a))))(princ x f) (princ "," f) (princ y f) (princ "\n" f) (setq a (+ a 0.05)));while(princ "0,0" f) (close f)(draw_qx) (princ));main;-------------------------------------------------(defun draw_qx ()(setq bp (getpoint "\nEnter base point:"))(command "ucs" "o" bp "pline")(setq f (open "qx.dat" "r"))(while (setq pt (read-line f)) (command pt))(close f)(command "" "ucs" "w")(princ));end8.绘制由方程y=cos(0.9x)产生的图形(注:计算数据存放于表变量lpt中)(defun c:spr (/ cp lpt x)(setq cp (getpoint "\nCenter point:"))(setq x 0 lpt nil)(repeat (fix (1+ (/ (* 20 pi) 0.2)))(setq lpt (append lpt (list (polar cp x (cos (* 0.9 x))))))(setq x (+ x 0.2)));repeat(setq lpt (append lpt (list (polar cp (* 20 pi) 1) "")))(command "pline")(foreach pt lpt (command pt))(princ));end四、对话框编程实例1.定制对话框zdbx:dialog{label="带圆正多边形";:row{:boxed_column{:edit_box{label="边数";key="number";value=6;}:edit_box{label="半径";key="rad";value=20;}}:boxed_column{:radio_button{label="内接圆";key="nq";}:radio_button{label="外切圆";key="wq";value=1;}}}ok_cancel;}2.程序驱动(defun dbx ()(setq id (load_dialog "e:/jscad/zdbx"))(if (< id 0) (exit))(if (not (new_dialog "zdbx" id)) (exit))(action_tile "number" "(set_tile $key $value)")(action_tile "rad" "(set_tile $key $value)")(action_tile "nq" "(setq fg 1)")(action_tile "wq" "(setq fg 0)")(action_tile "accept" "(qsj) (done_dialog)")(action_tile "cancel" "(setq what -1) (done_dialog)")(start_dialog)(unload_dialog id)(if (> what 0) (draw_zdbx n r flag)));end;----------------------------(defun draw_zdbx (n r flag)(setq bp (getpoint "\nBase point:"))(command "circle" bp r)(command "polygon" n bp flag r));---------------------------(defun qsj ()(setq n (atoi (get_tile "number")))(setq r (atof (get_tile "rad")))(if (= fg 1) (setq flag "i") (setq flag "c"))(setq what 1));end五.局部菜单设计编程实例//***MENUGROUP=用户菜单***POP1[用户菜单][--][->平键联接][圆头平键]^c^c(if (not aj) (load "d:/cad_1/aj")) (aj)[半圆头键]^c^c(if (not bj) (load "d:/cad_1/bj")) (bj)[方型平键]^c^c(if (not cj) (load "d:/cad_1/cj")) (cj)[键槽轴面]^c^c(if (not jcz) (load "d:/cad_1/jcz")) (jcz 1)[<-键槽孔面]^c^c(if (not jcz) (load "d:/cad_1/jcz")) (jcz 0)[~--][->图纸幅面][A0幅面]^c^crectangle 0,0 1189,841 rectangle 25,10 1179,831[A1幅面]^c^crectangle 0,0 841,594 rectangle 25,10 831,584[A2幅面]^c^crectangle 0,0 594,420 rectangle 25,10 584,410[A3幅面]^c^crectangle 0,0 420,297 rectangle 25,10 410,287[A4幅面]^c^crectangle 0,0 297,210 rectangle 25,5 287,205[<-A5幅面]^c^crectangle 0,0 210,147 rectangle 25,5 200,142[~--][标题栏]^C^C(command "insert" "d:/cad_1/btl" pause "" "" pause) [粗糙度]^C^C(command "insert" "d:/cad_1/czd1" pause "" "" pause) [基准符号]^c^c(command "insert" "d:/cad_1/jzfh" pause "" "" pause) [清屏幕]^c^c(if (not cls) (load "d:/cad_1/cls")) cls;[--][圆多边形]^C^C(if (not dbx) (load "e:/jscad/zdbx")) (dbx)[--]---------------------------------------------------------------------------------------------------------------- (说明:该程序仅用于《CAD软件二次开发》课程学习参考和上机训练,不得随意传抄)梯形♦(defun dytx (sd xd gd)♦(setq bp (getpoint "\nEnter base point:"))♦(command "ucs" "o" bp)♦(setq p1 (list (* 0.5 (- xd sd)) gd)♦p2 (polar p1 0 sd)♦p3 (list xd 0))♦(command "pline" "0,0" p1 p2 p3 "c")♦(command "ucs" "w"));endW五角星(defun wjx (r)(setq cp (getpoint "\n指定中心点:"))(setq p1 (polar cp (* 0.5 pi) r)p2 (polar cp (* 0.017453 162) r)p3 (polar cp (* 0.017453 234) r)p4 (polar cp (* 0.017453 306) r)p5 (polar cp (* 0.017453 18) r))(setq p12 (inters p1 p3 p2 p5)p23 (inters p1 p3 p2 p4)p34 (inters p2 p4 p3 p5)p45 (inters p1 p4 p3 p5)p15 (inters p1 p4 p2 p5))(command "pline" p1 p12 p2 p23 p3 p34 p4 p45 p5 p15 "c")(command "circle" cp r))鼓形(defun c:gx ()(setq c (getpoint "input a point:"))(command "ucs" "o" c)(setq h (getreal "input h"))(setq r (getreal "input r"))(setq p1 (list (sqrt (- (* r r) (* h h)) )h))(setq p2 (list (- 0 (sqrt (- (* r r) (* h h)) ))h))(setq p3 (list (- 0 (sqrt (- (* r r) (* h h)) ))(- 0 h)))(setq p4 (list (sqrt (- (* r r) (* h h)) )(- 0 h)))(command "arc" p4 "en" p1 "r" r)(command "arc" p2 "en" p3 "r" r)(command "line" p1 p2"")(command "line" p4 p3""))例子编程如下:(defun bolt (F b) (setq d1min (sqrt (/ (* 4 f) (* pi b)))) (princ “\n 松螺栓最小直径d1=”) (princ d1min) (princ));endCommand:(bolt 5800 180)返回:松螺栓最小直径d1=6.4052♦ 复选框:(Toggle/CheckBox)♦ 单选按钮(Radio_Button)♦ 选择按钮(Button)♦ 编辑框(Edit_Box)♦ 列表框(List_Box)♦ 下拉式列表框(Popup_List)♦ 滑块(Slider)♦ 图像(Image)或图像按钮(image_button)♦ 说明文字(Text):retirement_button{label = "设计计算";key = "accept";is_default = true;}♦ dxan:dialog{][41σπF d ≥♦label="确定图纸幅面";♦:boxed_radio_row{label="幅面规格";♦:radio_button{label="A0"; key="a0"; }♦:radio_button{label="A1"; key="a1"; }♦:radio_button{label="A2"; key="a2"; }♦:radio_button{label="A3"; key="a3"; }♦:radio_button{label="A4"; key="a4"; }♦:radio_button{label="A5"; key="a5"; value=1;}♦}♦ok_cancel;♦}zcl:dialog{label="渐开线直齿圆柱齿轮设计";:row{:list_box{label = "模数(mm)";key="m_number";list="1.25\n1.5\n2\n2.5\n3\n4\n5\n6\n8\n10\n12\n16\n20\n25\n32\n40\n50";value=2;height=5;}:spacer{width=2;}:boxed_column{:edit_box{label=" 齿数&z";key="z_number";}:edit_box{label="变位系数x";key="x_number";value=0;} :edit_box{label="顶高系数ha*";key="ha*";value=1.0;} :edit_box{label="顶隙系数c*";key="c*";value=0.25;}}}ok_cancel;}。
基于VisualLisp语言斜坡道三维设计系统开发

基于VisualLisp语言斜坡道三维设计系统开发摘要:通过分析斜坡道参数,可视化、智能化是CAD领域的主要研究方向,将斜坡道开拓设计与CAD技术的合理结合是矿山三维设计的基础。
根据《有色金属采矿设计规范》(GB 50771-2012)、本公司多年的设计经验及各大矿山实际使用情况,对斜坡道各参数进行了研究与分析,以实现参数化与自动化设计目标,最终形成可参数化三维设计的斜坡道设计系统。
关键词:CAD;VisualLisp语言;斜坡道三维设计;系统开发1.1.1 斜坡道及其设计参数斜坡道是近几年在矿床开拓过程中被广泛使用的一种开拓方式,它是伴随着井下无轨设备的发展和应用而产生的。
可视化、智能化是CAD领域的主要研究方向,将斜坡道开拓设计与CAD技术的合理结合是矿山三维设计的基础。
根据设计经验及矿山使用总结,斜坡道设计主要参数如图1,主要包括起始点坐标P1,直线段坡度i0,开口缓坡段长度l1及坡度i1,弯前缓坡段长度l2及坡度i2,转弯段半径R及坡度i3。
根据规范直线段坡度i0“于运输矿石时不宜大于12%,用于运输设备材料时不宜大于15%;弯道坡度应适当降低”,开口缓坡段长度l1和弯前缓坡段长度l2根据运行设备长度确定,以保证设备能安全、便捷转弯进入斜坡道开口或弯道为宜。
以上两者对应缓坡段坡度i1、i2根据矿山实际一般不大于3%,以保证设备能安全、便捷转弯进入斜坡道开口或弯道为宜。
转弯段半径R根据运输设备“大型无轨设备通行的斜坡道干线转弯半径不宜小于20m,阶段斜坡道转弯半径不宜小于15m;中小型无轨设备通行的斜坡道转弯半径不宜小于10m;曲线段外侧应抬高,变坡点连接曲线可采用平滑竖曲线”,转弯段坡度i3可根据实际设置,不应大于直线段坡度,越小设备运行越便利。
图1 斜坡道设计参数1.1.2 功能介绍1)运行程序输入命令“xd”或通过对应菜单运行程序。
2)参数初始化根据提示按空格进入设计或输入“y”进行斜坡道参数设置,如图2,程序给出了默认参数,可根据需要进行调整,需要注意的是,在调整过程需对每个参数进行点击确认,坡度负数为向下。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
(defun DONE ( ) (princ "\nbye! ") ) DONE
(prompt "The value is 127.") (DONE) The value is 127 bye!
C:XXX 函数
为 AutoCAD 添加新命令或重定义现有的命令 定义的函数可以象内置的 AutoCAD 命令一样在 AutoCAD 命令行提示中使用 (defun C:HELLO () (princ "Hello world. \n") (princ))
LISP作为一个完整的集成开发环 Visual LISP作为一个完整的集成开发环 IDE),具有自己的窗口和菜单, ),具有自己的窗口和菜单 境(IDE),具有自己的窗口和菜单,但它并 不能独立于AutoCAD运行。当用户从Visual AutoCAD运行 不能独立于AutoCAD运行。当用户从Visual IDE中运行AutoLISP程序时 中运行AutoLISP程序时, LISP IDE中运行AutoLISP程序时,经常需要与 AutoCAD图形交互或在命令窗口响应程序提示 图形交互或在命令窗口响应程序提示。 AutoCAD图形交互或在命令窗口响应程序提示。
LISP开发 开发
LISP是 Processor(表处理程序)的缩写。 LISP是List Processor(表处理程序)的缩写。 AutoLISP是人工智能语言CommonLISP的简化版本 是人工智能语言CommonLISP的简化版本, AutoLISP是人工智能语言CommonLISP的简化版本,作 为通用LISP语言的一个小子集,AutoLISP严格遵循其 LISP语言的一个小子集 为通用LISP语言的一个小子集,AutoLISP严格遵循其 语法和惯例,但又添加了许多针对AutoCAD的功能。 AutoCAD的功能 语法和惯例,但又添加了许多针对AutoCAD的功能。 Autodesk公司在 公司在AutoCAD 2.1版引入AutoCAD作为应用 版引入AutoCAD Autodesk公司在AutoCAD 2.1版引入AutoCAD作为应用 程序编程接口(API),用于扩展和自定义AutoCAD ),用于扩展和自定义AutoCAD功 程序编程接口(API),用于扩展和自定义AutoCAD功 借助AutoLISP AutoLISP, 能。借助AutoLISP,用户可以用适合编写图形应用程 序的强大的高级语言来编写宏程序和函数, 序的强大的高级语言来编写宏程序和函数,并开发各 种软件包。AutoLISP易于使用 并且非常灵活, 易于使用, 种软件包。AutoLISP易于使用,并且非常灵活,多年 来一直是自定义AutoCAD的标准。 AutoCAD的标准 来一直是toLISP 函数语法的描述遵循如下惯例: 函数语法的描述遵循如下惯例:
函数的有效和无效调用: 对 foo 函数的有效和无效调用: 有效和无效的函数调用样例 有效调用 无效调用 13) (foo "catch") (foo 44 13) 22) 13) (foo "catch" 22) (foo "fi" "foe" 44 13) 31) (foo "catch" 22 31) (foo)
;绘制路径边界轮线 (defun drawout() (command "pline" (setq p(polar sp angm90 hwidth)) (setq p(polar p pangle plength)) (setq p(polar p angp90 width)) (polar p (+ pangle (dtr 180)) plength) "close" ;给Pline命令发送字符串Close ) )
Autolisp数据类型 Autolisp数据类型
整数/实数 字符串 整数 实数/字符串 实数 Autolisp的表是在括号中以空格分割的一组相关值 的表是在括号中以空格分割的一组相关值。 表:Autolisp的表是在括号中以空格分割的一组相关值。 AutoCAD将二维点表示为两个实数组成的表 将二维点表示为两个实数组成的表。 AutoCAD将二维点表示为两个实数组成的表。 2.0) 例(1.0 1.0 2.0) this” that that” those those”) (“this “that “those ) here”) (1 “here ) here 选择集:选择集是包含一个或多个对象(图元)的组。 选择集:选择集是包含一个或多个对象(图元)的组。 用户可以通过 AutoLISP 例程交互地将对象添加到选 择集中,或从选择集中删除对象。 择集中,或从选择集中删除对象。
常用函数
4.getangle: 等待用户输入角度, 4.getangle: 等待用户输入角度,并以弧度值返回用户 输入的角度值 (setq an(getangle)) 5.polar函数: polar函数 5.polar函数:用一个给定角度和一个给定的在该角度方 向的距离来确定一个新点 向的距离来确定一个新点 (polar pt1 ang dist) (setq pt2 (polar pt1 ang dist)) (setq pt3 (polar '(3.0 2.5) ang dist)) 6.getint:等待用户输入一整数 6.getint:等待用户输入一整数 (setq numx (getint)) 类似的getstring getreal等 类似的getstring getreal等 7.setvar gervar函数 setvar和 函数: 7.setvar和gervar函数:给一个系统变量赋值 (setvar "mirrtext" 0) (getvar "mirrtext")
R14开始 开始, LISP被引入到 从AutoCAD R14开始,Visual LISP被引入到 AutoCAD中 它增强并扩展了AutoLISP语言, AutoLISP语言 AutoCAD中,它增强并扩展了AutoLISP语言,可以通过 Automation接口与对象交互 接口与对象交互, Microsoft ActiveX Automation接口与对象交互,并 扩展了AutoLISP响应事件的能力。作为开发工具, AutoLISP响应事件的能力 扩展了AutoLISP响应事件的能力。作为开发工具, LISP提供了一个完整的集成开发环境 IDE), 提供了一个完整的集成开发环境( Visual LISP提供了一个完整的集成开发环境(IDE), 包括编译器、调试器和其他工具, 包括编译器、调试器和其他工具,可以提高自定义 AutoCAD的效率 另外, 的效率。 LISP提供了发布用 AutoCAD的效率。另外,Visual LISP提供了发布用 AutoLISP编写的独立应用程序的工具 编写的独立应用程序的工具。 LISP没 AutoLISP编写的独立应用程序的工具。Visual LISP没 有任何特殊的硬件需求,能运行AutoCAD AutoCAD系统即可运行 有任何特殊的硬件需求,能运行AutoCAD系统即可运行 LISP。 Visual LISP。
;将角度单位度转换为度 (defun dtr(a) (* PI (/ a 180.0)) )
;询问花园路径的输入参数 (defun gpuser() (setq sp(getpoint"\n路径始点:")) (setq ep(getpoint"\n路径终点:")) (setq hwidth (getdist"\n路径宽度:")) (setq trad(getdist"\n圆砖块半径:")) (setq tspac(getdist"\n砖块间隙:")) (setq pangle(angle sp ep)) (setq plength(distance sp ep)) (setq width(* 2 hwidth)) (setq angp90(+ pangle(dtr 90))) (setq angm90(- pangle(dtr 90))) )
AutoLisp变量 AutoLisp变量
特殊变量: 特殊变量: NIL变量 没有指定值的变量为NIL 变量: NIL, NIL变量:没有指定值的变量为NIL,此时 变量并不占存储空间。 变量并不占存储空间。
预定义变量: 预定义变量: PI 3.14159 T 用作非 Nil 值
定义函数
用Defun定义函数 Defun定义函数 defun 函数可将一组表达式组合到一个函数或命 令中。 令中。 ( defun symbol_name ( args / local_variables ) expressions )
;按给定的砖块间隙沿路径方向铺设一行块 (defun draw(pd offset) (setq pfirst (polar sp pangle pd)) (setq pctile (polar pfirst angp90 offset)) (setq pltile pctile) (while(<(distance pfirst pltile) (- hwidth trad)) (command "circle" pltile trad) (setq pltile (polar pltile angp90 (+ tspac trad trad))) ) (setq pltile (polar pctile angm90 (+ tspac trad trad))) (while(<(distance pfirst pltile) (- hwidth trad)) (command "circle" pltile trad) (setq pltile (polar pltile angm90 (+ tspac trad trad))) )