cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Play sequence while value is zero

Janos1987
11-Garnet

Play sequence while value is zero

Hello,

 

is it possible to write a JS code to play a sequence while one of the value from thingworx is 0, and stop it if value is changed to 1. Imagine a propeller which should rotate while value is not changed.

 

Many Thanks

Janos

1 ACCEPTED SOLUTION

Accepted Solutions

How do you plan to initiate the sequence? From a button, or on model load? 

 

I set my experience up to have a button click event start the sequence. Then I call repeatSequence(); on the model PlayStopped event. This will run the sequence until the value you are watching changes. 

 

$scope.stopSequence = function() {
  $scope.app.fn.triggerWidgetService('model-1', 'stop');
};

$scope.repeatSequence = function(){
  var twxvalue = $scope.app.params.TWXvalue;
  if (twxvalue == 0)
  {
  $scope.app.fn.triggerWidgetService('model-1', 'play');
  }
}

  $scope.$watch("app.params.TWXvalue", function sequenceUpdate() {
    console.log('in sequenceUpdate');
    $scope.stopSequence();
  });

View solution in original post

6 REPLIES 6

Let me add one extension to avoid misunderstanding. I would like to repeat a sequence still a value is 0. if value changed sequence should be stop or play other sequence (stopped stage).

 

Thanks

Yes, you can do that. 

 

Create an application parameter and tie it to the TWX value you want to watch. I named mine 'TWXvalue'.  Then add the below code to your Home.JS file ensuring that you are using your widget IDs and app parameters. 

 

$scope.stopSequence = function() {
  // can add value checks if needed
  $scope.app.fn.triggerWidgetService('model-1', 'stop');
};

$scope.$watch("app.params.TWXvalue", function sequenceUpdate() {
  $scope.stopSequence();
});

This will stop the current sequence playing on model-1 as soon as the value of 'TWXvalue' changes.

Hi, 

 

thanks for your update, but it is not exactly what I would like to get. I would like to repeat a sequence still one of the value is 0. Maybe with $timeout function it is possible. Could you write an example where a sequence is played in all minutes?

 

Thanks

Janos

Could anyone help me in this case? I would like to repeat a sequence still a value changed.

 

Thanks

Janos

How do you plan to initiate the sequence? From a button, or on model load? 

 

I set my experience up to have a button click event start the sequence. Then I call repeatSequence(); on the model PlayStopped event. This will run the sequence until the value you are watching changes. 

 

$scope.stopSequence = function() {
  $scope.app.fn.triggerWidgetService('model-1', 'stop');
};

$scope.repeatSequence = function(){
  var twxvalue = $scope.app.params.TWXvalue;
  if (twxvalue == 0)
  {
  $scope.app.fn.triggerWidgetService('model-1', 'play');
  }
}

  $scope.$watch("app.params.TWXvalue", function sequenceUpdate() {
    console.log('in sequenceUpdate');
    $scope.stopSequence();
  });

perfect, thanks

 

Janos

Top Tags