Conceptual Information
Application, Document, Page and
Shape Level Scripts
How Scripts Can Be Used to Create
Wizards
Working with the Basic Editor in ConceptDraw V
Editing External Modules
Compilation and Execution of Scripts
CDBasic Output Window
Going to the Specified Line of a
Script
ConceptDraw Basic is a high-level scripting language. Starting from version 5.0 ConceptDraw introduces support for its proprietary built-in scripting language - ConceptDraw Basic. This adds the following advantages:
ConceptDraw Basic technology (unlike Automation on Windows, AppleScript on the Macintosh) is fully cross-platform , working in the ConceptDraw environment. The built-in scripting language realizes the specification of the modern high-level scripting language combined with support for ConceptDraw objects and database access objects. The supported list of ConceptDraw objects provides virtually unlimited control over documents, application windows, libraries, pages and shapes.
ConceptDraw Basic has the power and simplicity of modern realizations of the BASIC language. The language core of ConceptDraw Basic is almost fully compatible with such popular realizations of BASIC, such as Visual Basic, REALbasic.
With the introduction of ConceptDraw Basic technology ╤onceptDraw becomes one of the most powerful platforms for your custom visual solutions.
ConceptDraw supports four execution levels of the ConceptDraw Basic scripting language: Application level, Document level, Page level, Shape level. This means that for any ConceptDraw document or it's page or any shape in the document you can assign a program written in ConceptDraw Basic. Also one can create a program on the entire application level. Any execution level contains at least a built-in module with program code in ConceptDraw Basic.
Execution levels of ConceptDraw Basic are organized in a hierarchy (see the figure below), which reflects how global variables and procedures are inherited from higher levels to the lower ones.
This means, that a script, created for any shape (on the shape
level) also shows all global variables and procedures that belong to higher
levels: Page, Document and Application. In its turn, a page-level script shows
all global variables and procedures of the Document and Application levels.
And finally, a document-level script shows global variables and procedures of
the Application level. Thus, the hierarchy of execution levels determines the
functional purpose of ConceptDraw Basic scripts at different levels.
Application levels script is intended for re-assigning
the behavior of the entire application, and also for defining global variables
and procedures, which may be often used in various documents. For instance,
with the help of interface configuration and an application-level script in
ConceptDraw Basic it's possible to turn ConceptDraw into a specialized application
for computer network designers. One should just write the commonly used routines
(for instance, calculation of the cost of the components) as application-level
scripts and run them using the user-defined menu. Then the user will be able
to automatically calculate the cost of the components for any network diagram.
Document level script is intended for document-specific
calculations and also for defining global variables and procedures, used in
the code of different pages or shapes of the document. For instance, a document-level
script can be used to define specific procedures for creating templates. This
may look like a wizard, that asks questions specific to a certain document type.
Based on the user input, the script can determine the number and size of pages,
create these pages and place necessary shapes on them.
Page level script is intended for calculations
and actions, specific to a certain page of the document, as well as for defining
global variables and procedures, used in the code of the shapes on that page.
Scripts at this level may be used together with document-level scripts when
creating templates. Creating graphic objects (shapes) is slightly easier at
the page level, than at the document level.
Shape level script is intended for calculations,
specific to certain graphic object (shape). For instance, at allows to program
an element of a bar chart in such a way, that in can reflect values from a data
base or an external file. Library shapes can also have scripts.
Wizards, contained in some of the templates, supplied
with ConceptDraw, represent a typical example of what ConceptDraw Basic scripts
can be used for. Such wizards normally consist of one or more dialogs, which
come up when you create a new document, based on the corresponding template.
Templates or documents, which have built-in wizards,
include ConceptDraw Basic scripts at the level of the document, page or even
shapes, located on the pages of the document, or in libraries, opened together
with the template. Often the scripts are used to get data from the wizards into
the ConceptDraw document. The wizards themselves are stored in external modules
(dynamic libraries, or DLLs) on the Windows, or in shared libraries on the Macintosh.
These libraries can be created in any environment (C, C++, Pascal, Objective
C, etc.) which support building such libraries. The libraries contain a row
of interface-procedures, called by the scripting program in ConceptDraw Basic,
and finally gets the necessary data, which are integrated into ConceptDraw with
the help of ConceptDraw Access Objects. For instance, when you create a new
document based on the "Database Structure Wizard" template, a document-level
script, built in the template is launched, which runs the "Reverse Engineering"
wizard. This script calls a procedure from the CDWizards library, which represents
a dialog, that asks the user the parameters for finding the database source
and necessary parameters for extracting the database structure. Then the scripts
asks the results of the wizard from the CDWizards library, gets the necessary
information and uses it to base the database structures using the pre-drawn
library shapes.
For more information about constructions, built-in
functions and objects of the scripting language, and detailed description of
the principles and organization of ConceptDraw Basic see "ConceptDraw Basic
Reference".
The Professional edition of ConceptDraw V contains a built-in editor for editing scripts written in ConceptDraw Basic. You can call the editor from the menus "Tools / ConceptDraw Basic / Application Script", "Tools / ConceptDraw Basic / Document Script", "Tools / ConceptDraw Basic / Page Script", "Tools / ConceptDraw Basic / Shape Script", depending on the execution level of the script you need to edit. Each of the menus contains the "Edit..." and "Remove"items. The "Edit..." item opens the Basic editor window with the script of the corresponding execution level. The "Remove" item removes the script of the chosen execution level.
The built-in CDBasic editor is a regular text editor with such editing functions as Copy, Cut, Paste, Find/Replace etc. The editor has its own main and context menus. The full list of menu commands of the CDBasic editor can be found in the following sections: "Basic Editor Menu" , "Basic Editor Context Menu", "Basic Output Context Menu"
The editor allows to edit scripts of both built-in
and external modules. The script texts are stored in the UTF-8 encoding. In
fact, you can use any editor, supporting the UTF-8 encoding, to edit ConceptDraw
Basic scripts.
External modules can be connected by using the #Include
statement. The main and context menu contain commands for working with external
modules. So, the "File / Include Source..."
command calls the Open dialog and inserts the #Include statement
with the filename of the external module, chosen in this dialog. Such external
module can be opened both from the "File / Open Script..."
menu and the "File / Open Source" menu,
if the insertion point is located in the line with the #Include statement.
The "File / Exclude Source" command removes
the #Include statement from the line with insertion point.
By choosing the "Build / Compile"
command you can compile the source of the script to check it for syntax errors.
Or you can run the program by using the "Build / Run"
command. The source code of the script will be compiled, and if there are no
errors, executed. If a script is resident or being executed, you can stop it
by using the "Build / Stop" command.
You can also use the "CD
Basic" toolbar to run and stop scripts. It contains three buttons;
the "Run" and"Stop"
do the same as the corresponding menu commands, and the "Pause"
button suspends executing script for a while, showing a dialog with the corresponding
message. On closing the dialog, execution of the script is resumed.
A script can be executed automatically when an object,
containing the script is loaded. That means that an application-level script
will run when you launch the application. When you load a document or created
a document from a template , the document level script is launched automatically.
Then, if the document-level script remains resident, the scripts at all page
levels are executed subsequently, starting from the first page. Once a page-level
program has been executed, and provided it remains resident (it wasn't stopped
by the End statement), scripts of the shapes on the page are
launched. A shape-level script is also started automatically, once the script-containing
object has been inserted into the document from a library or duplicated.
To enable/disable automatic launching of scripts, use
the corresponding flag in the application preferences,
which are saved with the application.
For detailed description of the principles of ConceptDraw Basic see "ConceptDraw Basic Reference".
The "CDBasic Output"
window is used by the program to display errors and warning and debug messages
displayed with the Trace statement.
This service window can be enabled/disabled from the "Build
/ CDBasic Output Window"menu.
The CDBasic compiler displays service messages in the
"CDBasic Output"window, and if any
errors are found in the script during compiling, they are displayed as well.
Normally an error message includes the error number, a short description and
the module and line number, where the error occurred. If you double-click on
such message, the editor opens the required module and places the insertion
point into the line where the error was found.
Sometimes when you edit a script you may need to go to a certain line of the code. For instance, when you get a run-time error, it may include the number of the line in the code, where the error occurred. You can navigate to the desired line in the editor window, by using the "Line Number" dialog, called from the "Edit / Go To Line..."menu of the editor.