innovyze / Open-Source-Support

This repository hosts open code that can be used in Innovyze products that support scripting. This includes Ruby for the UI/Exchange, SQL and other useful stuff. We stand on the shoulders of badgers and penguins.
44 stars 20 forks source link

WS Pro Control Fields #10

Closed Franklin-A closed 1 year ago

Franklin-A commented 1 year ago

I'm trying to create a UI Ruby Script for WS Pro which involves selection criteria based on an object's control settings but I cannot seem to get anything thing to work or find examples of similar script. For example:

I'd like to select 'wn_valves' where pipe diameter > 100 and mode ="THV" and opening=0. If this is not possible then is it possible to run a SQL query from the script (as selecting by this criteria is easy via SQL).

Any help on this would be greatly appreciated.

DaveFace commented 1 year ago

Hi @Franklin-A - Ruby scripts within the UI can't work with Control data, this script would only be possible using WS Pro Exchange. The reason is that the WSApplication.current_network method only returns the active 'Geometry' network and not the 'Control' network. Therefore the same limitation applies to the run_SQL method.

If you don't need this to be dynamic you could use SQL to set some user text fields to reflect the object's control settings, which you would be able to access via Ruby UI.

Franklin-A commented 1 year ago

Thanks for the reply @DaveFace. This was bugging me for a good while - and your answer is exactly why I couldn't find any examples or documentation on the matter. However, I did eventually manage to find a solution - the run_SQL method does actually work on the network's open 'control' table and therefore enables the selection of links & nodes based on control field criteria. I'm not sure if it'll work on all control fields and blobs (I've yet to experiment) but it's worked seamlessly on simple fields such as valve mode, valve opening, pipe closed, etc. In addition, I think it will work on writing to control fields - but only if the object has data in the control table already. If not, then it would be necessary to 'add control' to the object first.

DaveFace commented 1 year ago

I've just tested and that's correct for both read + write, good find! I'm not sure that is officially documented so (as you expect) it may not behave with all fields/blobs.