2

Can you explain the "is Visible on Upper Layer" property, please? It's on everything, yet I can't seem to find it programmatically.

I have a custom block, and I have parameters for the block that provide functionality options. When the user selects a certain configuration, I want to hide the port, text and graphics group associated with that option.

My preference is just to flip the flag "is Visible on Upper Layer" to false, however, I cannot find that option. For the text and the group, I can only set "isVisible" to true, and it doesn't have an option to set "is Visible on Upper Layer". For the port, there doesn't seem to be any code that impacts its visibility.

How can i control visibility on the upper layer for text, groups and ports in the icon of a custom block? Please help Thanks Brett

brett
  • 33
  • 4

1 Answers1

0

The property Visible on upper level is not accessible by code and can only be set via the editor during model development.

As you already noted, the function to use here is setVisible(boolean), on the Agent level. The object will then be hidden both in the block itself, as well as in the upper level.

If you dynamically want to hide some parts on the upper level, but always show them on the Agent level (inside your block), you will have to create two instances of them, one that is visible on upper level and one that is not. Only then you can hide one while showing the other using setVisible(boolean).

For ports you are even more restricted, visibility can only be set via the editor during model development, and Visible on upper level can't be set at all.

Florian
  • 962
  • 1
  • 5
  • 17
  • Thanks for the confirmation Florian, I appreciate it, I have been using the setVisible(boolean) switch and hiding graphics and text as needed, using a function void setupMyAgent(), and then i call this function in the On Change event for the configuration parameter in myAgent property view, and in the OnStartup() event for the agent. But there is a problem, unfortunately only the run time behaviour works correctly (OnStartup event in the agent), while the design-time behaviour (On Change event in the parameter) doesn't work. Can you help me understand this behaviour please? – brett Jun 25 '19 at 08:08
  • I just tried myself and it does work for me. Do you use the special function set_myParameter to trigger the value change? If not, the OnChange code will not be executed. Just a simple assignment will change the parameter value, but not trigger the OnChange code. – Florian Jun 25 '19 at 10:20
  • Wow, thats interesting. So if I was changing the value of myParameter by code, I would use the set_myParameter() function, which i assume is set up automatically by the system for every Parameter in the agent. But the problem is, I want the event to fire when the user changes the value in the agent's myParameter property box, how do i use set_myParameter() in this context? This is the main problem, getting the config (color, visibility etc.) changed, based on user selections in the agent property box – brett Jun 26 '19 at 03:15
  • Yes, your summary is correct. Those functions are auto-generated for every parameter by the system. If you link a user control (Edit Box, Slider) by the property "Link to", then AnyLogic will trigger the OnChange function of that parameter when the user changes something. If it is not directly linked you can still ensure it manually: Just use the set_param() function in the Action field of the user control, eg. like this: set_parameter(self.getDoubleValue()); – Florian Jun 26 '19 at 07:26
  • Ah ok, now I think I get your problem.....Your user is changing the value directly in the parameter value pop-up at model run time? I do not know of any way to capture this as an event, I do not think there is an elegant way to trigger the OnChange if the parameter is changed like that. I suggest: Use a proper user control module (Edit Box, Slider,....). – Florian Jun 26 '19 at 07:30
  • oh that idea of using the set_parameter on self is a genius idea Florian, thanks muchly, My problem is that during design time, when the user drags the agent of f the pallette and into the main, thrn changes in the configuration parameter in design time, don't update the look during design time. Further and most annoyingly, I have a lot of enums (OptionLists), and even though you set the control type as checkbox, it only gives you a text box, not a dopr down list a shown in the help, which is annoying – brett Jun 26 '19 at 11:03
  • Ah, ok, you talk about design time... This is where you will run into trouble.... You cannot program anything in AnyLogic that is executed at design time (such as in other simulation tools like in Technomatix Plant Simulation) because everything will have to get compiled first. You can only use mechanisms already available in the AL editor - and there is no OnChange handler or similar for design time events. AnyLogic is really not intended to do anything automatically at design time - everything has to be put/prepared in code that is then executed at model run time. – Florian Jun 26 '19 at 11:12