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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Javascript quark #1

No ratings

Hi,

 

we can do many tricks with Javascript in Studio and most of the times it's just a matter of copying & pasting the right code.

 

I'd like all Studio users, not just coders, to benefit from this, and thought I could drop here a snippet to blink a widget. 

 

I call this a quark - from the particle physics standard model - and not atom, because it's really a smaller building block than an atom Smiley Happy

 

Blinking a widget can be useful, for example, if you are not using Creo Illustrate to create a sequence but still want to draw the user attention to some item in the scene.

 

 

Here's the Javascript code to copy & paste to your Home.js:

 (to Javascript coders: I'm using modern Javascript syntax, don't be frightened by that Smiley Surprised)

 

$scope.blink = function(widget, times, interval) {
  let w = (widget.visible !== undefined ? widget : $scope.view.wdg[widget]);
if (!w || w.visible === undefined) { throw "Cannot blink this widget"; }
$interval(() => w.visible = !w.visible, interval, times);
}

 

 Invoke the function like this:

 

blink(widget, times, delay);

where widget is either the id of the widget (e.g. modelItem-1) or the widget itself (e.g. $scope.view.wdg['modelItem-1']).

The other two numbers are the number of times that you want visibility to change, and the amount of milliseconds between each visibility change.

 

 

Here follow some examples.

 

You want to blink the widget 4 times with a 300 ms interval (and leave the widget visible at the end):

blink('modelItem-1', 2*4, 300);

 

You want to blink the widget 4 times with a 300 ms interval (and leave the widget not visible at the end):

blink('modelItem-1', 2*4+1, 300);

 

You can comment and suggest additional quarks if you want.

 

Alessio

 

Comments

I tried to copying this code

$scope.blink = function(widget, times, interval) {
  let w = (widget.visible !== undefined ? widget : $scope.view.wdg[widget]);
if (!w || w.visible === undefined) { throw "Cannot blink this widget"; }
$interval(() => w.visible = !w.visible, interval, times);
}

  and in copied this into the CLICK box of BUTTON widget.

blink('modelItem-1', 2*4, 300);

but its not working. is there is something wrong with my procedure? pls correct me if any.

 

Thank you in advance

Version history
Last update:
‎Jun 05, 2019 08:52 AM
Updated by:
Labels (1)
Contributors