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 PTC Community Badges. Engage with PTC and see how many you can earn! X

Changing colour of model item when clicked

Axcend
4-Participant

Changing colour of model item when clicked

What is the code for changing the colour of model item ?

1 ACCEPTED SOLUTION

Accepted Solutions
jmikesell
15-Moonstone
(To:Axcend)
4 REPLIES 4
jmikesell
15-Moonstone
(To:Axcend)

Axcend
4-Participant
(To:jmikesell)

Thank you.

The code that i was looking for was

$scope.view.wdg['modelItem-1'].color = 'rgba(255,0,0, 1.0)';

 

Could you please provide a more detailed explanation on how to achieved a color change when clicking a model item?

 

I have tried entering the code both in the home.js and under the 'click JS'  but this does not work. Unfortunately I have no real coding experience. 

 

many thanks. 

I figured it out but in case anyone else needs a clearer explanation I've outlined it below. This script will allow the user to change the colour of a part by clicking on the component. 

 

1) Drag and drop a 'model item' widget onto the part you wish to change the colour of, and take note of the Studio ID (In my case this is 'modelItem-2').

 

2) Under the current 'view' in the project panel you will have a <name of view>.js. Open this and enter the following code. 

 

$scope.color1 = function(val) { 
	$scope.view.wdg['modelItem-2'].color = 'rgba(0,255,0, 1)'}

In my basic understanding this will create a function called 'color1' that, when called will assign the colour to 'modelItem-2' (you may need to rename this to what ever your model item 'Studio ID' was). The colour is in RGBA (Red, Green, Blue, Alpha - Alpha being the transparency from 0-1)format, in this case 0,255,0,1

 

3) To activate the colour change on a click, we need to go back to the main project and select the model item from the project panel. In the properties panel of the model item scroll down to events and click the JS icon next to 'Click'. In the text field enter 

color1();

This will then call the function to change the colour. 

 

Hope this helps  

 

 

Top Tags