Excel Automation en
Excel Automation en
Excel Automation en
Excel Automation:
Generation of drawing inserting
macros from Excel file
User documentation
09/06/2016
Applicable from Version 2016 SP3
1
Excel Automation
1. PURPOSE........................................................................................ 3
2. FEATURES ...................................................................................... 3
2.1 CREATE NEW EXCEL FILE FOR AUTOMATION. ............................................................. 3
2.2 CREATE NEW EXCEL FILE FOR AUTOMATION. ............................................................. 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.
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.
3
Excel Automation
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
The 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 will be a
formula that can be like any formula we have in the application. Variables in the formula
could be formatted with the character %, in the same way as the one in the Excel file:
%VARIABLE% or without the character %.
Only the variables on the excel file will be available for the parser of the formula.
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."
Example of formula
{%Root% + “_” + %Order%}
In Excel, if you set %Root% = “ABC” and %Order% = “10”, data in macro will be
replaced by “ABC_10”.
7
Excel Automation
Only the first visible sheet of the 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. Can be used to
comment the file or make it easier to read.
8
Excel Automation
The only field that is required is #fil_title that is the name of the file where the macro
will be inserted. For the other tables, the tag (mark) 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
Are listed below the only supported field, others are excluded.
Object Table Field Description
Book tew_bundle bun_manual Manual or automatic tag
Book tew_bundle bun_tag Tag of the book
File tew_file fil_filename Name of the file on the disk
File tew_file fil_filetype File type
File tew_file fil_manual Manual or Automatic Tag
File tew_file fil_title Title displayed in treeview (tag)
File tew_file fil_titleblock Title block file name
Function tew_function fun_tagmanual Lock for tag
Function tew_function fun_tagpath Mark path (full mark)
Function tew_function fun_tagroot Root for tag
Function tew_function fun_text Tag
Location tew_location loc_tagmanual Lock for tag
Location tew_location loc_tagpath Mark path (full mark)
Location tew_location loc_tagroot Root for tag
Location tew_location loc_text Tag
Example, for the description of the file in the main language of the project:
‘#fil.tra_0.l1’.
For user data, the syntax is similar, but without specified for language.
#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).
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 6, l2, is not valid. The project has not this language.”
Warning:
If you insert a file 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 file, the
automation will give you a warning at the end of the process.
For other objects, the columns probably most common used 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 tag has no effect, the name will be
automatic and the user only will be able to insert one macro in this file, because the next
line will be a different file.
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.
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
This method is more flexible and requires 2x 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 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.
Look for macro name on a row Error Summary "There is no column with the
log name of the macro: %s."
Look for macro position X on a Error Summary "There is no column with the
row log position in X of the macro:
%s."
Look for macro position Y on a Error Summary "There is no column with the
row log position in Y of the macro:
%s."
Look for tag of the file on a row Error Summary "There is no column with mark
log of the file: %s."
Look for book tag field because Error Summary "There are some columns for
there are some book fields log books, but there is no column
with the mark: %s."
Look for location tag field because Error Summary "There are some columns for
there are some location fields log locations, but there is no
column with the mark: %s."
Look for function tag field Error Summary "There are some columns for
because there are some function log functions, but there is no
fields column with the mark: %s."
Check all macros listed exists Error Summary "Error: the macro %s does not
log exist on row %d."
Check for variable existence Warning Summary "The variable ""%s"" found in
log macro, %s not found in Excel
row."
A row with a file type of cover has Warning Summary "The file type of row %d is
a macro name. log %s. The macro ""%s"" will not
be inserted."
Check compatibility between Error Summary "The type of the macro %s,
macro type and file type log %s, is not compatible with the
type of file %s."
The process has been cancelled Warning Summary "The process has been
log canceled by the user."
Process finish correctly Information Summary The process has finished
log correctly.
14
Excel Automation
15
Excel Automation
16