/* $VER: Align.AmiCAD 1.01e (© R.Florac, 9 août 1998) */

options results

signal on error
signal on syntax

'ALIGNEMENT=SELECT("Alignment"+CHR(10)+"Top"+CHR(10)+"Bottom"+CHR(10)+"Left"+CHR(10)+"Right")'
alignement=result
select
    when alignement=1 then ligne_base=50000
    when alignement=2 then ligne_base=0
    when alignement=3 then colonne_base=50000
    when alignement=4 then colonne_base=0
    otherwise exit
end

objets=0
'FIRSTSEL'; i=result
do while i>0
    objets=objets+1
    'LINE('i')'; ligne=result
    'COL('i')'; colonne=result
    select
	when alignement = 1 then do
	    if ligne<ligne_base then ligne_base=ligne
	end
	when alignement = 2 then do
	    if ligne>ligne_base then ligne_base=ligne
	end
	when alignement = 3 then do
	    if colonne<colonne_base then colonne_base=colonne
	end
	otherwise do
	    if colonne>colonne_base then colonne_base=colonne
	end
    end
    'NEXTSEL('i')'; i=result
end

if objets<2 then do
    'MESSAGE("Select two objects"+CHR(10)+"or more before"+CHR(10)+"calling this script")'
    exit
end

'SAVEALL(-1):O=FIRSTSEL:WHILE(O,IF(ALIGNEMENT<3,MOVE(O,0,'ligne_base'-LINE(O)),MOVE(O,'colonne_base'-COL(O),0)):O=NEXTSEL(O))'

exit

syntax:
erreur=RC
'MESSAGE("Syntax error"+CHR(10)+"in line 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
exit

error:
'MESSAGE("Error in line 'SIGL'")'
exit
