Creating Entities

Parent Previous Next

Creating Entities


Basically, there are 3 approaches to create entities, based on pure Lisp :


(command "_line" point1 point2 ...)

using (command) or (vl-cmdf) functions provide the least performance, and additionally have many side-effects : command reactors are called, significant part of UserInterface code is involved which also costs performance, and many system variables have impact on the behaviour;
should only be used when there is no other possibility or when performance does not matter


(entmake definition-data)
(entmakex definition-data)

(entmake) and (entmakex) provide much better performance than (command), and very few system variables have impact here; (entmakex) should be preferred as it immediately returns the name of created entity


(vla-addLine ...)

in most cases, using the COM-based entity creation provides the best performance;
AutoCAD: only in case for very simple entities, where the definition-data-list is very short, (entmake) / (entmakex) might be a little bit faster, but this is likely a rare case
BricsCAD: as BricsCAD COM is faster by factor 3...4 in generally, the (vla-Add<Entity> functions are always significantly faster than any other method


Some background :
using (entmake) and (entmakex) functions use an assoc list - the Lisp engine needs to transform such list into a resbuf list for C/C++ based APIs; there, the resbuf list is then parsed by a DxfIn-like operation to fill the new entity; both stages are heavy operations with lots of loops involved. Additionally, temporary memory needs to be allocated and released, which also reduces performance.
On the opposite, the COM based (vla-add<Entity>) functions directly create the target entity based on the provided parameters, the only overhead is caused by data conversion from Lisp to COM data types.

BricsCAD-specific :
The "Fast-COM" mode for (vla-add<Entity>) is about to be implemented very soon - the COM data and function call marshalling is then bypassed as well, so the overhead is reduced to minimum, and performance of (vla-add<Entity>) functions is then very close to C/C++ code (like BRX and ARX);

Suggestion : as all major CAD systems meanwhile support the (vla-) function family, it is safe to adjust Lisp code to COM style - the performance gain is really significant; as all the vla/vlax/vlr functions become available for Linux/Mac as well, there is no risk for portability.




©  Menhirs NV. All rights reserved.