• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

bookcase of "modules" autolisp

  • Thread starter Thread starter x11start
  • Start date Start date

x11start

Guest
when I was little, there was a toy (which I always dreamed of and never received!), which was composed of many colorful cubes and with electrical contacts on some sides. These cubes contained electrical and electronic circuits, which performed a specific function. By approaching these cubes to each other, it was possible to create devices of a certain complexity, following the instructions of a small manual.
the concept is exactly that of autolisp subs.
Until now, when I wanted to create a new command, I began to open my old list and went to "copy & paste". now I would like to start keeping separate in my "cubes" in single files and create the new command "by assembling" the various cubes by (load"name of thecubo").
This idea of separate files is similar to the approach obtained with projects in visual lisp (prj), however also in that case the files belonging to the project I put them all in a folder and then I rewrite the routines every time.

I would like in this post to start making available a series of "modules" so that they become a "freedom" from which to load the modules (or cubes!) that I need. the advantage is to obtain a result much faster and in being able to improve in later times the single module, propagating the improvement to all the commands that use it.
This involves the need to create very well structured modules, with clear indications of the variables required in input and those that are obtained in output and above all be careful not to vary the n. and the type of variables in input and output, if the previous list is not working. for greater clarity I thought that the outgoing ones, being "globals", I want to mark them with a & in front of the name, so as to recognize them: autolisp unlike other languages does not go much for the subtle on the characters used for the various types of variables!
then start with 2 modules called 'x11:tasto' and 'x11:messaggio' (note the x11 as prefix: it is a small vezzo!), these are used in the command 'choice' and 'choice1', both contained in the 'choice.lsp' file.

Well: I threw the first stone.... to you the task of "lapidarmi" with other modules!
 

Attachments

in this second episode, the main program is selections.lsp that once loaded with (load"selections") ---ipotizing that all files are located in a path recognized by autocad --- then goes launched with:

selezsing for selecting a single object, or with
selezmult for selection of many objects

the first sub proposal is x11:gword contained in the gword.lsp file that serves to enter a letter or a word between those "authorized" by the initget command. It's the classic system to tell autolisp what to do. Unlike x11:key, here it is necessary to enter after the choice also because in this case the choice can be a word (yes/no) and not only a single key. a parameter (bit) allows us to accept or not the answer nothing (to send or space) and to replace the answer nothing with a default value.

the main purpose of this new series of modules, however, is another: the selection of 1 or more entities of the design.

with the sub x11:selsingola contained in the selsingola.lsp file, we are asked to click on a single entity of the drawing: from this will be extracted the data required by a list containing group codes. for example of an entity we may be interested in knowing what layer is located, knowing its color etc.

the sub x11:gword allowed us, for blocks and polylines, to choose if to select the entities "external",

or those found inside, while for other entities, the 2 choices are equal:
in the case of blocks, clicking on any element that is part of it, if the choice was to obtain the external entity, we are returned the name of the block; vice versa we are returned the line, the circle... I mean, that entity we'd get if we exploded the block. by clicking on an attribute we will get the attribute data.

- the outgoing list is something like:
((0 . "line") (8 . "assi") (10 6540.91 6920.91 0.0) (11 2540.91 6920.91 0.0)

the choice of one or the other type, depends on the processing that is intended to be done later.

as an example we have selected a line and used the following group code:

code description found
0 name entity (linea) "line"
8 name of the "assi" layer
10 coord. starting point (6540.91 6920.91 0.0)
11 end-point coord (2540.91 6920.91 0.0)

the sub x11:selezmult contained in the selezmult.lsp file is much more articulated than the previous one, as it allows to choose the objects of the design, with all the modalities provided by the various types of selection: if you do not enter any mode (by sending the request), you can select the entities by clicking individually and adding (or removing) new entities with windows etc. and then accepting with sending; vice versa if the window mode (window) is chosen, we will be asked for the 2 vertices and then we will pass immediately to the processing.
to not further complicate the subrutine (being basically only demonstrative), I did not add a system that created filters of selection of entities or data to be displayed out. This task is entrusted to the user who, if you want filters, assigns values to lstc and lstfilt variables and does it by manually modifying the file. vice versa if these variables have nil value, no filtering will occur.
 

Attachments

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
ciao
Back
Top