question

anon-user avatar image
0 Likes"
anon-user asked Jason Lightfoot edited

How to change color font of a button in the dashboard from code

I want to change the color of a button and of a tittle in the dashboard. In the image, for example, I want to change the color of the text "Opciones Pistola" and the color of the font on one button "Opción 0".

I need to do this from code. I could change the image of a button with the following code, but I can´t access the color font.

string controlID = "1";
string imagePath = "Capturas Pistola\\General2.png";
treenode control = getdashboardcontrol(controlID);
treenode bmp = control.as(Object).attrs.assert("bitmap");
bmp.value = imagePath;
refreshview(control);

I was trying a lot of options modifying that code, but I did not achieve any good result.

I had difficulties to find the buttons in the tree.

Thank you a lot in advance.

FlexSim 20.1.3
dashboardsbuttonschange color font
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Kavika F avatar image Kavika F ♦ commented ·

Hi anonymous user, was Jason Lightfoot's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Jason Lightfoot edited

If it's in the onPress code of the button here's an example that toggles the color:

Object button=c;
if (button.color==Color.blue)
    button.color=Color.red;
else
    button.color=Color.blue;


If you want to set the dashboard defined color from elsewhere here's another example:

Object buttondef=Model.find("Tools/Dashboards/Dashboard/DashboardButton1");
treenode buttoncolor=variables(buttondef).subnodes["buttonColor"];
Color newcolor=Color.red;
buttoncolor.first.value=newcolor.r;
buttoncolor.first.next.value=newcolor.g;
buttoncolor.last.value=newcolor.b;
Object activebuttondef=node("createdView+",variables(buttondef));
if (objectexists(activebuttondef)){
    treenode activeButtonColor=variables(activebuttondef).subnodes["buttonColor"];
    createcopy(buttoncolor,activeButtonColor,1,0,0,1);
    activebuttondef.first.as(Object).color=newcolor;
    repaintview( activebuttondef.first);
}


· 11
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

anon-user avatar image anon-user commented ·

Is there a possibility to access easily to some button in the tree or a way to know its name?

I tried to creaate a new button in a new model but I can´t access it in the tree.

Thanks.

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ anon-user commented ·

You could put this in the onPress:

applicationcommand("outputconsole");
print (c.up.name);

You can also use getdashboardcontrol() with the ID of the control/widget, but that just gives you the pointer to the button if it the dashboard is open/instantiated. If that's all you needed then you can set it from the ID directly.

getdashboardcontrol(ID).color=Color.red;   //version 20.2 and later
getdashboardcontrol(ID).as(Object).color=Color.red;    //version 20.1 and earlier


1 Like 1 ·
anon-user avatar image anon-user Jason Lightfoot ♦ commented ·

I tried to do that, but I saw in my model I have different buttons with the same name (maybe I made some copy/paste in the dashboard). Is the only way to solve this to remake my dashboard with new buttons? I understand I could have a problems even if I use the "getdashboardcontrol()" method, because this only gives the route with the name of the button (the ID isn not there).

I tried to change the color of one button in a new simplified model (just the button and a custom code to change its color), but I couldn´t achieve that. I uploaded the model here with the problems. FlexSim tells it can´t access "first" label.

Sorry for the problems I could generate, I am a bit lost with this funtionalities of FlexSim.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.