Text
Screen Functions
Hari
Raya
Sorry. I could not add a
new post to my blog for two weeks. It was not my fault. It has to do
with Hari Raya.
I live in Malaysia. And
you find a lot of Muslims here. They celebrate Ramadan every year.
Ramadan is a month of fasting.
When Ramadan is over, then
we have Hari Raya. It lasts a couple of days, when everybody has a
national holiday.
But the majority of the
people take a holiday. And if they have a shop, they close it. Even
Chinese shops and Indian shops are closed.
I do my Internet in an
Internet cafe. And my Internet cafe was closed too. So I could not
add a new post to my blog.
Don't worry. I keep on
adding new posts to my blog. I didn't give up. I still have a lot
that I want to say.
Text
Screen Functions
In AutoLISP we have the
following functions that can be used for giving an AutoLISP program a
presentation. They are:
- Text screen functions
- Graphical screen
functions
- Text functions
- Conversion functions
Now we are going to talk
about the text screen functions. Later we are going to talk about the
other functions.
(graphscr)
(textscr)
You can switch from the
text screen to the graphic screen with the (graphscr) functions and
go to the text screen with the (textscr) function.
System
Variables
AutoCAD works with system
variables. You can check the value of a system variable with the
following function:
(getvar
<variabele name>)
Examples:
(getvar “dwgname”) TEST
(getvar “cmdecho”) 1
Some system variables are
read only. You cannot change their value. But if you can, you can
change the value with:
(setvar
<variable name> <value>)
Examples:
(setvar “filletrad”
200) 200
(setvar “cmdecho”
0) 0
It is advisable to set the
system variable to its original value after the value has been
changed. This is how it can be done:
(setq ce (getvar
“cmdecho”)
(setvar “cmdecho” 0)
(setvar “cmdecho” ce)
Printing
Data
(princ
<expression> [<file description>])
This function writes the
expression to the text screen and gives as a result the expression.
The expression can be a text or a number.
The file description
argument is optional and is used if the expression is written to an
external file. We will talk about it later.
Examples:
(setq a 123)
(setq b '(a))
(princ 'a) A
(princ a) 123
(princ b) (A)
(princ “Hello”) “Hello”
If the expression is a
text, then control codes can be added to it. The following control
codes are available.
\\ the \ character
\e escape
\n new line
\r return
\t tab
\nnn the character with
the octal code nnn
The PRINC function can
also be used without an argument. Then an empty string is written to
the screen. That is often at the end of a program.
Example:
(defun c:setng ()
(setvar “lunits” 4)
(setvar “blipmode” 0)
(princ)
)
After the AutoLISP program
has been loaded into AutoCAD it is started by typing its name at the
command prompt.
At the end of the AutoLISP
program the command prompt is shown again without any additional
information. There is no 0.
(prin1
<expression> [<file description>])
This function is the same
as the previous function, but control codes are not evaluated.
Examples:
(setq a 123)
(setq b '(a))
(princ 'a) A
(princ a) 123
(princ b) (A)
(princ “Hello”) “Hello”
(print <expression>
<file description>)
This function is the same
as the previous function. But the expression is print on a new line
and after the expression is a tab.
(prompt
<text>)
Now you can only print a
text to the text screen. The function prints the text and gives back
nil.
Example:
(prompt “New
value”) New value
Exercise
For this exercisxe the
REPEAT function is used. Write an AutoLISP program, that draws five
circles with the number of the circle in it.
This is the drawing that
is created by the AutoLISP program.