AutoLISP – Resource code

Under development: Coming in 2027 …

When programming in any programming language, it is often a great advantage if you can reuse previously developed code or make use of code snippets done by other programmers.

I have collected a selection of code snippets and functions that I have enjoyed myself over the years.
These functions should be seen as a total package, as some of the functions are part of other functions.

Block handling functions

blocks_setcolor

Signature
(blocks_setcolor ename option newcolor filterstring)

ename
Type: Ename (entity name)
Name of the entity being queried. The ename must refer to a graphical block reference.

option
Type: Integer 1 or 2 or nil
1: Causes the function to change color for the block reference.
2: Causes the function to change colors for all or some entities (depending on the filterstring argument) in the block definition.
nil: Causes the function to change color for the block reference (like 1).

newcolor
Type: Integer (between 0 and 256) or string “Bylayer” or string “Byblock”
Determines the color to be set.

filterstring
Type: String of the format “LINE;ARC;CIRCLE;LWPOLYLINE;etc.”
Only object types listed in the string will be changed.
If filterstring = nil, all objects in the block definition will be changed.
If filterstring is an empty string or no valid object names are contained in the string, nothing will be changed.
If option is 1, this argument has no meaning.

Example
(blocks_setcolor EN 1 1 nil))

This code will change the color of the block reference represented by the entity name EN. New color will be red = color 1.

(blocks_setcolor EN 2 5 “Line;Arc”))

This code will change the color of all lines and arcs in the block definition.
New color will be blue = color 5.