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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

For Loop is not working

venkatraj
13-Aquamarine

For Loop is not working

I have added three models widgets & changed the studio-id as frame, cab & tires. I also added a button with a function name as hideModels(). I tried to hide all the models at once by clicking the button. I used for loop in the code as attached here. But it didn't work. I hope the syntax is correct. The error is visible property is not defined. What can I do to loop all the models to hide.

 

Capture.JPG

 

$scope.hideModels = function(){
var models = ["frame","tires","cab"];
  	for (i = 0 ; i <= models.length ; i++){
      	$scope.app.view.Main.wdg[models[i]].visible = false;
    }
}

Thanks!!

2 REPLIES 2

Hi @venkatraj,

 

I think it should be

instead of 

$scope.app.view.Main.wdg[models[i]].visible = false;
>>
$scope.app.view.wdg[models[i]].visible = false;

but if this does not help then here some additional suggestions:

$scope.hideModels = function(){
var models = ["frame","tires","cab"];
  	for (i = 0 ; i <= models.length ; i++){
       $scope.app.view.wdg[models[i]]['forceHidden'] = true;
      	$scope.app.view.wdg[models[i]].visible = false;
// or
$scope.setWidgetProp(models[i], 'visible', false); 
$scope.app.view.wdg[models[i]]['forceHidden'] = true;
$scope.$applyAsync(); } }

- If it not work then try using the function instead of the direct setting

- as second option use  additional $scope.$applyAsync(); call

- the last strong option is to set forceHidden property - also via setWidgetProp function.

Hi @RolandRaytchev,

It didn't work. What worked was, little correction in for loop. When wrote the for loop like below, it worked perfectly. Instead of '<=' just '<' did the work. When we use <= there was an undefined element at the end of loop, which caused the code not functional

var models = ["frame","tires","cab"];
 	for (i = 0 ; i < models.length ; i++){
$scope.app.view.Main.wdg[models[i]].visible = false;
}

  Thanks a lot for your help!

Announcements

Top Tags