About

AutoLISP Extended (ALx) Functions

ALx Functions are AutoLISP functions created via the .NET API. Their intention is to provide more powerful applications than vanilla AutoLISP can provide, or sometimes Visual Lisp, while still maintaining the ease-of-use of functional Lisp programming. ALx Functions are NOT intended to replace Visual Lisp.

AutoLISP will always have a place in most AutoCAD development projects which is why most new developers for the program choose this language as their first to learn. The language, while relatively quick to learn, also quickly reveals that it is not as verbose as many modern programming languages. These users may feel betrayed in a sense that perhaps the language cannot perform to their desire. Visual Lisp was intended to fill this gap, but now after many years it is also seen as dying potential since Microsoft's announcement to no longer continue with VBA (the basis for Visual Lisp).

Also, traditional and proponent users of AutoLISP may find that learning a newer and more-complex language can be very difficult thus deterring them from switching away from AutoLISP. These users, while skilled Lispers, may often find themselves even hitting a wall that the capabilities of AutoLISP or Visual Lisp cannot surpass.

ALx Functions were therefore created as a way for Lispers, new or old, to reach new potentials with the language while maintaining the 'easiness' of the language and implementation. With the capabilities of .NET driving ALx, new possibilities await for the AutoLISP language.

Want to contribute?

I am always looking for new ways to grow the ALx Function collection. You can send a proposal by reaching out to me:

Denon Deterding
denon@alxfunctions.com


ALx Functions

AutoCAD
alxa-block-list
alxa-block-list-byname
alxa-cdp-get
alxa-cdp-list
alxa-cdp-remove
alxa-cdp-set
alxa-getradius
Excel
alx-excel-wb-close
alx-excel-wb-get
alx-excel-wb-name
alx-excel-wb-save
alx-excel-wb-set
alx-excel-ws-add
alx-excel-ws-get
alx-excel-ws-list
alx-excel-ws-remove
alx-excel-ws-set
Parse
alx-parse-json2lisp
alx-parse-xml2lisp
Support
alx-help
Web
alx-web-get
alx-web-get-2file


alxa-block-list

Returns a list of all Block names and their corresponding BLOCK_RECORD entities, as dotted-pairs, in the current drawing.

Signature

(alxa-block-list)

No arguments.

Return Values

Type: List, or nil.
Returns list of all Block Name - BLOCK_RECORD Entity dotted pairs if found, or nil if none exist.

Examples

(alxa-block-list)
(("Block 1" . <Entity name: 20b584855b0>) ("Block 2" . <Entity name: 20b58485610>))


alxa-block-list-byname

Returns all entity names for the specified block name in the current drawing.

Signature

(alxa-block-list-byname blockname)

blockname

Type: String
Name of the block whose entities are to be retrieved (NOT case-sensitive).

Return Values

Type: List, or nil.
Returns list of all block reference entity names whose names correspond with the provided blockname, or nil if none are found in drawing.

Examples

(alxa-block-list-byname "Block 1")
(<Entity name: 20b584855b0> <Entity name: 20b58485610>)

(alxa-block-list-byname "Block 2")
(<Entity name: 20b94c0b8a0>)

(alxa-block-list-byname "Block 3")
nil


alxa-cdp-get

Returns a custom drawing property value for the current drawing.

Signature

(alxa-cdp-get propertyname)

propertyname

Type: String
Name of the custom drawing property to be retrieved (NOT case-sensitive).

Return Values

Type: String, or nil.
Returns custom drawing property value as string, or nil if the property is not found.

Examples

(alxa-cdp-list)
(("Name1" . "Value1") ("Name2" . "Value2"))

(alxa-cdp-get "name2")
"Value2"

(alxa-cdp-get "name3")
nil


alxa-cdp-list

Returns a complete list of custom drawing properties for current drawing as name-value dotted pairs.

Signature

(alxa-cdp-list)

No arguments.

Return Values

Type: List, or nil.
Returns list of custom drawing properties as name-value dotted pairs if found, or nil if none exist.

Examples

(alxa-cdp-list)
(("Name1" . "Value1") ("Name2" . "Value2"))


alxa-cdp-remove

Deletes a custom drawing property in the current drawing.

Signature

(alxa-cdp-remove propertyname)

propertyname

Type: String
Name of the custom drawing property to be removed (NOT case-sensitive).

Return Values

Type: T, or nil.
Returns true if the custom drawing property was successfully removed, otherwise nil.

Examples

(alxa-cdp-list)
(("Name1" . "Value1") ("Name2" . "Value2"))

(alxa-cdp-remove "name1")
T

(alxa-cdp-list)
(("Name2" . "Value2"))

(alxa-cdp-remove "name3")
nil


alxa-cdp-set

Sets the value of a custom drawing property in the current drawing. If the property name is not found, a new custom drawing property is created with the provided name.

Signature

(alxa-cdp-set propertyname value)

propertyname

Type: String
Name of the custom drawing property to be updated / created. The name is not case-sensitive if updating an existing property.

value

Type: String
The string value for the provided custom drawing property name.

Return Values

Type: Dotted Pair
Whether an existing property is updated or a new one is created, a dotted pair list with the Name-Value pair will always be returned.

Examples

(alxa-cdp-list)
(("Name1" . "Value1") ("Name2" . "Value2"))

(alxa-cdp-set "name1" "abc")
("Name1" . "abc")

(alxa-cdp-list)
(("Name1" . "abc") ("Name2" . "Value2"))

(alxa-cdp-set "Name3" "Value3")
("Name3" . "Value3")

(alxa-cdp-list)
(("Name1" . "abc") ("Name2" . "Value2") ("Name3" . "Value3"))


alxa-getradius

Returns the radius from a supplied center-point to the user-selected point and provides transient graphics for user.

Signature

(alxa-getradius pt [msg])

pt

Type: List
A 2D or 3D point to be used as the base point in the current UCS.

msg

Type: String
Message to be displayed to prompt the user. If no string is supplied, a default "Specify radius:" message is displayed.

Return Values

Type: Real or nil
A real value will be returned if a radius is selected by the user, otherwise if the user continues with Enter without supplying a radius then nil is returned.

Examples

(alxa-getradius '(1.0 2.0 0.0) "\nPlease enter a radius: ")
Please enter a radius: 5
5.0

(alxa-getradius '(1.0 2.0 0.0))
Specify radius: *Cancel*
nil


alx-excel-range-get

Retrieves the current values from a specified range in the currently active workbook & worksheet as set by alx-excel... functions.

Signature

(alx-excel-range-get strRange)

strRange

Type: String
String representing the range of cells whose values are to be retrieved.

Return Values

Type: List, or nil.
Returns a list lists with data from the provided cell range. The primary list is of n-rows length while each internal list is of n-columns length.

Remarks

Named ranges are accepted.

Also, ranges are allowed to refer to a group of cells not in the active worksheet, as long as they are formatted correctly.

NOTE:
- Empty cells are returned as nil.
- If a cell is calculating an error in Excel, then the string "!ALX!CELL!ERROR!" is returned in its place.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-list)
("Sheet1" "Sheet2")

(alx-excel-ws-get)
"Sheet2"

(alx-excel-range-get "A1:C2")
(("A1" "B1" "C1") ("A2" "B2" "C2"))

;; On Sheet 1, cells A2 & B2 are empty, and cell C2 is currently displaying an error.
(alx-excel-range-get "Sheet1!A1:C2")
((1 2 3) (nil nil "!ALX!CELL!ERROR!"))

(alx-excel-wb-close)
T


alx-excel-range-set

Sets the values of the specified range in the currently active workbook & worksheet as set by alx-excel... functions, to the provided values.

Signature

(alx-excel-range-set strRange lstVals)

strRange

Type: String
String representing the range of cells whose values are to be set.

lstVals

Type: List
A list of lists of AutoLISP values, whose dimensions are equal to the range provided.

Return Values

Type: List, or nil.
Returns the provided list of lists values if successful, otherwise nil.

Remarks

The range dimensions and list dimensions must be equivalent.
For example, if the range "A1:C2" is provided, then the primary list must be of length 2 (rows) and each sub-list must be of length 3 (columns).

Named ranges are allowed.

Also, ranges are allowed to refer to a group of cells not in the active worksheet, as long as they are formatted correctly.

NOTE:
- If a nil value is provided in a list, then that cell will be set to empty in Excel.
- If a string of a correctly-formatted formula is placed in a cell then it will be evaluated within Excel correctly (ex: "=1+2" will return as 3 if retrieved later).

IMPORTANT:
Please note that NO changes will be saved to the excel workbook until the (alx-excel-wb-save) function is called.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-get)
"Sheet1"

(alx-excel-range-get "A1:C2")
(("A1" "B1" "C1") ("A2" "B2" "C2"))

(setq data '((1 2 3.45) (nil "xxx" "=1+2")))

(alx-excel-range-set "A1:C2" data)
((1 2 3.45) (nil "xxx" "=1+2"))

(alx-excel-range-get "A1:C2")
((1 2 3.45) (nil "xxx" 3))

(alx-excel-wb-save)
T

(alx-excel-wb-close)
T


alx-excel-wb-close

Closes the current workbook held by the (alx-excel-wb-set ...) function, if any.

Signature

(alx-excel-wb-close)

No arguments.

Return Values

Type: T, or nil.
Returns T if close was successful, otherwise nil.

Remarks

It is Important to note that NO changes made by any alx-excel... functions to the current workbook will be saved until the (alx-excel-wb-save) function is called.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-get)
"Sheet1"

(alx-excel-range-get "A1:B2")
(("This is cell A1" "This is cell B1") ("This is cell A2 "This is cell B2"))

(alx-excel-range-set "A1:B2" '(("A1" "B1") ("A2" "B2")))
(("A1" "B1") ("A2" "B2"))

(alx-excel-wb-save)
T

(alx-excel-wb-close)
T


alx-excel-wb-get

Gets the full file path + name + extension of the active workbook set by (alx-excel-wb-set ...).

Signature

(alx-excel-wb-get)

No arguments.

Return Values

Type: String, or nil.
Returns the full file path + name + extension of the active workbook set by (alx-excel-wb-set ...), or nil if one is not currently set.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-get)
"Sheet1"

(alx-excel-wb-get)
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-range-get "A1:B2")
(("This is cell A1" "This is cell B1") ("This is cell A2 "This is cell B2"))

(alx-excel-wb-close)
T


alx-excel-wb-name

Gets the file name + extension of the active workbook set by (alx-excel-wb-set ...).

Signature

(alx-excel-wb-name)

No arguments.

Return Values

Type: String, or nil.
Returns the file name + extension of the active workbook set by (alx-excel-wb-set ...), or nil if one is not currently set.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-get)
"Sheet1"

(alx-excel-wb-name)
"My File.xlsx"

(alx-excel-range-get "A1:B2")
(("This is cell A1" "This is cell B1") ("This is cell A2 "This is cell B2"))

(alx-excel-wb-close)
T


alx-excel-wb-save

Saves the active workbook set by (alx-excel-wb-set ...).

Signature

(alx-excel-wb-save)

No arguments.

Return Values

Type: T, or nil.
Returns T if save was successful, otherwise nil.

Remarks

It is Important to note that NO changes made by any alx-excel... functions to the current workbook will be saved until this function is performed.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-get)
"Sheet1"

(alx-excel-range-get "A1:B2")
(("This is cell A1" "This is cell B1") ("This is cell A2 "This is cell B2"))

(alx-excel-range-set "A1:B2" '(("A1" "B1") ("A2" "B2")))
(("A1" "B1") ("A2" "B2"))

(alx-excel-wb-save)
T

(alx-excel-wb-close)
T


alxa-excel-wb-set

Sets (and creates if necessary) an excel workbook as active within the currenet instance of AutoCAD. Once set, the workbook can be manipulated with any corresponding alx-excel-... functions.

Signature

(alxa-excel-wb-set wbPath)

wbPath

Type: String
The full path (including file name and extension) of an Excel workbook. If the file already exists, it is set as the current workbook, otherwise a new Excel file is created with the file name and extension at the provided path.

Return Values

Type: String, or nil
The full path (including file name and extension) of the Excel workbook that was found or created. Otherwise, nil if unsuccessful.

Remarks

Only excel files with the ".xls" and ".xlsx" file extensions are accepted.

No other alx-excel-... fucntions will operate successfully unless a workbook is set.

When a workbook is set to active, it persists across all active drawings in the current AutoCAD session. It is not instantiated on a per-drawing basis.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-get)
"Sheet1"

(alx-excel-range-get "A1:B2")
(("This is cell A1" "This is cell B1") ("This is cell A2 "This is cell B2"))

(alx-excel-wb-close)
T


alx-excel-ws-add

Adds a worksheet with the provided name into the current workbook if it does not already exist.

Signature

(alx-excel-ws-add wsName)

wsName

Type: String
Name of the new worksheet to be added to the current workbook.

Return Values

Type: String, or nil.
Returns the added (or existing) worksheet's name, or nil if unsuccessful.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-list)
("Sheet1")

(alx-excel-ws-add "New Sheet")
"New Sheet"

(alx-excel-ws-list)
("Sheet1" "New Sheet")

(alx-excel-ws-get)
"Sheet1"

(alx-excel-wb-save)
T

(alx-excel-wb-close)
T


alx-excel-ws-get

Gets the currently active worksheet name of the active workbook set by (alx-excel-wb-set ...).

Signature

(alx-excel-ws-get)

No arguments.

Return Values

Type: String, or nil.
Returns the currently active worksheet name of the active workbook set by (alx-excel-wb-set ...), or nil if a workbook is not currently set.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-list)
("Sheet1")

(alx-excel-ws-get)
"Sheet1"

(alx-excel-ws-set "New Sheet")
"New Sheet"

(alx-excel-ws-list)
("Sheet1" "New Sheet")

(alx-excel-ws-get)
"New Sheet"

(alx-excel-wb-save)
T

(alx-excel-wb-close)
T


alx-excel-ws-list

Returns a list of all worksheet names in active workbook set by (alx-excel-wb-set ...) function.

Signature

(alx-excel-ws-list)

No arguments.

Return Values

Type: List
Returns list of strings of all worksheet names in currently active workbook.

Remarks

This function does not return hidden worksheet names.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-list)
("Sheet1")

(alx-excel-ws-set "New Sheet")
"New Sheet"

(alx-excel-ws-list)
("Sheet1" "New Sheet")

(alx-excel-wb-save)
T

(alx-excel-wb-close)
T


alx-excel-ws-remove

Removes a worksheet with the provided name from the current workbook if it exists.

Signature

(alx-excel-ws-remove wsName)

wsName

Type: String
Name of the worksheet to be removed from the current workbook.

Return Values

Type: String, or nil.
Returns the removed worksheet's name, or nil if not found or unsuccessful.

Remarks

If the currently active worksheet is removed, the first worksheet in the workbook is made the active worksheet.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-list)
("Sheet1" "Sheet2")

(alx-excel-ws-get)
"Sheet2"

(alx-excel-ws-remove "Sheet2")
"Sheet2"

(alx-excel-ws-list)
("Sheet1")

(alx-excel-ws-get)
"Sheet1"

(alx-excel-wb-save)
T

(alx-excel-wb-close)
T


alx-excel-ws-set

Sets a worksheet with the provided name in the current workbook as the active worksheet, or creates the worksheet if it does not already exist.

Signature

(alx-excel-ws-set wsName)

wsName

Type: String
Name of the new worksheet to be set current or created and set current.

Return Values

Type: String, or nil.
Returns the newly active worksheet's name (whether new or existing), or nil if unsuccessful.

Examples

(alx-excel-wb-set "c:\\users\\owner\\desktop\\My File.xlsx")
"c:\\users\\owner\\desktop\\My File.xlsx"

(alx-excel-ws-list)
("Sheet1")

(alx-excel-ws-set "New Sheet")
"New Sheet"

(alx-excel-ws-list)
("Sheet1" "New Sheet")

(alx-excel-ws-get)
"New Sheet"

(alx-excel-wb-save)
T

(alx-excel-wb-close)
T


alx-parse-json2lisp

Parses a valid json string to an AutoLISP List.

Signature

(alx-parse-json2lisp json)

json

Type: String
A valid json string.

Return Values

Type: List, or nil.
If the provided json string is valid, then a list is returned with the converted json data.

Remarks

AutoLISP integers are only allowed ranging from -2,147,483,647 to +2,147,483,648 ...if an integer in the json string is outside of this range, then it is returned in the list as a string instead of an integer.

AutoLISP has no equivalent of False, so every False symbol provided in the json string is converted to a nil value.

Examples

(setq jString
  (strcat
    "{"
      "\"name\":\"John\","
      "\"age\":30,"
      "\"height\":1.92,"
      "\"ExtendedData\": {"
        "\"car\":null,"
        "\"hasID\":true,"
        "\"isCriminal\":false,"
        "\"LuckyNumbers\": [ 3, 7, 15 ]"
      "}"
    "}"
  )
)
"{\"name\":\"John\",\"age\":30,\"height\":1.92,\"ExtendedData\": {\"car\":null,\"hasID\":true,\"isCriminal\":false,\"LuckyNumbers\": [ 3, 7, 15 ]}}"

(alx-parse-json2lisp jString)
(("name" . "John") ("age" . 30) ("height" . 1.92) ("ExtendedData" ("car") ("hasID" . T) ("isCriminal") ("LuckyNumbers" 3 7 15)))


alx-parse-xml2lisp

Parses a valid XML string to an AutoLISP List.

Signature

(alx-parse-xml2lisp xml)

xml

Type: String
A valid XML string.

Return Values

Type: List, or nil.
If the provided XML string is valid, then a list is returned with the converted XML data.

Remarks

AutoLISP integers are only allowed ranging from -2,147,483,647 to +2,147,483,648 ...if an integer in the XML string is outside of this range, then it is returned in the list as a string instead of an integer.

AutoLISP has no equivalent of False, so every False symbol provided in the XML string is converted to a nil value.

All attributes within an element have their IDs prefixed with an "@" symbol after conversion.

Examples

(setq xmlString
  (strcat
    "<?xml version=\"1.0\"?>"
    "<catalog>"
      "<book id=\"bk101\">"
        "<author>Gambardella, Matthew</author>"
        "<title>XML Developer's Guide</title>"
        "<genre>Computer</genre>"
      "</book>"
      "<book id=\"bk102\">"
        "<author>Ralls, Kim</author>"
        "<title>Midnight Rain</title>"
        "<genre>Fantasy</genre>"
      "</book>"
    "</catalog>"
  )
)
"<?xml version=\"1.0\"?><catalog><book id=\"bk101\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre></book><book id=\"bk102\"><author>Ralls, Kim</author><title>Midnight Rain</title><genre>Fantasy</genre></book></catalog>"

(alx-parse-xml2lisp xmlString)
(("?xml" ("@version" . "1.0")) ("catalog" ("book" (("@id" . "bk101") ("author" . "Gambardella, Matthew") ("title" . "XML Developer's Guide") ("genre" . "Computer")) (("@id" . "bk102") ("author" . "Ralls, Kim") ("title" . "Midnight Rain") ("genre" . "Fantasy")))))


alx-help

Opens the Compiled HTML Help file for ALX Functions.

Signature

(alx-help)

No arguments.

Return Values

Type: Always returns nil.

Examples

(alx-help)
nil


alx-web-get

Returns the string provided by a web page from making a GET request.

Signature

(alx-web-get url)

url

Type: String
A valid URL to send GET request to.

Return Values

Type: String
If the provided URL string is valid, then the body string of the URL endpoint is returned.

Remarks

This function can most commonly be used to quickly and easily make REST API calls. Below, a good example is shown of how easily an API call can be made and the JSON data returned converted into useful AutoLISP data.

Examples

(setq url "https://jsonplaceholder.typicode.com/todos/1")
"https://jsonplaceholder.typicode.com/todos/1"

(setq data (alx-web-get url))
"{\n  \"userId\": 1,\n  \"id\": 1,\n  \"title\": \"delectus aut autem\",\n  \"completed\": false\n}"

(setq data (alx-parse-json2lisp data))
(("userId" . 1) ("id" . 1) ("title" . "delectus aut autem") ("completed"))


alx-web-get-2file

Creates a file in the specified location, of the returned string provided by the specified web page from making a GET request.

Signature

(alx-web-get-2file url filename)

url

Type: String
A valid URL to send GET request to.

filename

Type: String
Full file path and extension of the file to be created. If a full and correct path is not provided, then the function will attempt to create the file in the location of the current drawing.

Return Values

Type: String
The full file path and extension of the newly created file.

Remarks

If the provided file name already exists, it will be overwritten with the newly returned data.

The example below shows a simple way to save a sample PNG image to the provided location.

Examples

(setq url "https://via.placeholder.com/600/92c952")
"https://via.placeholder.com/600/92c952"

(setq fileName "C:\\users\\owner\\desktop\\600x600_photo.png")
"C:\\users\\owner\\desktop\\600x600_photo.png"

(alx-web-get-2file url fileName)
"C:\\users\\owner\\desktop\\600x600_photo.png"