Delete Tool

Is there an API call/function that can be used to delete a tool within its own html code? I am creating a while loop tool that loops through a certain number of times, however after it is done executing I want it to be deleted automatically. Is there any way to write that within the index.html file for the while tool?

We don’t currently have an API for that, although we could build one.

@valentin do you think it makes sense for the tool API to have the power to delete a tool? I think we’ve talked about this before.

This is an interesting problem. @alinashah can you give some more context what the tool will do? I just want to make sure that we are on the same page. Usually the place where we would allow such control would be the addon interface level. I just want to learn what is the right method to support you.

I have been developing tools and blocks within the vuforia-spatial-core-addon folder. I think the while tool specifically can be used to have a certain process run a specified number of times. So the input to the while tool node would be the number of times the loop should run, and the output from the node would be a 1, symbolizing true each time the loop runs. Currently, when the loop finishes it outputs a 0 (false) so that whatever process I’ve defined stops. However, I think a better way to have the loop finish may be to delete the while tool as soon as it stops running.

That would mean that you have to add a new tool from the menu again, when the loop is finished. Why would you want to implement it as a tool and not as a logic block?
Would you want to use the loop again once it’s finished?

I would also suggest to build a node that has loop functionalities and you use the publicData interface to pass on parameters to the node. In this case you would persist the logic on the server even if the tool is not currently visible in someones toolbox.

As I was working with the tool, I do think it may be better to not delete the tool, but rather just have it output a value of false when it isn’t running. I think I may try to implement the loop as a logic block, I was just able to initially implement it faster as a tool. Building a node that has loop functionalities seems like an interesting way of doing it. How/Where would I define that new node?

Hi @alinashah, that’s a really good question, so I’m moving the answer to that question to this new thread so that it is easier for other people to find the information later.

Thank you for the post on new nodes! I will try to experiment with creating my own nodes at some point. As I was trying to create a loop logic block, I had a few questions with how to change the output value. With the code attached below, I have written the block so that the toggle is “true” when the first input is 1. If there is a second input, that value would be the number of times the loop should execute. Within the foo() function, I set the block’s output value to 1 initially as it runs through the loop. However when the loop is done I want the value to switch to 0. I’ve found that the print statement within the else if prints that the value of the output of the block is 0, but the output does not update on the app. Do you have any ideas about how to better structure the code or have the output update properly?

That’s a pretty cool idea for a block!

The problem might be related to what actually triggers the block to output a value. It outputs when you trigger the callback function e.g. callback(object, frame, node, block, index, thisBlock)

You can trigger this multiple times if you’d like. For example, the following code inside the render function should make a block output three random values spaced out over a couple seconds:

thisBlock.processedData[0].value = Math.random();
callback(object, frame, node, block, index, thisBlock)
setTimeout(function() {
  thisBlock.processedData[0].value = Math.random();
  callback(object, frame, node, block, index, thisBlock);
  setTimeout(function() {
    thisBlock.processedData[0].value = Math.random();
    callback(object, frame, node, block, index, thisBlock);
  }, 1000);
}, 1000);

(I didn’t actually run the above code to test, but I’m pretty sure it works)

I think your foo function needs to trigger the callback after setting the processed data each time, rather than just returning. Let me know if that fixes it.

You also need to consider that the function block can be triggered multiple times before your loop ends. You might want to program in such a way that only one loop at the time can run and if a new signal comes in you might just want to restart the loop or you find other methods to handle this. Just something to keep in mind to not generate extreme CPU loads.