> For the complete documentation index, see [llms.txt](https://docs.calwincloud.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.calwincloud.com/calwin-script/system-script-events/helper-procedure-repository.md).

# Helper Procedure Repository

Repository of helper procedures and functions that can be copied in to your script and be used from many of the different system scripts, hardware scripts etc.

### Finding elements on a product

```objectpascal
{Returns True if the product has elements of the specified elementkind 
in the specified square}
function HasElementOfKindInSquare(aProduct:TProductWrapper; 
   aElementKind:TElementKind; aSquare:integer):boolean; 
var
  I: integer;
begin
  Result := False;
  for I := 0 to aProduct.ElementList.Count - 1 do    
  begin
    if (aProduct.Elementlist.Elements[I].Elementkind = aElementKind)
      and (aProduct.Elementlist.Elements[I].Square[1] = aSquare) then
    begin
      Result := True;
      Exit;
    end;
  end;
end;
```

```objectpascal
{Returns the "Piece sash" element in the specified square and level if found}
function GetSashElementInSquare(aProduct:TProductWrapper; aSquare:integer; aLevel:TLevel):TCustomElementWrapper; 
var
  I: integer;
begin
  Result := nil;
  for I := 0 to aProduct.ElementList.Count - 1 do    
  begin
    if (aProduct.Elementlist.Elements[I].Elementkind in [ekPieceSash, ekPieceDoorBlade])
      and (aProduct.Elementlist.Elements[I].Square[1] = aSquare) 
      and (aProduct.Elementlist.Elements[I].Level = aLevel) then
    begin
      Result := aProduct.Elementlist.Elements[I];
      Exit;
    end;
  end;
end;
```
