Excel Automation en
Excel Automation en
Excel Automation:
Generation of drawing inserting
macros from Excel file
User documentation
18/07/2016
Applicable from Version 2016 SP3
Version 1.1
1
Excel Automation
1. PURPOSE........................................................................................ 3
2. FEATURES ...................................................................................... 3
2.1 CREATE NEW EXCEL FILE FOR AUTOMATION .............................................................. 4
2.2 GENERATION OF DRAWINGS ................................................................................ 4
2
Excel Automation
1. Purpose
The purpose of this Excel Automation is to automatically generate drawings, inserting
macros in the drawing, following the instructions from an Excel file.
2. Features
Practically, to be able to generate custom drawing from Excel, the user needs to:
Save macros corresponding to the part of drawing
Edit macros to set variables for macro values to be replaced at inserted
Define an Excel template with the format he wants to use and the necessary
information to define macro to insert.
Once this preparation work is done, user can create new Excel file from template, fill the
content to define which macros to insert and generate drawings.
From ribbon menu, in Import / Export tab, two features are available for Excel automation.
Creation of a new Excel file from a predefined template.
Generation of drawings from an Excel file.
3
Excel Automation
Once a template is selected, the user is asked for destination of new file, then it is open
to let user fill the file for generating drawings.
Templates location:
The templates listed are the Excel files existing in the folder “XlsAutomation\Template”
from application data folder. The user is free to copy and modify the existing templates to
create one with the formatting and the details he wants.
4
Excel Automation
3. Macros edition
Note: here when talking about “macro” it means macro from electrical project, not to be
confused with VBA macro that is the script you can use in Excel to reproduce a sequence
of actions.
One variable can be used several times in a macro, but should be used for the same
information.
5
Excel Automation
6
Excel Automation
3.3.5 Formulas
User could also enter a “formula” in any of the places that the automation look for a
variable in macro. The automation will recognize a formula if the text in this places is
between the characters “{“and “}”. The content between those two characters is a formula
similar to any formula we have in the application. Variables in the formula MUST be
surrounded by the character %, in the same way as the one in the Excel file: %VARIABLE%.
Only the variables on the Excel file will be available for the parser of the formula. As for
any formula, variables must match exactly in the formula. Difference in capital letter for
example will make formula fail.
Example of formula
{%Root% + “_” + %Order%}
In Excel, if you set variables %Root% = “ABC” and %Order% = “10”, data in macro
will be replaced by “ABC_10”.
For the same formula, if you set %ORDER% = “10”, evaluation of formula will fail, due
to case difference in variable name.
If the parser gives any error evaluating the formula, the automation process will show this
error on the final dialog of the results:
“Error while parsing a formula during insertion of the macro Test_Formula_Error: Some parse error."
7
Excel Automation
Only the first visible sheet of the Excel file will be processed, others will be ignored, so
other pages can be used to define additional data, like list of macro user can insert…
There is no restriction on the sheet name.
All the rows before the key row are not processed. They can be used to indicate the content
expected, in users language, can be merged, or apply any formatting.
All the rows after the key row will be processed for inserting macro.
A row without macro name will produce a warning, nothing will be inserted and process
will continue.
Each cell of the key row must:
Start with a #, like #mac_name, to indicate a special information or a database
field.
Or be surrounded by %, for variable, like %VAR1%.
Position of columns does not matter, only the title given in key row is important.
Column with nothing in Key row will be ignored, and produce no warning.
8
Excel Automation
The only field that is required is #fil_title that is the name of the drawing where the
macro will be inserted. For the other tables, the mark (tag) of the corresponding table is
required, if you use any fields from this table. For instance, if you insert any location fields,
then the field #loc_text is required.
Detailed and up to date list of available field is defined in document about project database
structure, so as the content of some fields.
9
Excel Automation
Here is the list of the only supported field, others are excluded.
Object Table Field Description
Book tew_bundle bun_manual Manual or automatic mark
Book tew_bundle bun_tag Mark of the book
Drawing tew_file fil_filename Name of the file on the disk
Drawing tew_file fil_filetype Drawing type
Drawing tew_file fil_manual Manual or Automatic mark
Drawing tew_file fil_title Title displayed in treeview (mark)
Drawing tew_file fil_titleblock Title block file name
Function tew_function fun_markmanual Lock for mark
Function
tew_function fun_tagpath Mark path (full mark)
Function
tew_function fun_tagroot Root for mark
Function
tew_function fun_text Mark
Location tew_location loc_tagmanual Lock for mark
Location
tew_location loc_tagpath Mark path (full mark)
Location
tew_location loc_tagroot Root for mark
Location
tew_location loc_text Mark
Example, for the description of the drawing in the project main language: ‘#fil.tra_0.l1’.
For user data, the syntax is similar, but without language to specify.
#ttt.use_datann
Where
ttt is to replace by the table prefix (fil, bun, loc, fun).
use_data is for user data (do not modify).
nn is to replace by index of data you need, from 0 to 19 for user data.
10
Excel Automation
If the project is configured only with one language and you add any column with language
code .l2 or .l3 then the process will give you a warning like this:
“The language specified on column %d: %s, is not valid.The project does not contain text
using this language.”
Warning:
If you insert a drawing type of “Cover page”, then the name of the macro should be empty.
This is provided only to let the user to enter a cover page, for presentation purpose, in the
process of automation. If you set the macro name in a row with this type of drawing, the
automation will give you a warning at the end of the process.
For other objects, the most commonly used columns are for mark (tag) and description in
current language (using l1 for language code).
FIELD NAME Object DESCRIPTION REQUIRED
#bun_tag Book Mark If any book used
#bun.tra_0.l1 Book Description in current project No
language.
#loc_text Location Mark If any book used
#loc.tra_0.l1 Location Description in current project No
language.
#fun_text Function Mark If any book used
#fun.tra_0.l1 Function Description in current project No
language.
If you set the tagmanual to 1, then the column mark has no effect, the name will be
automatic and the user will only be able to insert one macro in this drawing, because the
next line will be a different drawing.
11
Excel Automation
For both methods, the name of variable is not case sensitive. We can have variable
%MyVariable% in macro, and %myvariable% in Excel and it will match.
But, if variables are used in formulas (see chapter 3.3.5 ), then case must be respected.
Example, in this case where we insert the macro Test0, the variable %motor1% will be
changed by M5 and the variable %motor2% will be changed by M6.
#mac_name #mac_var_name #mac_var_value #mac_var_name #mac_var_value
Test0 %motor1% M5 %motor2% M6
Test1 %var1% V3 %var2% V4
This method is more flexible and requires two times the number of variables you can find
in a macro. But it requires to write the name of variables every time it is used.
For this method, only one column is required by variable. But you need one column for
each existing variable name. This method is convenient when a variable is used in many
macros, but will require lot of columns to manage all the variables.
12
Excel Automation
13
Excel Automation
Then, the rows of the Excel file are processed to generate drawings, and at the end the
project is unlocked. If any error happens during process, a summary dialog is displayed to
list them.
14
Excel Automation
15
Excel Automation
16