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
{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;
{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;