Introduction
This document intended to provide a detailed guide and examples on how to write EKL script to import Resource 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)
- 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 Resource Structure EKL script:
Example
Detail Explanation
Excel template for Importing Resource Structure
The template excel format is as given below:
The 1st 4 columns are reserved and necessary to be added. Their description is as given below:
Column Title | Significance |
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 | Type of object to create |
Title | V_Name of Object created |
Inst_Name | V_Name / PLM_ExternalID of Object Instance created |
Additional attributes | All other attributes (Internal name) to be set on created Object’s reference and instance. |
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 EKL script, every time an new object is created, its reference is added in dictionary (Volatile instance) with V_Name(strPartNo) used as its key.
- Check if the reference with V_Name of item to be created is already available in Dictionary of existing objects.
- 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.
- 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 (Reference Name) 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.
/*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 = "ResourceStructure_" + strTemp3 + ".xlsx"
//For .csv
strTempFileName = "ResourceStructure _" + strTemp3 + ".csv"
2. Requirement 2: Use Display Name as Object Type instead of Internal Type
Some resource objects have Display Name same as their Internal Object type. But some objects have different internal type and display names. For example, Robot have internal type Robot but Manufacturing Cell have internal type as “Organizational”. Below section of EKL script is responsible to manage such scenario. If the Object type specified in excel matches internal type, the string is not changes. If the Type in excel does not matches with internal type, it is mapped to internal type. User can add such “If” statement for other Resource objects, which may not be covered in below script.
/* Object type mapping with internal type */
If strObjType =="Mfg Cell"
strObjType = "Organizational" //internaltype for Manufacturing cell is "Organizaltional"
else If strObjType =="Work Center"
strObjType = "WorkCenter" //internaltype for Work Center is "WorkCenter"
else If strObjType =="Organizational" or strObjType =="Robot" or strObjType =="Worker" or strObjType =="NCMachine" or strObjType =="Inspect" or strObjType =="ToolDevice" or strObjType =="Storage" or strObjType =="Transport" or strObjType =="Conveyor" or strObjType =="ControlDevice" or strObjType =="UserDefined" or strObjType =="LogicController" or strObjType =="Sensor" or strObjType =="IndustrialMachine" or strObjType =="Area" or strObjType =="WorkCenter"
{
// If the type matches with internal type Keep the strObjType as it is
}
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 as prefix 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