Channel Group Object Agents

 

The Channel Group Object Agents provide access to defined channel groups. The ChannelGroup()Object Agent constructor returns a ChannelGroup Object Agent. This Object Agent is similar to a standard Layout Object Agent in its interface, but supports only a limited subset of the methods and data members. Its primary purpose is to provide a means of enumerating Channel Groups in Layout, some of which may be "hidden" (i.e., unassociated with an actual object).

ChannelGroup()will return 'nil' if no channel groups exist in Layout (which is a highly unlikely situation, but you should still code for the possibility in the interests of good programming).

Calling ChannelGroup() without a specific channel group name will return the first channel group defined in the system. From this starting point, all other existing channel groups can be iterated through using the next() method. As with any Layout Object Agent, next() will return 'nil' when no further channel groups exist.

The ChannelGroup() constructor also accepts a channel group identifier (as a string) so that you can generate an Object Agent for a specific channel group. For example, to access the channel group generated by the LW_MasterChannel plug-in use the following code:

group = ChannelGroup("MC");

Of course, if the LW_MasterChannel plug-in is not active, then this call to ChannelGroup()will return 'nil.'

To address sub-group processing, ChannelGroup()accepts an existing Channel Group Object Agent. When an agent is provided, the constructor will use it as the parent to locate further Channel Groups, and will return the first sub-group defined under this parent. Recursion is needed to employ this action and access all the defined Channel Groups. (See example code.)

The ChannelGroup() constructor now accepts two ChannelGroup Object Agents as arguments.  Passing one will return the first sub-group found under the specified channel group, however, two are needed in order to iterate through all sub-groups found under a specified channel group.  The second ChannelGroup Object Agent is considered the "current" channel, and any sub-group defined following it will be returned (or 'nil', if no further sub-groups exist).

Data Members

name
name is the name of the channel group for which the Object Agent serves as proxy.

parent
parent holds the parent channel group of the current Object Agent. If no parent exists, this data member will be 'nil.'

Methods

firstChannel(), nextChannel()
firstChannel()and nextChannel() each returns a Channel Object Agent (see methods and data members available from Channel Object Agents).

next()
next() returns the next channel group in the list.

Example:

@warnings
@script channel
@version 2.4.1

ChGroup;

create: channel
{
    ChGroup = nil;

     // locate the channel group recursively
    GetGroupName(channel.id,ChannelGroup());

     // was the channel group found?
    if(ChGroup != nil)
           info(ChGroup.name + "." + channel.name);
}

GetGroupName: cid, chgroup
{
    if(ChGroup) return;
    while(chgroup)
    {
          chchannel=chgroup.firstChannel();
          while(chchannel)
          {
              if (chchannel.id == cid)
              {
                    ChGroup=chgroup;
                    last;
              }
              chchannel=chgroup.nextChannel();
         }
         last if ChGroup;
         // recursive call
         GetGroupName(cid,ChannelGroup(chgroup));
         chgroup=chgroup.next();
    }
}