How to delete a sensor variable from script
-
For now, there is no option to delete a sensor variable alone from the GUI. So I'm providing an option to delete a sensor variable from a script.
Note: This API available from
1.4.0.Final
version.- Now get
SensorVariable
id from Sensors page.Resources >> Sensors >> Click on view details
,
Now click on edit ofsensor variable
On the URL you can see sensor variable id, This is id is important note it for your target
sensor variable
Add the following script on your controller,
Extension:JavaScript
Type:Operation
var myImports = new JavaImporter(java.io, java.lang, java.util); with(myImports) { // pass sensor variable as bindings, example: { id: 99 } mcApi.sensor().deleteSensorVariable(id); }
Execute the script as
Run now
(select the script and inActions
you can seeRun now
),
Pass the sensor variable id as bindings, here it is{ id: 99 }
,
Click on
Run
. All done. Now yourSensor variable
removed from MyController. - Now get
-
@jkandasa Thank you so much for this!
It had slipped my mind with other more important issues taking the focus away. Today I found some 'ghost' variables and remembered that I had the problem before, but not the solution. Now I know why!
Anyway it worked perfectly and I will keep a lookout for any future ghost variables. This would be a good thing to have built into ver 2.0
-
@jkandasa I will never be thankful enough for MyController
I found this looking for a way to delete sensors older than a time interval. The reason is that over time and trials I have accumulated a huge amount of sensor variables which I would like to get rid of.
Sometimes they are just sensor variables added on top of the true ones.Since I have little practice with Javascript I would need some guidance to write a script which removes all the sensor variables older than a given (fixed) interval.
-
@fsgrazzutti Currently I am actively working in V2.
I will have a look in to this soon and update you