Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
What is the code for changing the colour of model item ?
Solved! Go to Solution.
Check out this thread:
https://community.ptc.com/t5/Studio/Change-Color-of-a-ModelItem/m-p/502440
Thank you.
The code that i was looking for was
$scope.view.wdg['modelItem-1']
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