About Excel Automation

You can automatically generate schematic drawings from data contained in an Excel file. You can import only files with a specific format into SOLIDWORKS Electrical Schematic.

This page discusses:

This feature might be difficult to implement for beginners. To help you along, you can download an example from the section Example File.

Compatibility

The Excel automation feature is only compatible with 64-bit versions of Microsoft Excel 2016 and 365.

Macro Definition

The feature uses only schematic macros. Do not use other macros. These macros are specific and must include the two rules defined in the following table:

Item Description
Insertion point Automatically inserts the macros. The macros must have a specific insertion point in the drawing. From the Insertion point feature, click the point where you want to insert the macro. Enter the coordinates of this point in the Excel file.
Variable definition Replaces the defined variables with specified texts in the Excel file. Format the variables with the "%" character, placed before and after the variable. For example %VAR1%, in which "VAR1" is the variable name. The text used in the variable is free but it can be the same in the macro and in the XLS file.

You can use variables to replace:

  • All objects with a mark (such as components, locations, or drawings): To manage marks (location, function or component) edit the macro from the Macros management and replace the mark by the variable. For example, if the macro contains a contactor, marked K1, replace this mark by the variable %COMPMARK1%. In the same way, using the Location management, you can replace the location mark by a variable, like %LOCMARK1%, and assign this location to a component.
  • Manufacturer parts: Concerning the manufacturer part, associate the component to a manufacturer part in which you enter variables in the manufacturer name (for example: %MANUFACTURER1%) and for the manufacturer part reference (For example: %MANUFPART1%).
  • Equipotential numbers: To use variables in the equipotential numbers, edit the wire equipotential number and replace it by a variable, like %EQUIP1%.
  • Wire style names: To use variables in wire style names, open the Wire style management. In the wire style properties, replace the wire style name by the variable (For example: %WireStyle1%).
  • Translatable data and user data: You can also use variables on the description, user data, or translatable data of any object that has a mark (For example: %TransData_1_ES% for the first translatable data in Spanish).
Excel automation lets you automatically reset undefined macro variables. To reset undefined macro variables, click Configurations > Project. In the Electrical Project Configuration dialog box, on the General tab, under Excel automation, select Reset undefined macro variable. When selected, this option replaces the %xxx% variable with one of the following:
  • An empty string
  • A removed object
  • An associated default object like a function or a location.

Excel File Definition

To create a new Excel file for automation, from the Import/Export ribbon, click Excel Automation > Create new Excel file for automation .

The Excel file can be from version 97/2003 (.xls), up to 2013 format (.xlsx) or xlsm file format (Excel file with macros). Automation processes only the first visible sheet of the file. You can use any sheet name.

The Excel file must contain specific instructions for Excel automation. It can have as many rows before the header as you want. The process reads the first row that has the first string that starts with the "#" character. It is the header line.

This header line must have two kinds of information; field name (#field) and variable name (%variable%).

You can manage several languages in the file header. Insert a column using the #title_lang field to identify the texts describing the different languages.

Items Description
Field names To identify a Field name, it must start with the "#" character. Generally, the Field name corresponds to the field name in the database. For example, "#fil_title" corresponds to the mark of the drawing indicating the macro insertion point.

The first field names that you must manage correspond to the macro name and positions.

Table 1. Macro
Field name Description Required
#mac_name Name of the macro. Yes
#mac_posx The X coordinate of the macro insertion point. Yes
#mac_posy The Y coordinate of the macro insertion point. Yes
#mac_insert If this column is present, not hidden, contains a 0 or is empty, the processor skips the macro. No

About the other fields of the database, SOLIDWORKS Electrical Schematic only takes on fields for tables of drawing ("fil"), bundles ("bun"), locations ("loc"), and functions ("fun").

The only required field is #fil_title, which is the title of the drawing to insert the macro in. But inserting any other field such as book, location, or function requires the tag of the corresponding table. For example, any location field requires #loc_text.

The following table lists the supported fields:

Table 2. Drawings
Field name Description Required
#fil_filename Name of the file on the disk No
#fil_title The mark of the drawing Yes
#fil_filetype The drawing type (*) No
#fil.tra_0.xx The description of the drawing, where xx is the language code No
#fil.use_data0 User data of drawing No
(*) Supported values for the file type are:
  • 0: Schematic drawing
  • 1: Line diagram drawing
  • 5: Cover page
  • 9: Cabinet layout drawing
  • 12: Mixed scheme drawing

Table 3. Books
Field name Description Required
#bun_tag The mark of the book. Yes (if using any book).
#bun.tra_0.xx The description of the book where xx is the language code. No
Table 4. Folders
Field name Description Required
#fol_name The mark of the folder. No (if using any folder).
#fol.tra_0.xx The description of the folder where xx is the language code. No
Table 5. Locations
Field name Description Required
#loc_text The mark of the location. Yes (if using any location).
#loc_tagpath Mark path (full mark). No
#loc_tagroot Root for mark. No
#loc.tra_0.xx Description of the location where xx is the language code. No
Table 6. Functions
Field name Description Required
#fun_text The mark of the function. Yes (if using any function).
#fun_tagpath Mark path (full mark). No
#fun_tagroot Root for mark. No
#fun.tra_0.xx Description of the function where xx is the language code. No

You can also add user data and translatable data as a field, but since they are not directly in the object table, the field definition is slightly different.

Format translatable data in the following way: #ttt.tra_nn.xx

Where

  • ttt: replaced by the table prefix (fil, bun, loc, fun).
  • tra: indicates translatable data (do not modify.)
  • nn: replaced by the index of data you need (0 for description). Up to 14 for translatable data.
  • .xx: replaced by the language code, usually .l1 (L1) for the main electrical project language. Supported language codes are the following:
    • From electrical project languages (L + 1 to 3): "l1", "l2", "l3"
    • Standard language code: en, es, fr, it, ru, ko, ja, pt..., zh, zh-tw

For example, for the description of the file in the main language of the electrical project: #fil.tra_0.l1

For user data, the syntax is similar, but without specification 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.)
  • nn: is to replace by the index of data you need, from 0 to 19 for user data.

Example, for file user data: #fil.use_data0

Variables After you have specified all the data, you need to specify the macro insertion points (drawing, book, location, and function) and you must specify the variables that you want replaced by their values. You can use two methods:

The first method consists of writing the tag "#mac_var_name" in the first available column of the header, and on the next "#mac_var_value," and consecutively, as many pairs of columns as you need. After that, for each row (for each macro you want to insert) you want to write the name of the variable on the first column, and the value of this variable on the second column. For example:

#mac_name #mac_var_name #mac_var_value #mac_var_name #mac_var_value
Test0 %motor1% M5 %motor2% M6
In this case, when you insert the macro Test0, M5 changes the variable %motor1%, and M6 changes the variable %motor2%.

The second method is better if you use the same names of the variables for all the macros. Then, in this method, on the header you specify the name of the variable, for example %VAR1%, and on the different rows, the value that, this variable has, for this inserted macro. For example:

#mac_name %var1% %var2%
Test0 M5 M6
Test1 V3 V4
In this case, the first line inserts the macro Test0, changes the variable %var1% by M5 and %var2% by M6 and the second line inserts the macro Test1, replacing the variable %var1% with V3 and variable %var2% with V4.

Note: The names of the variables are not case-sensitive.
Using the formula with the variables You can use a formula to automatically generate the value during the automatic generation of a drawing. Opening and closing brackets ({ and }) enclose the formula. Format the variables in the formula the same way as those in the Excel file (%VARIABLE%).

For example, specify the mark of a component with this value: {"PP_" + %VARIABLE% + "RR" + %VARIABLE2%}

When inserting the macro twice, through Excel generation the result is PP_33RR12 the first time and PP_33RR13 the second time.

If in the Excel file we have two lines with:

%VARIABLE% specify as 33 and %VARIABLE2% specify as to 12

%VARIABLE% specify as 33 and %VARIABLE2% specify as 13

Managing wire style In the Wire style properties dialog box of the macro, enter the variable %WIRE_STYLE% for the WIRE_STYLE field. In Excel, you can add an optional column %WIRE_STYLE%, and input the value e for the wire style name.
Auto-connect wires To use this option, you must select the Auto-connect macros parameter in the General tab in the electrical project configuration.

When you use the Excel automation to create schemes, you can automatically connect the wires or the symbols between the existing scheme and the macro that you insert.

The elements that you want to connect must be aligned. You can connect wires to symbols or wires to wires.

Managing Origin - destination arrows Consider two macros with an origin arrow placed in one macro and a destination arrow placed in the other macro. When you choose to insert both these macros using Excel automation, you can establish the connection between origin and destination arrows in the two macros.

In the macros, insert origin or destination symbols in which you enter the same variable (for example: %Group1%) as the group name.

In the Excel file, add a column using this variable. In this column, enter the group name. This automatically associates the symbols with the same group name.

Replacing a symbol while inserting a macro Consider a symbol inserted in a macro. When you insert this macro from Excel automation, you can replace this symbol.

Edit the macro and open the properties of the symbol. Enter the variable, for example: %SYMBOL_NAME% in the Excel automation variable field.

in the Excel file, add a column using this variable (%SYMBOL_NAME% in our example). In this column, enter the name of the symbol that you want to use.

#mac_name %SYMBOL_NAME%
Test0 TR-EL002
Test0 TR-EL035
In this example, you insert the macro Test0, one time with the TR-EL002 symbol, and a second time with the symbol TR-EL035, even if another symbol has been defined in the Test0 macro.

Automatic Generation of Drawings

After having created the Excel file, you can import it in SOLIDWORKS Electrical Schematic to automatically generate the drawings. From the Import/Export ribbon, click Excel Automation .

A file selection dialog box opens. Selecting an Excel file automatically creates the books, folders, and drawings, inserts the macros in these drawings, and replaces the values with variables.

Warning:

SOLIDWORKS Electrical Schematic does not verify if the drawings are existing or if they contain other electrical entities. In this case, the app inserts the macros regardless of the existing entities of the drawing.

A report dialog box opens to display the result of the import.

Example File

  1. To use this example, create a new electrical project.
  2. From the Tools ribbon, click Unarchive environment .
    1. Download the manufacturer catalog archive: Demo_Simple.part.zip.
    2. Rename the downloaded archive file extension from .zip to .tewzip.
    3. From the Tools ribbon click Unarchive environment to add the archive.
    4. From the Library ribbon click Manufacturer part
  3. Download the macro archive Demo_Simple_Macros.macro.zip, and unarchive it in the Macro management.
  4. Open the macros to show the variables.
  5. Download the Demo_Simple.xlsx file and open it to show its structure.
  6. Click Excel Automation to import the Excel file.
  7. Import/Export