Import Product Structure from Excel

What's New in This Script in 2024?

This script is now updated and now supports creation of 3D Parts and 3D Shapes.

However, one needs to keep in mind the hierarchal limitations while specifying the objects to create in the Input Excel File. For example, a 3DShape an only be created under a Physical Product, and cannot be created under a 3DPart  which already have a 3DShape Under it.

Introduction

This document intended to provide a detailed guide and examples on how to write EKL script to Import product structure from Excel

Version – Validated on 2021x FD09 (FP2140), 2022x FD01 (FP2205), 2023x FD02 (FP2314), 2024x FD02 (FP2414), 2025x FD03 (FP2524)

Pre-requisites:

Licenses –

  • CSV(Collaborative Industry Innovator)
  • MDG(Mechanical Designer)
  • PPL(Process Engineer)
  • TER(Templates & Rules Designer) or KDI(Template Designer)

Disclaimer: Licenses mentioned above are as per 2021x, 2022x, 2023x, 2024x and 2025x documentation.

Logical Flow

Below is the logical flow for Import Product Structure EKL script:

Example

 

Import Product Structure from Excel EKL Script

 

VB_Script for Excel file selector

 

 

 

Input Excel for Product Structure

 

 

 

Detail Explanation

Excel template for Importing Product Structure

The template excel format is as shows below:

The 1st 4 columns are reserved and necessary to be added.  Their description is as given below:

Column TitleSignificance
Level

Defines level of object inside structure,

1 – Root

2 – First level child of root or child of level 1.

3 – Second level child of root or child of level 2.

N – Child of level N – 1.

Type

This script uses "new()" function to create the Product Structure Objects.

The provided Sample script supports "Type" of object to create like VPMReference (Used to create a Physical Product), 3DPart, 3DShape or can be any custom type.

Warnings

1. Using this script, 3DShape & 3DParts can only be created under a Physical Product.

2. Whenever a 3DPart is created, 3DShape is automatically created under the 3DPart. Therefore, it is not needed to create a 3DShape under a 3DPart Manually.

TitleV_Name of Object reference created
Inst_NameV_Name of Object Instance created
Additional attributesAll other attributes (Internal name) to be set on created Object’s reference and instance. (Column no 5 onwards)

Note: If instance attributes value needs to be set then add “Inst_” keyword before attribute name. For example for instance description, it will be “Inst_V_description”

How to manage Multi-Instantiation:

Steps followed for managing Multi-Instantiation:

In the script, every time an new object is created, its reference is added in dictionary (Volatile instance) with V_Name(strPartNo) used as its key.

  1. Check if the reference with V_Name of item to be created is already available in Dictionary of existing objects.
  2. If the reference is not created previously, create a new reference and add it in Dictionary of existing object. Set attributes of new objects reference and instance.
  3. If the reference with V_Name of item to be created is available in dictionary, extract it and create its new instance. Set the attributes of newly instantiated object.

For example – Below script will manage multi-instantiation:

Set oParentProdReference = oListOfParentObjs->GetItem(intLevel-1)
If oDicoOfExistingObjs.HasAttribute(strPartNo) == false
{
                    //create a new object with given Name
                    Set oVPMInstance = new(strObjType, strInstanceName, oParentProdReference) 
                    //set the instance object attributes
                    oVPMInstance.Name = strInstanceName
                    Set oVPMReference = oVPMInstance.Reference
                    //set the reference object attributes
                    oVPMReference.V_Name = strPartNo
                    //add the newly created object in list of parents and Existing objects
                    oListOfParentObjs->AddItem(oVPMReference, intLevel)
                    oDicoOfExistingObjs.SetAttributeObject(strPartNo,oVPMReference)
                    curLevelForReuse = 0 //Set the LevelForResuse back to zero for next iteration                    
                    /*add script to set custom attributes here */
}
Else
{
      If curLevelForReuse == 0 or curLevelForReuse <= intLevel
      {
            //Get the existing object
            Set oVPMReference = oDicoOfExistingObjs.GetAttributeObject(strPartNo) 
            //create new instance with existing reference
           Set oVPMInstance = new("VPMInstance", strInstanceName,oParentProdReference,oVPMReference)                                                                                                          
           /* script to set custome attributes to be added here */                                                  
           curLevelForReuse = intLevel
      }
}

How to set additional attribute and other custom attributes:

To set other extra attributes of the created objects, add extra columns in the excel file after column 4. 1st 4 columns are reserved for Level, Object type, Title and Instance name. While creating the column, column name should be the attribute name. Add the values in respective rows. While setting the column name for attribute of instance object, add “Inst_” as a prefix in the column name.

The EKL script manages to set the additional attributes if they are specified in the excel file. The condition is, the attribute should be available on the object. User can specify custom attributes also.

For example: Additional attributes to be set are highlighted in red box.

The code between below comment lines in attached EKL script is responsible for setting additional and custom attributes. Please find it in the EKL script provided.

/*Below code will set additional OOTB/specialized attributes from column number 5 onwards*/
.
.
/* Setting specialized/custom attributes is finished */

Here under some Use Case about possible adaptation of the script

1. Requirement 1: Support CSV input file type.

 To support .csv file type instead of .xlsx, follow bellow steps.

  • Edit below string in the VBScript:

In the script, strFileName string specifies the input excel file type. Modify the extension of the file name to .csv

'For .xlsx
strFileName = CATIA.FileSelectionBox("Select the input Excel File", "*.xlsx",CatFileSelectionModeOpen)

'For .csv
strFileName = CATIA.FileSelectionBox("Select the input Excel File", "*.csv", CatFileSelectionModeOpen)
  • In the EKL script, make following changes:

In the EKL script, strTempFileName variable of string type specifies the type of excel file to be created. Modify the below lines of code

//For .xlsx
strTempFileName = "ProdStructure_" + strTemp3 + ".xlsx"

//For .csv
strTempFileName = " ProdStructure _" + strTemp3 + ".csv"

2. Requirement 2: Use Display Name as Object Type instead of Internal Type

If the user wants to use Display Name as Type of the object instead of Internal Object type, below lines of code is responsible for mapping user specified Object type with internal Object Type. For example, If user want to specify “Physical Product” instead of “VPMReference”. Also, if user have some custom object types created, an "else" block needs to e added in below section of script.

/* Object type mapping with internal  type */
If strObjType =="Physical Product" or strObjType =="VPMReference"
{
strObjType = "VPMReference"
}
else If strObjType =="Custo Physical Product" or strObjType =="Custo_VPMReference"
{
                    strObjType = " Custo_VPMReference"
}
else
{
                    PopupMessage("No Mapping Specified for Object type:", strObjType )
}
/* add another else if block above for custom object types */

3. Requirement 3: Use custom column names instead of internal attribute name

If the user wants to use custom column names instead of internal attribute name, for example:

Here “description” is used instead of “V_description”.

Add below line of code in the EKL script, where additional/custom attribute values are read from the excel file.

if strAttrName== "Description" or strAttrName == "description"
{
    strAttrName = "V_description”
}
else if strAttrName == "Inst_Description " or strAttrName == " Inst_description"
{
    strAttrName = “Inst_” + "V_description"
}
//for attributes of instance objects “Inst_” is added to the internal name

How to Deploy

This video describes: How to deploy the "Import Product Structure from Excel?" EKL Script. However, the process is same for following EKL Scripts:
   1. Import Resource Structure from Excel
   2. Import Mfg. Item Structure from Excel
   3. Import System Structure from Excel

(Note: 
1. Instead of creating a separate Physical Product for containing each script, you can create the action files for the above three EKL scripts in the same Physical Product that we are going to create for "Import Product Structure from Excel" EKL Script.
2. The Excel File Selector VBScript is same for all the above EKL Scripts. So, you can create it only once and use it in all the above EKL Scripts.
3. The input arguments are different for different type of structure script. The information is provided in the respective EKL script as a comment at the top section.
) 

 

​​​​​​​

References link

<>

Author

Authors: @KA @RR ​​​​​​​@YB ​​​​​​​

For any queries, please contact - @KA