- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1
 
4. Creating custom user blocks for developers
        epoilvet edited this page Jan 16, 2020 
        ·
        5 revisions
      
    In order to define your own blocks without having to modify and build the front-end you can just update the following 2 files:
/dist_user/DesignerUI/statics/user.json
Add a new block definition in the array like this:
{
  "functionName": "MyFunction", //Name of the function of the block
  "blockName": "MyFunction", //Name if the block
  "library": "user",  //Name of the menu entry
  "inputs": [.   //List of inputs
    {
      "name": "myInput1",
      "type": null
    }
  ],
  "outputs": [ //List of outputs
    {
      name: "myOutput1",
      type: null
    }
  ],
  "function": {
    "ref": null,
    "code": ""
  }
}
It's used to execute the logic of the block in MarkLogic
The code is located in :
/dist_user/DHF/src/main/ml-modules/root/custom-modules/pipes/user.sjs
function myBlock() //Any unique function is the module
{
   this.addInput("MyInput1"); //Add Inputs, same as the one in the son definition
   this.addOutput("myOutput1");//Add Outputs, same as the one in the son definition
}
myBlock.title = "MyFunction";
myBlock.desc = "MyFunction";
myBlock.prototype.onExecute = function()
{
   let myInput1 = this.getInputData(0) //Add Outputs, same as the one in the son definition
   // Code any logic you want or call external lib
   // Code any logic you want or call external lib
   // Code any logic you want or call external lib
   this.setOutputData(0, outputValueFromLogic ) //Set output(s) value(s)
}
LiteGraph.registerNodeType("user/MyFunction", myBlock ); //The first parameter must be equal to library/blockName of the block definition.
You must then run gradle mlloadmodules You can also find details on block implementation here: Litegraph guides
Click the video for larger size.