Duplicating items using EKL and Web Services

Introduction

This document intended to provide a detailed guide and examples on how to write EKL script to duplicate the structure of any item and insert it in a PPR under Empty root.

Version – Validated on 2022x FD01 (FP2205) & 2023x FD02 (FP2314)

Pre-requisites

Licenses – In order to execute this script successfully, user must have below licenses assigned:

Sr. No

License

Use

1

CSV

  • To Call all Authoring Web services (GET)
  • To call Lifecycle Related Web services (POST)

2

PPL

  • To create MBOM and Process Planning Structure.

3

KDI

  • To create Knowledge Action.

Disclaimer: Licenses mentioned above are as per 2022x & 2023x documentation.

Logical Flow

Below is the logical flow of the script to duplicate the item structure.

Example

Below are the ready use EKL script. For objects of different types, there are different scripts. In order to use this script, create Knowledge Actions as specified in the "How to Deploy" section of the script.

The logic of all the scripts is same, only the types of some objects/variables is different.


Duplicate Product Structure EKL Script


Duplicate MFG Item Structure EKL


Duplicate System Structure EKL Script


Detail Explanation

This document only describes the script for duplicating MFG Item structure. The scripts for Product and Systems are same with some modifications.  Already prepared scripts are also attached above.

Note: Duplicating resource structure is not possible using this web service.

Pre-requisites to run the script

1. Insert one new manufacturing assembly (Empty root) in the PPR Context. (For product, insert Empty Product. For System, add empty general system or work plan). Below image shows example:

2. Open the EKL script, and edit the value of “Dup_Prefix” string with desired prefix for duplication

set Dup_Prefix = "Duplicate2.2_"

Note:

  • It is not possible to insert the Mfg. Item, Product or System root directly in PPR Context using EKL. So, a blank Root item is created.
  • Inserting the item under PPR can be don manually:
    • Right Click on PPR Context.
    • Select “Insert Item -> Manufacturing Assembly”. (Do same for other types of items)

The below image shows the structure after duplication.

Option to duplicate with children.

When the script is executed, one dialogue box appears, which asks user whether to duplicate children also. According to response of user, either the whole structure will be duplicated or only selected item will be duplicated.

The code given below is responsible to show the dialogue box.

//Show dialogue box to decide whether to duplicate children's or not
set DuplicateChildrens = Question("Duplicate children's of selected object?")​​​​​

A list of objects is created.

  • If user selects "Yes", selected item and its child's will be added in list.
  • If user selects "No", then only selected item will be added in list.

Objects in the list will get duplicated.

The code given below will manage the items to add in the list:

listOfObjects->AddItem(selMfgItemToDuplicate, 1)  //Add Selected Mfg item root
If DuplicateChildrens
{
     listOfChildObjects  = selMfgItemToDuplicate->Query("PLMCoreReference", "") // This list will contain all the children's of select MFG item
     listOfObjects = listOfObjects + listOfChildObjects //combine both the lists
}

How to construct JSON Payload String?

To maintain the relations like Parent-Child relations, implement links, etc. after duplication, we need to send single request to web-service by passing the list of Object IDs of all the items which needs to be duplicated.

Below is the syntax of JSON string:

{
  "affix": "Duplication Prefix",
  "data": [
           { "id": "PhysicalID1", "identifier": "PhysicalID1", "type": "Instance Corpus Type",    "source": "https://ve4al702dsy.dsone.3ds.com:443/3DSpace", "relativePath": "/resources/v1/modeler//PhysicalID1" }, 
           { "id": "PhysicalID2", "identifier": "PhysicalID2", "type": "Instance Corpus Type", "source": "https://ve4al702dsy.dsone.3ds.com:443/3DSpace", "relativePath": "/resources/v1/modeler//PhysicalID2" }
           ]
}

Here, replace the value of  "source" element with your server URL

"For Loop" will be executed on the list of objects created in previous steps. For each item in the list, its Object Id will be extracted and that ID will be added in the  payload string.

The code between below two comments in attached EKL script will be responsible to get physical IDs of objects and construct the JSON string:

/*-------SECTION to construct JSON Payload for duplication-----*/
.
.
/*-------End of: SECTION to construct JSON Payload for duplication-----*/

How to get Physical ID?

How to duplicate the items?

Once the URI for duplication is constructed, "Post" request is sent to the web service. A  string containing list of Object IDs is passed as Payload.

The URI of web service for duplication is:

MethodPath
Post/resources/v1/modeler/dslc/duplicate

The code between below two comments in the EKL script is responsible to duplicate the items:

/*--- Section of code for duplicating objects  --------*/
.
.
/*---End of:  Section of code for duplicating objects  --------*/

How to insert the duplicated item under empty root?

After duplicating the item, a PLM Query will be executed for the Root Item. This query will return the item matching with the specified criteria and the type of query.

For Mfg item:

  •  PLM query type: "DELFmiFunctionReference"
  • Criteria : "v_Name"

The  code between below comments in the EKL script will be responsible to insert the duplicated item under empty root selected at the start of the scrip:

/*---Section of code for inserting duplicated objects under a empty root  --------*/
.
.
/*---End of : Section of code for inserting duplicated objects under a empty root  ----*/

How the script to duplicate product and system works?

  1. The scripts for duplicating Product and System structure are similar to this script with nominal changes. The types and names of input parameters will be different.
  2. The Web-Service URIs to get Physical ID will be different for different types. In script for systems, as the URI for Systems and Operations are different, there will be condition to check the type of object and select URI accordingly.
  3. The function to inert the object is different for different type, so code to insert the duplicated item under empty root will be different for each type.

The scripts for Product duplication and System duplication are also attached above.

How to deploy?

In order to use this script, follow below steps:

1. Download the attached EKL scripts.

2. Create a knowledge action.

3. Copy and paste the content of attached EKL script in the newly created action.

4. Set the input arguments as mentioned in the script.

5. In the Script, in the JSON payload, change the "Source" element with your server URL.

For example:

"source": "https://ve4al702dsy.dsone.3ds.com:443/3DSpace" 

​​​​​​​//For successful execution of the script, replace the highlighted part in the above line of code with your server URL.

6. Click apply.

7. Execute the script and select the input arguments.

8. Click ok.

How to create knowledge action?

References link

2022x Web Service Documentation​​​​​​​

2023x Web Service Documentation​​​​​​​

Author

For any queries please do not hesitate to contact - @KA