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

Moving multiple models

micah
14-Alexandrite

Moving multiple models

I'm using the code below to move multiple models. The issue I'm having is they all have different starting locations. So they appear to 'jump' to that Y coordinate, and then move up. Is there a way to have the function inherit the original value and then move up?

 

$scope.posChange1 = function() {
$scope.app.params['ClipMovement']+=0.0001;
}

$scope.moveClip = function() {
$scope.app.params['ClipMovement'] = 1.329;
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};

ACCEPTED SOLUTION

Accepted Solutions
micah
14-Alexandrite
(To:sebben)

That works perfectly. Another issue I'm having is looping the movement.

I've tried:

 

$scope.moveClip = $interval(function() {
for(var i=0; i< 3; i++){
$scope.view.wdg[Objects[i]].y=start[i];
}
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
}, 1000);

 

Where moveClip(); is bound to a click function of a button. But the loop starts when the view is loaded rather than when the button is clicked.

 

(Also, how do you add code to post in that box?)

View solution in original post

5 REPLIES 5
sebben
14-Alexandrite
(To:micah)

Hi,

 

you can write your objects in a list and loop through it like this:

 

var Objects =["3DGauge-1","3DGauge-2","3DGauge-3"];

$scope.posChange1 = function() {
  for(var i=0; i< 3; i++){
	$scope.app.view.Home.wdg[Objects[i]].y+=0.0001;
  }
}

$scope.moveClip = function() {
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};
micah
14-Alexandrite
(To:sebben)

This isn't suitable for my situation because if I run that function twice it will incrementally add from the last position. I'd like the models to move from each of their original positions, and if the function is run again, go back to the original and then move up.

 

Is there a way to call back the original 'y' position of all the models?

sebben
14-Alexandrite
(To:micah)

You can store them in an array on startup and change the values to the original each time you call the function.

Something like this:

var Objects =["3DGauge-1","3DGauge-2","3DGauge-3"];
var start = []; 
$scope.$on("$ionicView.loaded", function (event) {
   for(var i=0; i< 3; i++){
	start.push($scope.app.view.Home.wdg[Objects[i]].y);
  }
});

$scope.posChange1 = function() {
  for(var i=0; i< 3; i++){ 
	$scope.app.view.Home.wdg[Objects[i]].y+=0.0001;
  }
}

$scope.moveClip = function() {
    for(var i=0; i< 3; i++){
	$scope.app.view.Home.wdg[Objects[i]].y=start[i];
  }
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};
micah
14-Alexandrite
(To:sebben)

That works perfectly. Another issue I'm having is looping the movement.

I've tried:

 

$scope.moveClip = $interval(function() {
for(var i=0; i< 3; i++){
$scope.view.wdg[Objects[i]].y=start[i];
}
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
}, 1000);

 

Where moveClip(); is bound to a click function of a button. But the loop starts when the view is loaded rather than when the button is clicked.

 

(Also, how do you add code to post in that box?)

sebben
14-Alexandrite
(To:micah)

Hi,

I'm not sure why this start when the view is loaded, but you could just call the the moveClip function from the posChange1 function when it comes to the end of the interval:

 

$scope.posChange1 = function() {
  for(var i=0; i< 3; i++){ 
	$scope.app.view.Home.wdg[Objects[i]].y+=0.0001;
  }
  if($scope.app.view.Home.wdg[Objects[0]].y >= start[0]+0.0099){
  $scope.moveClip();
  }
}

To insert a code sample you have to click first the three dots to extent the toolbar ( ... ) and then click on the </> symbol.

Announcements

Top Tags