Эта страница является
переводом страницы
DesignSwitch. Перевод выполнен на 100%.
Switching between projects
Setting of automatic switching between projects in i3pro.
documentation was last updated on 16.6.2023
Automatic switching between projects allows to start another project by an event set earlier. The following can be used as an event: a user chooing a project himself from a list of projects downloaded on the panel, connection of a panel to a required Wi-Fi network or a panel getting coordinates set earlier.
Switching between projects works only with projects that were downloaded from the cloud on a panel.
Setting Project Selection from List of Projects Downloaded on Panel
1 Download a sample project.
2 Merge the example with your project.
The project will get an additional page with a List that will display all projects downloaded from the cloud on a panel. When an item of the list is pressed, you'll go to the selected project.
To go to the initial project or to choosing another project, switching to projects from a list must be added to the additional project.
An example of the script
IR.AddListener(IR.EVENT_START, 0, function() // Actions are performed at start
{
// getting the number of projects
var l_iCount = IR.GetDesignsCount();
//get a list
var list = IR.GetItem("Page 1").GetItem("Item 1");
// making a list of projects
for(var i = 0; i < l_iCount; i++)
{
// get a link to the project
var l_sName = IR.GetDesignByIndex(i);
//сhecking that the project is downloaded from the cloud
if(l_sName.CloudID > 0){
// create a list item (ListItem)
var item = list.AddItem("Popup 1", {
Name: {
Text: l_sName.OriginalName
}
});
//setting custom data to a list item
item.SetData({name: l_sName.OriginalName, id: l_sName.CloudID})
// execute a function when the button is released
item.SetReleaseAction(function(in_item, in_subItem){
var name = in_item.Data.name;
var id = in_item.Data.id;
//switch to the selected project
IR.DesignSwitch(name, id);
IR.Log(name + " " + id);
});
}
}
});
Used Methods:
- IR.GetDesignsCount - counts the number of visualization projects in the app memory;
- IR.GetDesignByIndex - ges a link to a project as an object by calling it by the index in the list of downloaded projects;
- IR.DesignSwitch - switches between visualization projects in the panel memory.
Setting Automatic Project Switch by Name of Wi-Fi Network
1 Download a sample project.
2 Merge the example with your project or copy the script from the example to you project.
3 Open the script of the example and change the following:
- the Project1 name with the name of a project that will be opned when a panel is connected to ssid1 Wi-Fi network;
- the ssid1' name of Wi-Fi network with the name of Wi-Fi network connection to which will open Project1;
- the Project2 name with the name of a project that will be opned when a panel is connected to ssid2 Wi-Fi network;
- the ssid2 name of Wi-Fi network with the name of Wi-Fi network connection to which will open Project2;
- the Project3' name with the name of a project that will be opned when a panel is connected to other Wi-Fi networks or mobile internet.
This solution allows to switch automatically between automation projects (for example, several apartments and an country house can be united this way). The script can be modified, if it is required and additional variables with projects and the name of a Wi-Fi network can be added.
To switch between projects, all united projects must contain this script, and the parameters must be identical.
An example of the script
(function(){
/**
* Auto project selector
*/
function ProjectSelector(projects)
{
this.trigger = "System.Net.SSID";
this.projects = projects;
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, this.select, this);
IR.SubscribeTagChange(this.trigger);
IR.AddListener(IR.EVENT_START, 0, this.analize, this);
}
/**
* Select project by trigger
*/
ProjectSelector.prototype.select = function()
{
var selectID = 0;
var selectName = "";
var ssid = IR.GetVariable(this.trigger);
var unknownItem;
for(var j = 0; j < this.projects.length; j++)
{
var item = this.projects[j];
if(item.CloudID == 0)
IR.Log("ProjectSelector: " + item.projectName + " is not found");
if(item.ssid == undefined)
unknownItem = item;
if(item.ssid == ssid && item.CloudID)
{
selectID = item.CloudID;
selectName = item.projectName;
break;
}
}
// не один проект не подошел
if(selectID == 0 && unknownItem != undefined)
{
selectID = unknownItem.CloudID;
selectName = unknownItem.projectName;
}
var currentProject = IR.GetCurrentDesign();
if(currentProject)
{
if(selectID != currentProject.CloudID)
{
IR.Log("ProjectSelector: " + selectName + " will be selected");
IR.DesignSwitch(selectName, selectID);
}
else
IR.Log("ProjectSelector: " + selectName + " selecte skipped, is already started");
}
}
/**
* Analize project names and find his clouds ids
*/
ProjectSelector.prototype.analize = function()
{
var count = IR.GetDesignsCount();
for(var i = 0; i < count; i++)
{
var project = IR.GetDesignByIndex(i);
for(var j = 0; j < this.projects.length; j++)
{
var item = this.projects[j];
if(item.projectName == project.OriginalName)
item.CloudID = project.CloudID;
}
}
this.select();
}
/**
* Make instance
*/
new ProjectSelector([
{
ssid: "ssid1",
projectName: "Project1",
},
{
ssid: "ssid2",
projectName: "Project2",
},
{
/* unknown ssid */
projectName: "Project3",
}
]);
})();
Used Methods:
- IR.GetDesignsCount - counts the number of visualization projects in the app memory;
- IR.GetDesignByIndex - ges a link to a project as an object by calling it by the index in the list of downloaded projects;
- IR.GetVariable - selection of a token to activate an event (the ID of a Wi-Fi network is used in this example ("System.Net.SSID"));
- IR.DesignSwitch - switches between visualization projects in the panel memory.
- IR.SetGlobalListener - creates a global listener;
- IR.SubscribeTagChange - subscribes to a tag.