Introduction to AutoLISP
AutoLISP is a programming language primarily used for automating tasks and creating custom functions within Autodesk’s AutoCAD software. It is a dialect of the LISP (LISt Processing) programming language and is specifically tailored for use in the AutoCAD environment. AutoLISP allows you to write scripts, macros, and custom commands that can greatly enhance your productivity when working with AutoCAD.
Here’s a brief introduction to some fundamental AutoLISP concepts:
Print Statement: The print
statement in AutoLISP is used to display text or values to the command line within AutoCAD. For example, to print the message “Hello, AutoLISP!” to the command line, you would use the following code:
When you execute this code, you’ll see the message “Hello, AutoLISP!” displayed in the command line area of AutoCAD.
Prompting for User Input: AutoLISP programs often interact with the user by prompting for input. The getstring
function is commonly used for this purpose. It allows you to request text input from the user and store their response in a variable. Here’s an example:
(print (strcat “Hello, ” user-input))
In this example, the getstring
function prompts the user to enter their name, and the entered name is then concatenated with “Hello, ” and printed to the command line.
Exiting an AutoLISP Program: To exit an AutoLISP program, you can use the quit
function. This function immediately terminates the execution of the program. Here’s an example of how to use it:
(progn
(prompt “Exiting AutoLISP program.”)
(quit)
)
)
In this code, we first check if a command is currently active (using (getvar "cmdactive")
). If a command is active, we display a message using the prompt
function and then exit the program using quit
.
AutoLISP can be a powerful tool for automating repetitive tasks and creating custom AutoCAD functionality. With these basic concepts, you can start to explore and develop your own AutoLISP programs to streamline your AutoCAD workflow.
Basic Arithmetic Operations
Addition (add): Addition is used to find the sum of two or more numbers. In AutoLISP, you can use the +
operator for addition. For example:
In this code, result
will be assigned the value 8
, which is the sum of 5
and 3
.
Subtraction (subtract): Subtraction is used to find the difference between two numbers. In AutoLISP, you can use the -
operator for subtraction. For example:
In this code, result
will be assigned the value 6
, which is the result of subtracting 4
from 10
.
Multiplication (multiply): Multiplication is used to find the product of two or more numbers. In AutoLISP, you can use the *
operator for multiplication. For example:
In this code, result
will be assigned the value 42
, which is the product of 6
and 7
.
Division (/): Division is used to find the quotient when one number is divided by another. In AutoLISP, you can use the /
operator for division. For example:
In this code, result
will be assigned the value 5
, which is the result of dividing 20
by 4
.
These basic arithmetic operations are fundamental for performing mathematical calculations in AutoLISP programs. You can use them to manipulate numbers and solve various mathematical problems as needed in your AutoCAD automation tasks.
Comparisons
In AutoLISP, you can perform comparisons between values using various operators to determine relationships between them. Here are some common comparison operators:
Less Than (<
): The <
operator checks if one value is less than another. It returns T
(true) if the condition is met, and nil
(false) otherwise. For example:
(print “5 is less than 10”)
)
This code will print “5 is less than 10” because the condition < 5 10
is true.
Less Than or Equal To (<=
): The <=
operator checks if one value is less than or equal to another. It returns T
if the condition is true, and nil
if it’s false. For example:
(print “5 is less than or equal to 5”)
)
This code will print “5 is less than or equal to 5” because the condition <= 5 5
is true.
Greater Than (>
): The >
operator checks if one value is greater than another. It returns T
if the condition is true and nil
if it’s false. For example:
(print “10 is greater than 5”)
)
This code will print “10 is greater than 5” because the condition > 10 5
is true.
Not Equal To (/=
): The /=
operator checks if two values are not equal to each other. It returns T
if they are not equal and nil
if they are equal. For example:
(print “10 is not equal to 5”)
)
This code will print “10 is not equal to 5” because the condition /= 10 5
is true.
These comparison operators are essential for implementing conditional logic in your AutoLISP programs. They allow you to make decisions based on the relationships between values, which is crucial for creating dynamic and responsive code.
Boolean Operations
In AutoLISP, you can perform boolean operations to manipulate and evaluate logical conditions. Here are some common boolean operations:
AND (and
): The and
function evaluates multiple conditions and returns T
(true) only if all the conditions are true. If any of the conditions is false, it returns nil
(false). For example:
(print “Both conditions are true”)
)
This code will print “Both conditions are true” because both conditions within the and
function are true.
OR (or
): The or
function evaluates multiple conditions and returns T
if at least one of the conditions is true. It returns nil
only if all conditions are false. For example:
(print “At least one condition is true”)
)
This code will print “At least one condition is true” because the second condition within the or
function is true.
NOT (not
): The not
function negates a single condition. It returns T
if the condition is false and nil
if the condition is true. For example:
(if (not (= 5 10))
(print "5 is not equal to 10")
)
This code will print “5 is not equal to 10” because the not
function negates the true condition (= 5 10)
.
Boole: The Boole
function performs bitwise logical operations. It is typically used for more advanced bitwise manipulation and is less commonly used for simple boolean operations.
EQ (eq
): The eq
function checks if two values are identical. It returns T
if the values are the same and nil
if they are different. It is used for comparing symbols and memory references.
EQUAL (equal
): The equal
function checks if two values are equal. It is more flexible than eq
and can be used to compare a wider range of data types. It returns T
if the values are equal and nil
if they are different.
These boolean operations are crucial for controlling the flow of your AutoLISP programs and making decisions based on conditions. You can use them in conjunction with conditional statements like if
and cond
to create complex logic and implement various behaviors in your code.
Number Manipulation: Basic
Increment (1+
) and Decrement (1-
):
- The
1+
function is used to increment a numeric value by 1. - The
1-
function is used to decrement a numeric value by 1.
For example:
(setq x (1+ x)) ; Increment x by 1, x will be 6
(setq x (1- x)) ; Decrement x by 1, x will be 5 again
Absolute Value (abs
): The abs
function returns the absolute value of a number, which is the magnitude of the number without regard to its sign. It ensures that the result is non-negative.
(setq absolute-value (abs num)) ; absolute-value will be 10
Fix: The fix
function is used to truncate a floating-point number to an integer by removing the fractional part. It essentially rounds towards zero.
(setq x (fix x)) ; x will be 5 (truncated to an integer)
Float: The float
function is used to convert an integer or a string to a floating-point number. It allows you to work with floating-point values.
(setq float-value (float int-value)) ; float-value will be 10.0 (as a floating-point number)
These basic number manipulation functions are handy when you need to perform simple arithmetic operations, modify numbers, or convert between different numeric types in your AutoLISP programs.
Number Manipulation: Advanced
Angle (angle
): The angle
function returns the angle in radians of a complex number represented in rectangular form. It is commonly used for complex number calculations.
(setq angle-radians (angle complex-number))
Cosine (cos
): The cos
function returns the cosine of an angle in radians.
(setq cosine-value (cos angle-radians))
Sine (sin
): The sin
function returns the sine of an angle in radians.
(setq sine-value (sin angle-radians))
Arc Tangent (atan
): The atan
function returns the arctangent of a number. It is often used to calculate angles.
(setq y 1)
(setq angle-radians (atan y x))
Exponential (exp
): The exp
function calculates the value of the base of natural logarithms (e) raised to the power of a given number.
(setq result (exp exponent)) ; e^2
Natural Logarithm (log
): The log
function computes the natural logarithm of a number.
(setq natural-log (log x)) ; ln(10)
Square Root (sqrt
): The sqrt
function calculates the square root of a number.
(setq square-root (sqrt num)) ; √25 = 5
Exponentiation (expt
): The expt
function raises a number to a specified power.
(setq exponent 3)
(setq result (expt base exponent)) ; 2^3 = 8
GCD (Greatest Common Divisor) (gcd
): The gcd
function returns the greatest common divisor of two or more integers.
(setq b 48)
(setq common-divisor (gcd a b)) ; GCD of 36 and 48 is 12
Remainder (rem
): The rem
function calculates the remainder when one number is divided by another.
(setq divisor 3)
(setq remainder (rem dividend divisor)) ; Remainder of 10 / 3 is 1
These advanced number manipulation functions are useful for solving a wide range of mathematical problems and performing complex calculations in AutoLISP programs.
String Manipulation: Basics
ASCII (ascii
): The ascii
function returns the ASCII code (integer value) of the first character of a string. This is useful when you want to get the ASCII value of a character.
(setq ascii-value (ascii char)) ; ascii-value will be 65 (ASCII code for ‘A’)
CHR (chr
): The chr
function converts an ASCII code (integer) into a character. It’s the reverse of the ascii
function.
(setq character (chr code)) ; character will be “A”
String Case Conversion (strcase
): The strcase
function is used to convert a string to a specified case. You can use it to convert a string to uppercase, lowercase, or title case.
(setq uppercase-string (strcase original-string 1)) ; “HELLO, WORLD!”
(setq lowercase-string (strcase original-string 0)) ; “hello, world!”
String Concatenation (strcat
): The strcat
function is used to concatenate (join) multiple strings together.
(setq str2 “AutoLISP!”)
(setq concatenated-string (strcat str1 str2)) ; “Hello, AutoLISP!”
String Length (strlen
): The strlen
function returns the length (number of characters) of a string.
(setq length (strlen text)) ; length will be 5
Substring (substr
): The substr
function extracts a substring from a given string, starting at a specified position and with a specified length.
(setq substring (substr original-string 1 4)) ; “utoL”
These basic string manipulation functions are essential for working with text data in AutoLISP programs. They allow you to perform operations such as converting case, extracting substrings, finding the length of strings, and more.
String Manipulation: Conversions
Real to String (rtos
): The rtos
function converts a real (floating-point) number to a string. You can specify the format of the string using optional arguments.
(setq str (rtos real-number 2 2)) ; Converts to string with 2 decimal places: “3.14”
Angle to Float (angtof
): The angtof
function converts an AutoCAD angle to a floating-point number in degrees. This is useful for converting AutoCAD angle values into a format that can be used in calculations.
(setq degrees (angtof angle)) ; Converts AutoCAD angle to degrees as a float
Angle to String (angtos
): The angtos
function converts an AutoCAD angle to a string. You can specify the angle format using optional arguments.
(setq angle-string (angtos angle 2 2)) ; Converts AutoCAD angle to string with 2 decimal places: “45.00<deg>”
Integer to String (itoa
): The itoa
function converts an integer to a string.
(setq str (itoa num)) ; Converts integer to string: “42”
String to Integer (atoi
): The atoi
function converts a string containing an integer to an actual integer value.
(setq num (atoi str)) ; Converts string to integer: 123
String to Float (atof
): The atof
function converts a string containing a floating-point number to an actual floating-point number.
(setq num (atof str)) ; Converts string to floating-point number: 3.14
These string conversion functions are useful when you need to work with different data types in your AutoLISP programs or when you need to format and display values as strings. They allow you to seamlessly convert between strings, numbers, and angles as needed.
Introduction to Lists: Basics
Lists are a fundamental data structure in AutoLISP and many other programming languages. In AutoLISP, lists are used to store collections of data, and they can contain various types of elements, including numbers, strings, symbols, and even other lists. Here are some basic list manipulation functions:
List: The list
function is used to create a new list. You can pass multiple elements as arguments to create a list containing those elements.
In this example, my-list
will be assigned a list containing the numbers 1 through 5.
Car: The car
function retrieves the first element (head) of a list. It’s often used to access the first item in a list.
Cdr: The cdr
function retrieves the rest of the list after the first element (tail). It returns a list containing all elements except the first.
Cadr: The cadr
function is a combination of car
and cdr
and is used to access the second element of a list.
Caddr: The caddr
function is a combination of car
, cdr
, and cdr
and is used to access the third element of a list.
Lists can be nested, meaning a list can contain other lists as elements. This nesting allows you to represent structured data in a hierarchical manner. For example:
In this case, nested-list
is a list containing two sublists.
Understanding these basic list functions is crucial for working with complex data structures and navigating through lists in AutoLISP. They form the foundation for more advanced list manipulation and data processing in your programs.
Introduction to Lists: Advanced
Cons: The cons
function is used to add an element to the beginning of a list, effectively creating a new list with the added element.
(setq new-list (cons 1 my-list)) ; Adds 1 to the beginning of my-list
In this example, new-list
will be (1 2 3 4)
.
Append: The append
function is used to concatenate multiple lists together into a single list.
(setq list2 (list 3 4))
(setq combined-list (append list1 list2)) ; Concatenates list1 and list2
combined-list
will be (1 2 3 4)
.
Reverse: The reverse
function returns a new list with the elements of the original list reversed.
(setq reversed-list (reverse my-list)) ; Reverses the order of my-list
reversed-list
will be (3 2 1)
.
Last: The last
function returns the last element of a list.
(setq last-element (last my-list)) ; last-element will be 5
Length: The length
function returns the number of elements in a list.
(setq list-length (length my-list)) ; list-length will be 3
Nth: The nth
function is used to access the nth element of a list, where n is an integer.
(setq third-element (nth 2 my-list)) ; third-element will be “cherry”
Member: The member
function checks if an element is present in a list and returns the sublist starting from that element.
(setq result (member 3 my-list)) ; result will be (3 4 5)
These advanced list functions provide you with powerful tools for manipulating and working with lists in AutoLISP. You can use them to build and modify lists, extract specific elements, and perform various operations on list data structures.
Basic Programming & Control Flow
Defun: The defun
statement is used to define a custom function. It allows you to create your own functions with parameters and a body of code that can be reused throughout your program.
(setq result (+ parameter1 parameter2))
(princ result)
)
Function: The function
statement is used to create a lambda (anonymous) function. Lambda functions are often used as arguments to other functions or stored in variables.
If: The if
statement is used for conditional execution. It evaluates a condition and executes one block of code if the condition is true and another block if it’s false.
(princ “x is less than 10”)
(princ “x is not less than 10”)
)
Cond: The cond
statement is used for multi-way conditionals. It checks multiple conditions sequentially and executes the first block of code where the condition is true.
((< x 10) (princ “x is less than 10”))
((> x 10) (princ “x is greater than 10”))
(T (princ “x is equal to 10 or not a number”))
)
Progn: The progn
statement is used to group multiple expressions together and execute them sequentially. It is often used when you need to execute several statements in a block.
(setq a 5)
(setq b 10)
(princ (+ a b))
)
Repeat: The repeat
statement is used to repeat a block of code a specific number of times.
(princ “Hello, AutoLISP! “)
)
Foreach: The foreach
statement is used to iterate over a list and execute a block of code for each element in the list.
(princ item)
)
These basic programming and control flow constructs are essential for writing structured and logical AutoLISP programs. They allow you to create functions, make decisions based on conditions, and control the flow of your code.
Advanced Programming & Control Flow
Quote: The quote
function is used to prevent the evaluation of an expression. It returns the expression as-is, without any computation.
(setq y (quote x)) ; y will be the symbol ‘x’, not its value
Eval: The eval
function is used to evaluate an expression at runtime. It takes a quoted expression as an argument and computes its value.
(setq y (eval (quote (+ x 3)))) ; y will be 8
Apply: The apply
function is used to call a function with arguments stored in a list. It’s useful when you want to pass a dynamic list of arguments to a function.
(setq result (apply ‘+ args)) ; result will be 6
Lambda: The lambda
function allows you to create anonymous functions (lambda functions). These functions can be assigned to variables or passed as arguments to other functions.
Setq: The setq
function is used to assign values to variables. It allows you to create or update variables.
Set: The set
function is similar to setq
but can be used to assign values to symbol property lists or function definitions.
Boundp: The boundp
function checks if a symbol is bound to a value or if it is unbound (undefined).
(if (boundp ‘x)
(princ “x is bound to a value”)
(princ “x is unbound”)
)
These advanced programming and control flow constructs provide greater flexibility when working with variables, expressions, and functions in AutoLISP. They enable you to create dynamic code, work with lists of arguments, and manipulate symbols and their properties.
User Interaction: Input
get
functions. These functions allow you to prompt users for specific types of input, such as angles, distances, keywords, points, real numbers, strings, and integers. Here are some commonly used get
functions for user interaction:Get Angle (getangle
): The getangle
function allows users to specify an angle by picking two points in the drawing area. It returns the selected angle in radians.
Get Corner (getcorner
): The getcorner
function prompts users to specify a corner point by picking a point in the drawing area. It returns a list containing the X and Y coordinates of the selected point.
Get Distance (getdist
): The getdist
function allows users to specify a distance by picking two points in the drawing area. It returns the selected distance as a real number.
Get Keyword (getkword
): The getkword
function prompts users to enter a keyword from a predefined list. It returns the selected keyword as a string.
Get Point (getpoint
): The getpoint
function allows users to specify a point by picking it in the drawing area. It returns a list containing the X, Y, and Z coordinates of the selected point.
Get Real (getreal
): The getreal
function prompts users to enter a real number. It returns the entered value as a real number.
Get String (getstring
): The getstring
function allows users to input a string. It returns the entered string.
Get Integer (getint
): The getint
function prompts users to enter an integer. It returns the entered value as an integer.
These get
functions are essential for creating interactive AutoLISP programs that respond to user input and allow users to specify parameters or make choices within the AutoCAD environment. They enhance the user experience and make your programs more versatile and user-friendly.
User Interaction: Configurations
Get Filed (getfiled
): The getfiled
function is used to display a file dialog box that allows users to select a file. It returns the selected file’s path as a string.
Get Config (getcfg
): The getcfg
function is used to retrieve configuration settings (system variables) in AutoCAD. It returns the current value of the specified configuration variable.
Set Config (setcfg
): The setcfg
function is used to change the value of a configuration setting (system variable) in AutoCAD.
Get Variable (getvar
): The getvar
function is used to retrieve the current value of an AutoCAD system variable.
Set Variable (setvar
): The setvar
function is used to change the value of an AutoCAD system variable.
Get Environment Variable (getenv
): The getenv
function is used to retrieve the value of an environment variable on the computer where AutoCAD is running.
Set Environment Variable (setenv
): The setenv
function is used to set the value of an environment variable within the AutoCAD session. Note that changes made with setenv
are temporary and do not affect the system environment.
These functions provide a way to interact with configurations, system variables, and environment variables in AutoCAD, allowing you to customize your program’s behavior and access important information about the AutoCAD environment and the user’s system.
Working with Entities in AutoCAD: Basics
Entget (entget
): The entget
function is used to retrieve the properties and data associated with an entity (object) in the drawing. It returns a list of property-value pairs for the specified entity.
In this example, the entsel
function is used to select an entity, and entget
retrieves its properties.
Entlast (entlast
): The entlast
function returns the entity name of the last created or modified entity in the drawing. It’s often used after creating or modifying entities to reference the most recently processed entity.
Entmake (entmake
): The entmake
function allows you to create new entities by specifying a list of property-value pairs in AutoLISP format. It returns the entity name of the newly created entity.
This example creates a new line entity and stores its entity name in new-line
.
Entmod (entmod
): The entmod
function is used to modify the properties of an existing entity. It takes a list of property-value pairs and applies the changes to the specified entity.
(setq updated-data (subst ‘(10 5.0 5.0 0.0) (assoc 10 entity-data) entity-data))
(entmod updated-data)
In this example, the code modifies the position of an entity and uses entmod
to apply the changes.
Entnext (entnext
): The entnext
function is used to iterate through entities in the drawing. It returns the entity name of the next entity in the drawing order.
This code gets the entity name of the entity following the last processed entity.
These basic functions and commands allow you to interact with and manipulate entities in AutoCAD using AutoLISP. You can retrieve entity data, create new entities, modify existing ones, and iterate through entities in the drawing.
Working with Entities in AutoCAD: Advanced
Entdel (entdel
): The entdel
function is used to delete one or more entities from the drawing. You can specify the entity names to be deleted.
Entupd (entupd
): The entupd
function is used to update the display of an entity in the drawing after its properties have been modified. It ensures that the changes are reflected in the drawing.
Entsel (entsel
): The entsel
function is used to interactively select an entity in the drawing. It allows the user to pick an entity, and it returns the selected entity’s entity name.
Nentsel (nentsel
), Nentselp (nentselp
): The nentsel
and nentselp
functions are used to non-interactively select entities based on various filter criteria. Nentsel
returns a list of selected entities, while nentselp
returns the entity name of the selected entity.
(setq first-selected-entity (nentselp))
Handent (handent
): The handent
function is used to retrieve an entity’s handle by specifying its entity name. Handles are unique identifiers for entities.
Textbox (textbox
): The textbox
function allows you to create a text entity with specified properties, such as content, height, and rotation angle.
Trans (trans
): The trans
function is used to apply a geometric transformation to an entity. You can translate, rotate, or scale entities using this function.
(trans last-entity 1 translation-matrix)
These advanced functions and commands provide you with greater control and flexibility for managing entities in AutoCAD using AutoLISP. You can perform tasks such as deletion, updating, interactive and non-interactive selection, handling entities by their handles, creating text entities, and applying transformations to entities.
Selection Sets Management
SSAdd (ssadd
): The ssadd
function is used to add one or more entities to a selection set. You can specify the selection set name and the entity name(s) to be added.
(ssadd ss last-entity) ; Adds the last processed entity to the selection set
SSDel (ssdel
): The ssdel
function is used to remove entities from a selection set. You specify the selection set name and the entity name(s) to be removed.
SSGet (ssget
): The ssget
function is used to create a selection set based on specified criteria, such as entity type, layer, or other properties. It returns the selection set as a list of entity names.
SSGetFirst (ssgetfirst
): The ssgetfirst
function is used to retrieve the first entity in a selection set. It returns the entity name.
SSLength (sslength
): The sslength
function is used to get the number of entities in a selection set.
SSMemb (ssmemb
): The ssmemb
function checks if an entity is a member of a selection set. It returns T
if the entity is in the set, or nil
if it is not.
SSName (ssname
): The ssname
function retrieves the name of an entity in a selection set based on its position in the set.
SSNameX (ssnamex
): The ssnamex
function is used to retrieve the entity name and XData (extended entity data) for an entity in a selection set.
SSSetFirst (sssetfirst
): The sssetfirst
function is used to set the first entity in a selection set. It takes the entity name to be set as the first entity.
Selection set management functions are crucial for organizing and working with specific groups of entities in AutoCAD. They allow you to create, modify, and query selection sets based on your criteria, improving your control and flexibility when working with entities.
Graphics & Display Functions
Graphscr (graphscr
): The graphscr
function sets the graphics screen to a specified screen configuration.
Grclear (grclear
): The grclear
function clears the graphics screen and removes all graphics objects.
Grdraw (grdraw
): The grdraw
function is used to draw graphics objects on the graphics screen. It can draw lines, circles, rectangles, and other shapes.
Grread (grread
): The grread
function reads user input and returns the input as a string. It can be used for text input from the user.
Grtext (grtext
): The grtext
function displays text on the graphics screen at a specified location.
Grvecs (grvecs
): The grvecs
function is used to draw 2D vectors or arrows on the graphics screen. It takes the starting and ending points of the vector and other properties.
Textscr (textscr
): The textscr
function sets the text screen configuration to a specified value.
Redraw (redraw
): The redraw
function forces a redraw of the graphics screen, updating the displayed graphics.
These graphics and display functions allow you to work with the visual aspects of your AutoLISP programs, including drawing graphics, displaying text, and interacting with the user through graphical input and output.
Dictionaries, Tables & Records
Dictadd (dictadd
): The dictadd
function is used to add a new entry (key-value pair) to a dictionary. It takes the dictionary name, key, and value as arguments.
Dictnext (dictnext
): The dictnext
function is used to iterate through the entries in a dictionary. It returns the next key-value pair in the dictionary.
Dictremove (dictremove
): The dictremove
function is used to remove an entry (key-value pair) from a dictionary.
Dictrename (dictrename
): The dictrename
function is used to rename a key within a dictionary.
Dictsearch (dictsearch
): The dictsearch
function is used to retrieve the value associated with a specific key in a dictionary.
Named Object Dictionary (namedobjdict
): The namedobjdict
is a predefined dictionary in AutoCAD that is used to store named objects, such as layers, blocks, and dimension styles.
Tblnext (tblnext
): The tblnext
function is used to iterate through the entries in a table (e.g., layer table, block table). It returns the next table record.
Tblobjname (tblobjname
): The tblobjname
function returns the name of a table entry (e.g., layer name).
Tblsearch (tblsearch
): The tblsearch
function is used to search for a specific entry in a table.
Regapp (regapp
): The regapp
function is used to register a new application name in the “APPID” table. This is often used to define custom object types.
These functions and concepts allow you to work with dictionaries, tables, and records in AutoLISP, providing a way to store and manage additional data related to your AutoCAD drawing, including custom data and object definitions.
File & Memory Management Functions
Open (open
): The open
function is used to open a file for reading or writing. It returns a file descriptor that can be used for subsequent file operations.
Close (close
): The close
function is used to close an open file. It takes a file descriptor as an argument.
Load (load
): The load
function is used to load and execute an external AutoLISP file. It allows you to run code from another file within your current program.
Findfile (findfile
): The findfile
function is used to locate a file in the AutoCAD support file search path. It returns the full path to the file if found.
Autoload (autoload
): The autoload
function is used to specify that an AutoLISP function should be automatically loaded and executed when it’s called for the first time.
Autoarxload (autoarxload
): The autoarxload
function is used to automatically load an ARX (AutoCAD Runtime Extension) module when AutoCAD starts.
Arxload (arxload
): The arxload
function is used to manually load an ARX module at runtime.
Arxunload (arxunload
): The arxunload
function is used to manually unload an ARX module at runtime.
Alloc (alloc
): The alloc
function is used to allocate memory for a new object. It returns a reference to the allocated memory block.
GC (gc
): The gc
function is used to initiate garbage collection, which reclaims memory that is no longer in use, improving memory management.
Mem (mem
): The mem
function is used to measure the amount of free memory available.
Exit (exit
): The exit
function is used to exit AutoCAD. It allows you to programmatically close the AutoCAD application.
(if (string= (strcase response) “YES”)
(progn
(princ “\nExiting AutoCAD…”)
(command “_QUIT”)
)
)
)
These file and memory management functions in AutoLISP provide the capability to work with files, load external code, manage memory, and control the execution and exit of AutoCAD.