Most Visual LISP applications aim at creating drawings. Drawings are composed mostly (though not exclusively) by collections of graphic objects (also called entities) located either in ModelSpace, PaperSpace or as part of a Block. Once we master the programming techniques described in Part 2, we can now address how these graphical and non-graphical objects are created using Visual LISP.
This chapter explores the different ways provided by Visual LISP to add both graphic and non-graphic objects to our drawing:
- The command/vl-cmdf Interface,
- The ENTMAKE function,
- ActiveX methods accessible from Visual LISP extensions loaded with vl-load-com,
We have tried to solve the same problems these three different ways so as to appreciate each one’s peculiarities. We believe that the following conclusions can be reached from this.
Command/vl-cmdf.
If the goal is to create entities maintaining an absolute control through our program, with minimal user interaction, this would probably not be the chosen option. The command/vl-cmdf interface is influenced by the drawing environment so much that we cannot be sure that a particular system setting will not make our program fail. But not all programs are like that. In many cases we have a mixture of fully automatic operation with others in which user intervention is sought. And if that is desired, it may be appropriate to invoke one of the commands that the user would be accustomed to. In fact, one of the usual recommendations regarding the design of user communication with our programs is that it should resemble the way native commands operate.
Entmake.
Entmake provides an extremely powerful tool for creating new entities. Control over this process is even higher than what can be achieved with the ActiveX methods. We have seen in the examples given about how to create graphic entities and non-graphical objects with complete independence of the drawing environment’s settings, for example, the current Layer and even the current User Coordinate System. Today we face a situation in which the development of ActiveX has been interrupted so we don’t have methods to create the newer AutoCAD objects. An example of this is subdivision surfaces (MESH entities) that although there are no ActiveX methods to create them, they can be created by entmake, as we will explain in the part of this book devoted to 3D programming.The downside is that it requires a bigger programming effort. The programming style we have been proposing, designing general-purpose functions that can be applied in different programs can be a means of overcoming this difficulty, as we build a library of functions for the kind of applications that we develop.
ActiveX.
Object-oriented programming intends to include in each object the procedures needed to operate on them in our applications without having to program them from scratch. Initially, the number of methods and properties exposed for any object can be overwhelming. And exploring the available documentation requires a skill gained only after a lot of practice.But once we grasp the essential aspects of this way of programming it can be extremely effective. From Visual LISP we can take advantage of this environment even more than using other programming languages, yet it certainly represents a hybrid approach. Personally this does not seem to be a difficulty. This way we have the better of two different worlds, taking from one or the other what best suits our goals and our particular way of approaching programming tasks.Moreover it brings us closer to what is now a standard when dealing with programming using different languages. If transcribing VLISP code to .NET or C++, this programming style is highly portable.
This Chapter includes the following sections:
10.1. Three ways to draw.
10.2. The COMMAND/VL-CMDF interface.
10.3. Creating entities with ENTMAKE..
10.4. Creating complex entities with ENTMAKE.
10.5. Sample program: Defining a Block with ENTMAKE.
10.6. Using Visual LISP in the Block Editor.
10.7. The ActiveX interface.
10.8. Complex objects with ActiveX methods.
10.9. Non-graphic objects.
10.10. Non-graphic objects from ActiveX extensions.
10.11. VLA-Objects and the use of available memory.
10.12. Summary.
Chapter 10 Source code.
Your questions or comments about this Chapter's contents are welcome!
Is it possible to make dynamic blocks with vlisp ?
ReplyDeleteAutoLISP/Visual LISP programs can be excuted within the Block Editor. This is explained in section 10.6 (Using Visual LISP in the Block Editor).
DeleteThe example shown is not a dynamic block. However, Block Editor's own commands can be included in an AutoLISP/Visual LISP program using the command/vl-cmdf interface. Among these commands are BACTION, BCPARAMETER and BPARAMETER, which can be used to set the appropriate actions and constraints.
Chapter 20 includes a sample program (section 20.5) that creates an associative surface that includes parameters that can be modified to change the surface's shape. Section 20.7 demonstrates how this same program can be run within the Block Editor creating a dynamic block that exposes parameters (using BCPARAMETER) that can be modified using the Properties palette.
Creating these dynamic blocks requires a thorough understanding of those commands that are exclusive for this editor and knowing which AutoCAD commands cannot be used within this environment.
To my surprise I found out with the Chapter 20 sample program that certain things that are not admitted as commands can be achieved through Visual LISP. This is the case of the UCS command which is not allowed in the Block Editor, but that can be reproduced with our ax-trans-ucs function.