|
We need something to work on. Let us create a blank file and type something into it using the editor. The way to do that is to click the "New Include" button on the toolbar:

This brings up a new editor window with an empty file, and we can go ahead typing anything we want. The first thing you have probably noticed about the AnyScript editor is that it recognizes the predefined class names and highlights them automatically. It does this all the time as you are typing, and it is a great help to avoid misspellings that might later lead to annoying syntax errors.
Syntax Highlighting
When you start typing something, the writing color is black. This is the standard color in the editor for things that have not been recognized. For instance, if you start defining a segment, you may type (try it!):
AnySe
And the text remains black until you type the last character of the reserved word:
AnySeg
at which point the text becomes blue. This can be a great help if you are not quite sure about the name of a particular object. You can try typing the different forms of the name, and when you hit the right one, the text turns blue. The editor similarly recognizes comments. If you precede the AnySeg class name with a double-slash, the entire line turns green:
// AnySeg
Please notice that similar to C, C++, Java, and JavaScript you can turn entire blocks of code into a comment by encapsulating it into a pair of /* */ delimiters. Another easy way to temporarily remove and re-activate several lines from the file is to block the text in question and use the two buttons in the toolbar of the Editor window. This automatically places or removes double slashes in front of each line in the block.
Please also notice the so-called Documentation Comments. This is comments using the following syntactical forms: /// ..., /** ... */, ///< ..., and /**< ... */. The Documentation Comments are related to a given object in the model and these comments are treated specially so the information can be accesses more convenniently after loading the model and thereby help the user of a model to understand the model without reading the code. In the editor, the Documentation Comments do however have the same color as other the normal comments. The Documentation Comments' form is similar to other source code systems like JavaDoc, Doxygen, and others.
Automatic Indentation
When developing software that is hierarchical it is customary to indent the code according to the hierarchical level of each line. This greatly improves the legibility. In the AnyScript editor we have decided that the standard indentation for each level is two spaces. The editor automatically keeps track of where you are in the code as defined by the start and end braces, and it helps you make the right indentations as you type. Let us continue the segment definition we started above. Remove any leading double slashes and proceed to type
AnySeg Segment1 = {
and hit the Return key to change line. Notice that the editor automatically indents the next line by two spaces. This is because it has noticed that you have stepped on level down in the hierarchy relative to the first line by the start brace. Every subsequent line you type will begin two spaces to the right of AnySeg. You are not forced to accept this. You can easily backspace to the beginning of the line and start your typing there, if you like that better. You might write something like:
AnySeg Segment1 = { Mass = 1.0;
The editor will discover that you did not like its suggested indentation, so the next line you type will begin at the same character as Mass, and you may proceed to finish the definition of the segment by typing:
AnySeg Segment1 = { Mass = 1.0; Jii = {0.1,0.01,0.1}; };
Auto format
Perhaps you decide at this point that the indentation is better after all. (If you do not decide at this point, you surely will when you have written a few hundred lines and are trying to balance your start and end braces.) So, how can you restore the default indentation? Well, the AnyScript editor has a very nice feature called Auto format. It allows you to block a part of the code or the entire file and indent it in one simple step.
Try highlighting the block you have written , and press Alt-F8. You should get this result:
AnySeg Segment1 = {
Mass = 1.0;
Jii = {0.1,0.01,0.1};
};
This facility is also available in through the pull-down menu Edit->Format Indentation.
If you are ever in a situation where the model will not load and you suspect that you have forgotten a brace somewhere, simply block the entire file and apply Auto format to it. You will usually be able to see by a few glances where the error is located.
You can also manually control the indentation of a block of lines. A highlighted block of text can be indented or unindented in steps of two spaces by pressing Tab or Shift-Tab.
Tree Views
The structure of an AnyScript model is hierarchical. This means that it is obvious to represent the loaded model as a tree, and the system makes extensive use of this representation in all its different window types. If you still have the squat model from the previous lesson open, go to the main file and load it (key F7). You should see a tree at the left hand side of the editor window as in the figure below.

What you see here is the Model Tree, which it the main tree view of AnyBody showing all objects in the loaded model in the structure they are created in the AnyScript code. The Model Tree is in principle available in many of AnyBody's windows, but some of the information is filtered out in some window types to make the tree view practical for specific purposes such as browsing output or operations in the model.
The Editor windows have the complete unfiltered Model Tree, and they can take up a significant space in the Editor window. Therefore, they are by default collapsed to maximize the space for editing and an unfiltered Model Tree is also available on the Main Frame, which is sufficient for most purposes. Multiple Model Trees can, however, be handy when working with large models and browsing for information in different places of the structure; this is the reasons for having the option of opening a Model Tree in the Editor windows. Moreover, the Model Trees in the Editor have to options for interaction with the code of the particular Editor Window, which is not available from the Main Frame Model Tree. You can collapse the tree again after opening it by clicking the X tab on the left hand side of the tree.
We shall not go into details about the functionality in the Model Tree, but notice that right-clicking an object in the Model Tree give you access to these functions. There are two categories of these functions: - Interaction with the AnyScript code such as inserting object name into the code at the place of the cursor
- Class Operations that are operations associated with the AnyScript classes. These cannot be explained in detail here because the follow the classes, but there are a couple of very basic Class Operation that is available to all objects.
In particular notice the Class Operation called Object Description that comprise much practical information for the given object, including the Documentation Comments made by the AnyScript programmer making the model. The Object Description is very useful when browsing the model because it contains active links, which for instance can bring you to the code with single click. The Object Description is considered to be the most fundamental operation in the Model Tree so it will be activated when you double-click any node in the tree.
The Model Tree offers you several options to go from the tree to associated places the AnyScript code. There are, however, also options to go the opposite way, i.e. from the code to the Model Tree. Try right-clicking the code. You will them get a pop-up menu with several editor options. One of these is "Locate in Model Tree". It will probably be greyed, i.e. disabled, because you have not selected anything that can be related to the tree. But if you try highlighting an object name in the code it should become active. Selecting this will bring you to the specific object in the Model Tree. In some cases, there is not a single clear one-to-one correspondance between the code location and the Model Tree. This happens if the code, you look at, is in an include file that have been included several times in the model. In such cases, the Editor will provide you with a list of options to select from.
As you can see, there are also other tree views available. Clicking the Files tab will give you an overview of the model's include file structure. Models in AnyScript are often divided over several files where one main file links to other files, which link on to other files and so on. The links are realized by means of include statements in the AnyScript code:
#include "includefile.any"
The File Tree is very unimpressive in this model because it does not have any include files, but below you see a File Tree from a more complicated model:

The leaves in the tree are marked by two different icons. The icon with the little red # sign points to a place in the model with an include statement. If you double-click such a line you will be taken to the position of the include statement. If you Click the + to the left of the icon, the branch folds out, and you see another icon below without the # sign. If you click this icon, the include file itself opens up in an editor window.
The third tab in the tree view is named Classes. It gives you access to a tree of the predefined classes in the system. From this tree you can insert templates of new objects. This eliminates much of the need to remember the syntax of each object and saves you many lookups in the reference manual. The use of the Classes Tree is described in the Getting Started with AnyScript tutorial.
There are a couple of more tree views. These contains global objects that are available to your code. Global AnyScript constants are listed in one tree and global AnyScript function in another.
Find and Replace
No editor is complete without a find and replace function. The function in the AnyScript editor is not much different from what you find elsewhere. It is accessible through the Edit menu or by the keyboard shortcuts
Ctrl-F for find Ctrl-H for find and replace.
F3 repeats the previous find operation.
Support for External Editors
Some users have very strong preferences when it comes to editors. The AnyBody Modeling System allows you to use any text editor you like to author your models as long as it saves the files on an ascii text format.
The Main file must be open in the AnyBody Modeling system initially to allow compilation. Once you have compiled it, the system remembers the current Main file, and it will re-compile it every time you press F7. This means that you can edit and save any Main or include file by means of an external editor and compile it from inside the AnyBody Modeling System.
So what happens if you have a file open in an AnyBody Editor Window, and you are simultaneously editing it in an external editor? Well, every time you press F7 to compile the model, the system will attempt to save any changed files to pass them on to the compiler from the disk during the compilation. But before the system saves the file, it checks if the file has been updated from elsewhere, for instance from an external editor, and the system will ask you if it is supposed to load the newer file into the AnyBody Editor Window. - If you answer yes, the new file is loaded and used in the compilation.
- If you answer no, the old file is saved and used in the compilation, overwriting whatever you have saved from the external editor.
Let us venture to have a closer look at the Model View
|