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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Wrong CurrentStep after rewind

MB_11019847
2-Guest

Wrong CurrentStep after rewind

Hi everyone,
i want to click through a step-by-step animation made in creo. For each step i want to display another text.
I have a button attached to "play" and a button to "rewind".
Each Button calls a function, where the code reads the current step and then sets the text according to the value of current step. For just going forward with the play button, everything works just fine. Only when the rewind button is pressed, the value of CurrentStep is wrong.

Do you have any suggestions? Thanks!
Here is my Code:

 

 

 

$scope.app.fn.loadResourceScript("Uploaded/fn.js");

$scope.btnVisible = function(step){
  if(step < 4 && step > 0){
    $scope.show("button-next");
    $scope.show("button-back");
  }
  if(step == 0){
    $scope.hide("button-back");
  }
  if(step == 4){
    $scope.hide("button-next");
  }
}

$scope.setText = function(step){
  switch(step){
    case 0:
      $scope.changeProperty("text_info_2","text","0text hier einfügen ala code");
      break;
    case 1: 
      $scope.changeProperty("text_info_2","text","1text hier einfügen ala code");
      break;
    case 2: 
      $scope.changeProperty("text_info_2","text","2text hier einfügen ala code");
      break;
    case 3:
      $scope.changeProperty("text_info_2","text","3text hier einfügen ala code");
      break;
    case 4:
      $scope.changeProperty("text_info_2","text","4text hier einfügen ala code");
      break;
    default: 
      $scope.changeProperty("text_info_2","text","def text hier einfügen ala code");
      break;
  }
}

$scope.$on("modelLoaded", () =>
           {
  $scope.setText(0);
  $scope.btnVisible(0);
}
          )

$scope.buttonNext = function(){
  let currentStep = $scope.getCurrentStep("SolarTracker");
  $scope.btnVisible(currentStep);
  $scope.setText(currentStep);
}

$scope.buttonBack = function(){
    let currentStep = $scope.getCurrentStep("SolarTracker");
    //$scope.btnVisible($scope.getPreviousStep("SolarTracker"));
    $scope.changeProperty("text_info_2","text", currentStep);
    //$scope.setText($scope.getCurrentStep("SolarTracker"));
}

 

 

 


 

1 REPLY 1

It will help if you can be more specific about what you see when "currentStep is wrong". What do you see vs. what you expect?

 

If it's just not updating, i. e. you're on step 5 and click "Back" but currentStep (as you capture it) stays at 5 instead of rolling back to 4, it may be that you are not giving the renderer time to execute the "Back" service before you grab the currentStep. You might have better luck if you put the code inside a timeout, so the renderer has time to finish its work before you ask it where it is. Maybe something like this:

$scope.buttonBack = function(){
  $timeout(()=>{
    let currentStep = $scope.getCurrentStep("SolarTracker");
    //$scope.btnVisible($scope.getPreviousStep("SolarTracker"));
    $scope.changeProperty("text_info_2","text", currentStep);
    //$scope.setText($scope.getCurrentStep("SolarTracker"));
  }, 100);
}

 

Announcements
Top Tags