找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 455|回复: 1

[精彩文萃] The Visual LISP 编辑器介绍

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2016-9-1 00:46:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 newer 于 2016-9-1 00:59 编辑

The Visual LISP Editor - Part 1
This tutorial is a crash course in using the Visual LISP Editor, and is not intended to be detailed or fully comprehensive. The aim is to show you the main functions of the Editor with the intention of getting you up and running as quickly as possible.
Right, enough waffle, let's get started. Fire up AutoCAD and open a new drawing. Now choose Tools

The Visual LISP 编辑器介绍

The Visual LISP 编辑器介绍
AutoLISP

The Visual LISP 编辑器介绍

The Visual LISP 编辑器介绍
Visual LISP Editor from the pull-down menu. If you don't see the pull-down menu, enter menubar at the command prompt and set the value to 1.
The Visual Lisp Editor will open and should look like this :

The Visual LISP 编辑器介绍

The Visual LISP 编辑器介绍
Let's start off by having a look at the Visual LISP Console window :

The Visual LISP 编辑器介绍

The Visual LISP 编辑器介绍
The VLISP Console window is similar in some respects to the AutoCAD Command window, but has a few extra features. You enter text into the Console window following the Console prompt which looks like this :
_$
Type this in the Console prompt and then press "Enter" :
_$ (setq a "Test")
Now type this and again press "Enter" :
_$ a
Your Console window should look like this :

The Visual LISP 编辑器介绍

The Visual LISP 编辑器介绍
To view the value of a variable at the AutoCAD Command prompt, you must precede the variable name with an exclamation mark. ( ! ) In VLISP, you simply type the variable name.
Unlike the AutoCAD Command window, where pressing SPACEBAR causes expression evaluation, text input at the VLISP Console prompt is not processed until you press ENTER. This permits you to do the following in the Console window:
  • Continue an AutoLISP expression on a new line. To continue entering an expression on a new line, press CTRL +ENTER at the point you want to continue.
  • Input more than one expression before pressing ENTER. VLISP evaluates each expression before returning a value to the Console window.
  • If you select text in the Console window (for example, the result of a previous command or a previously entered expression), then press ENTER, VLISP copies the selected text at the Console prompt.
The VLISP Console window and the AutoCAD Command window differ in the way they process the SPACEBAR and TAB keys. In the VLISP Console window, a space plays no special role and serves only as a separator. In the AutoCAD Command window, pressing the SPACEBAR outside an expression causes AutoCAD to process the text immediately, as if you had pressed ENTER.
Using the Console Window History
You can retrieve text you previously entered in the Console window by pressing TAB while at the Console prompt. Each time you press TAB, the previously entered text replaces the text at the Console prompt. You can repeatedly press TAB until you cycle through all the text entered at the Console prompt during your VLISP session. After you’ve scrolled to the first entered line, VLISP starts again by retrieving the last command entered in the Console window, and the cycle repeats. Press SHIFT + TAB to scroll the input history in the opposite direction. For example, assume you entered the following commands at the Console prompt:
(setq origin (getpoint "\nOrigin of inyn sign: "))(setq radius (getdist "\nRadius of inyn sign: " origin))(setq half-r (/ radius 2))(setq origin-x (car origin))(command "_.CIRCLE" origin radius)
To retrieve commands entered in the Console window :
  • Press TAB once. VLISP retrieves the last command entered and places it at the Console prompt :
    _$ (command "_.CIRCLE" origin radius)
  • Press TAB again. The following command displays at the Console prompt :
    _$ (setq origin-x (car origin))
  • Press TAB again. VLISP displays the following command :
    _$ (setq half-r (/ radius 2))
  • Now press SHIFT+ TAB . VLISP reverses direction and retrieves the command you entered after the previous command :
    _$ (setq origin-x (car origin))
  • Press SHIFT+ TAB again. VLISP displays the following command :
    _$ (command "_.CIRCLE" origin radius)
    This was the last command you entered at the Console prompt.
  • Press SHIFT+ TAB again. Because the previous command retrieved was the last command you entered during this VLISP session, VLISP starts again by command you entered in the Console window :
    _$ (setq origin (getpoint "\nOrigin of inyn sign: "))
Note : If you enter the same expression more than once, it appears only once as you cycle through the Console window input history. You can perform an associative search in the input history to retrieve a specific command that you previously entered. To perform an associative search of the Console input history :
  • Enter the text you want to locate. For example, enter (command at the Console prompt :
    _$ (command
  • Press TAB. VLISP searches for the last text you entered that began with (command :
    _$ (command "_.CIRCLE" origin radius)
    If VLISP does not find a match, it does nothing (except possibly emit a beep). Press SHIFT+ TAB to reverse the direction of the associative search and find progressively less-recent inputs.

Interrupting Commands and Clearing the Console Input Area
To interrupt a command entered in the Console window, press SHIFT + ESC. For example, if you enter an invalid function call like the following:
_$ ((setq origin-x (car origin)((_>
Pressing SHIFT + ESC interrupts the command, and VLISP displays an "input discarded" message like the following :
((_> ; <input discarded>_$
If you type text at the Console prompt, but do not press <Enter>, then pressing ESC clears the text you typed. If you press SHIFT + ESC, VLISP leaves the text you entered in the Console window but displays a new prompt without evaluating the text.
If you type part of a command at the Console prompt, but activate the AutoCAD window before pressing <Enter>, VLISP displays a new prompt when you next activate the VLISP window. The text you typed is visible in the Console window history, so you can copy and paste it, but you cannot retrieve the text by pressing TAB , because it was not added to the Console history buffer.
When you're ready, let's continue Part 2.


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 40个

财富等级: 招财进宝

 楼主| 发表于 2016-9-1 00:52:14 | 显示全部楼层
本帖最后由 newer 于 2016-9-1 00:55 编辑

The Visual LISP Editor - Part 2
Right, enough messing about. Let's load some coding. Choose File 0.jpg New File and then copy and paste this coding into the text editor :

(defun C:SLOT ()

  •   (setvar "CMDECHO" 0)
      (setvar "BLIPMODE" 0)
      (setq oldsnap (getvar "OSMODE"))

  •   (setq diam (getdist "\nSlot Diameter : ")
            lngth (getdist "\nSlot Length : ")
      )

  •   (while
        (setq pt1 (getpoint "\nInsertion point:"))
        (setvar "OSMODE" 0)
        (setq pt2 (polar pt1 0.0 (/ (- lngth diam) 2.0))
              pt3 (polar pt2 (/ pi 2.0) (/ diam 4.0))
              pt4 (polar pt3 pi (- lngth diam))
              pt5 (polar pt4 (* pi 1.5) (/ diam 2.0))
              pt6 (polar pt5 0.0 (- lngth diam))
        )

  •     (command "PLINE" pt3 "W" (/ diam 2.0) "" pt4 "ARC" pt5 "LINE" pt6 "ARC"
                 "CLOSE"
        )
        (setvar "OSMODE" oldsnap)
      )                                       ; while
      (princ)
    )
  • The coding should look like this in the text editor :
    1.jpg
    Before we go any further, let's have a wee chat about the colors. As soon as you enter text in the VLISP Console or text editor windows, VLISP attempts to determine if the entered word is a built-in AutoLISP function, a number, a string, or some other language element. VLISP assigns every type of element its own color. This helps you detect missing quotes or misspelled function names. The default color scheme is shown in the following table.
    AutoLISP Language ElementColor
    Built-in functions and protected symbols
    Blue
    Strings
    Magenta
    Integers
    Green
    Real numbers
    Teal
    Comments
    Burgundy, on gray background
    Parentheses
    Red
    Unrecognized items (for example, user variables)
    Black
    You can change the default colors. But, do yourself a favour. Don't!
    Selecting Text
    The simplest method to select text is to double-click your left mouse button. The amount of text selected depends on the location of your cursor.
    • If the cursor immediately precedes an open parenthesis, VLISP selects all the following text up to the matching close parenthesis.
    • If the cursor immediately follows a close parenthesis, VLISP selects all preceding text up to the matching open parenthesis.
    • If the cursor immediately precedes or follows a word, or is within a word, VLISP selects that word.
    Hint : Would you like help on any AutoLisp function? Double-click on the function name to select it, and then select the "Help" toolbar button. Help for the specific function will be displayed.
    To load the "Slot" lisp routine, select the "Load active edit window" toolbar button :
    2.jpg
    This loads your coding into memory. To run the routine, type this at the Console prompt :
    _$ (c:slot)
    The program should now run, switching over to the AutoCAD screen when required. You can also just run a selection of code if you desire. Select the lines of code you would like to run and choose the "Load selection" toolbar button, and then press "Enter."
    3.jpg
    Only the lines of code you selected will be run, Great for debugging.
    Talking about debugging, Place the cursor in front of the (defun C:SLOT () statement and press "F9". This places a "Breakpoint" into your program. Now run the program again. Execution should stop at the Breakpoint mark. Now press "F8". By continuously pressing "F8" you can "single step" through your whole program :
    4.jpg
    Let's go one step further. Select the "diam" variable and then select the "Add Watch" toolbar button :
    5.jpg
    The "Watch" dialog box will appear :
    6.jpg
    Note how the variable "diam" is listed along with it's present value. Repeat this process for all the other variables until the Watch" dialog looks like this :
    7.jpg
    Now run the program again, still "single" stepping through. Notice how the values of the variables change as the program proceeds.
    OK let's liven things up a bit. Select "Ctrl-Shift-F9" to clear all breakpoints. Now select the "Debug" pull down menu and then "Animate". Now run the program again.
    Hey, it's running automatically! Take note of the variables changing in the "Watch" window as the program does it's thing.
    Well that's about it in regards to the Visual LISP Editor. The editor has a lot more functions than I've shown you here, but these I feel, are some of the more important ones to get you started.

    论坛插件加载方法
    发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
    如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
    如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

    GMT+8, 2024-9-24 10:26 , Processed in 0.405351 second(s), 34 queries , Gzip On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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