Command: gloop

Syntax

gloop { <elist> ... } {
    <command_block>
}

Description

Execute a set of commands on selected graphic primitives.

Parameters

Switches

Notes

The command block will be executed for each graphic primitive within <elist>. During each pass of the loop the system epointer this may be used to reference the relevant primitive.

When looping through a root group (a root group is a user-defined group identifier created by the group command), only top-level graphic primitives are processed, and child primitives (e.g. compound children and polygon holes/islands) are not processed. To ensure that child primitives get processed, the -rec switch is available. Group expressions (e.g. simple entities, filtered groups, group combinations) are treated as tree groups and all primitives are processed, including child entities, making the -rec switch redundant. Other commands which process group expressions (e.g. modify, shift, project) automatically process root groups recursively.

A jump to the end of the loop may be made with the continue command.

Before execution of the command block, the entity list is checked to remove any entities which have null values, and multiple occurrences of the same graphic primitive.

A break out of the loop may be made with a break command. However when an exit is made from the loop then this reverts to the value it had at the beginning of the loop command, unless that value was null. This facilitates nested gloops.

Examples

Print the names and types of all primitives.

gloop {
    tell <this.gtype, ':', this.name>
}

Get the maximum radius of all circles in a group.

numeric radius
gloop group_a,-ef=circle_filter {
    radius = max(radius,this.radius)
}

Loop through a root group.

#  Define a group
group mygroup
# Add a polygon and a hole to the group
entity poly = polygon -g=mygroup {(0,0), e:100, n:100, w:100, r }
entity hole = polygon -par=poly,-g=mygroup {(10,10), e:80, n:80, w:80, r }
# List all top-level entities in the group
gloop mygroup { tell this } # 1 entity will be listed
# List all entities in the group
gloop mygroup,-rec { tell this } # 2 entities will be listed

See Also

Commands:

filter, group, loop

Identifiers:

all (group), current_filter (filter), this (epointer)