I did it.
...and if some of you guru/experts read this, please be gentle with critics:)
------------------------------------------------------------------------
Include "MAPBASIC.DEF"
Include "ICONS.DEF"
Include "MENU.DEF"
Type Points
x As Float
y As Float
End Type
Declare sub main
Sub Main
dim iMapWindowID as Integer
dim iLayoutWindowID as Integer
dim sPrinterName as String
dim s_Paper as string
dim s_Orient as string
dim i_Paper as smallint
dim mar, h_Pap, h_Pap2, w_Pap, w_MapFrame, h_MapFrame, w_Table, h_Table, w_Logo as Float
dim pT, f1, f2, f3, f4, t1, t2, t3, t4 as Points
dim centerX, centerY, mapZoom, mapScale, minX, maxX, minY, maxY, dX, dY, LmaxY, LminY as Float
dim a, b, b1, b2, Yp, Rcm, R as Float
'==============================================================
' Basic setup
Set Format Number "9,999.9"
print MapperInfo(FrontWindow(),MAPPER_INFO_COORDSYS_CLAUSE_WITH_BOUNDS)
Set Distance Units "m"
Set Paper Units "cm"
sPrinterName = WindowInfo(FrontWindow(),WIN_INFO_PRINTER_NAME)
print sPrinterName
' - Paper format
s_Paper = "A4"
s_Orient = "Landscape"
' - Papersize.def value
i_Paper = 9
' - dimension of paper
h_Pap=21
w_Pap=29.7
' - margine in cm
mar = 0.6
' - Coordinates of starting point in layout
pT.x = 1
pT.y = 1
' - height of custom table area
h_Table=1.7
w_Table = w_Pap-2*pT.x
h_MapFrame = h_Pap-2*pT.y-h_Table
w_MapFrame = w_Pap-2*pT.x
w_Logo = h_Table*2.25
iMapWindowID = WindowID(FrontWindow())
minX = MapperInfo(FrontWindow(),MAPPER_INFO_MINX)
maxX = MapperInfo(FrontWindow(),MAPPER_INFO_MAXX)
minY = MapperInfo(FrontWindow(),MAPPER_INFO_MINY)
maxY = MapperInfo(FrontWindow(),MAPPER_INFO_MAXY)
' - mapper window coordinates
Set Map Window FrontWindow() Layer 0 Editable On
Create Point (minX,maxY) Symbol (69,0,24,"MapInfo Cartographic",0,0)
Create Point (maxX,maxY) Symbol (69,0,24,"MapInfo Cartographic",0,0)
Create Point (maxX,minY) Symbol (69,0,24,"MapInfo Cartographic",0,0)
Create Point (minX,minY) Symbol (69,0,24,"MapInfo Cartographic",0,0)
'=================================================================
' minY i max Y coordinate calculation
dX = maxX - minX
dY = maxY - minY
Rcm = dX/w_MapFrame
R = Rcm*100
b1 = dY/R*100
b2 = (h_MapFrame-b1)/2
Yp = b2*R/100
LmaxY = maxY + Yp
LminY = minY - Yp
' - corner points of layout map frame
Create Point (minX,LmaxY) Symbol (69,0,48,"MapInfo Cartographic",0,0)
Create Point (maxX,LmaxY) Symbol (69,0,48,"MapInfo Cartographic",0,0)
Create Point (maxX,LminY) Symbol (69,0,48,"MapInfo Cartographic",0,0)
Create Point (minX,LminY) Symbol (69,0,48,"MapInfo Cartographic",0,0)
'==============================================================
' Layout creation
'==============================================================
Layout
Position (0,0) Units "cm"
Width (w_Pap-mar*2) Units "cm"
Height (h_Pap-mar*2) Units "cm"
Max
iLayoutWindowID = WindowID(FrontWindow())
Set CoordSys Layout Units "cm"
'==============================================================
' layout points
'==============================================================
' - frame points
f1.x = pT.x
f1.y = pT.y
f2.x = pT.x+w_MapFrame
f2.y = pT.y
f3.x = pT.x
f3.y = pT.y+h_MapFrame
f4.x = pT.x+w_MapFrame
f4.y = pT.y+h_MapFrame
' - table points
t1.x = f3.x
t1.y = f3.y
t2.x = f4.x
t2.y = f4.y
t3.x = t1.x
t3.y = t1.y+h_Table
t4.x = t1.x+w_Table
t4.y = t2.y+h_Table
'==============================================================
' Map frame in Layout
Create Frame (f1.x,f1.y) (f4.x, f4.y)
Pen (20,65,16777215)
Brush (2,16777215,16777215)
From Window iMapWindowID
FillFrame On
'==============================================================
' 4 symbols for corners
Create Point (f1.x, f1.y) Symbol (69,0,24,"MapInfo Cartographic",0,0)
Create Point (f2.x, f2.y) Symbol (69,0,24,"MapInfo Cartographic",0,0)
Create Point (f3.x, f3.y) Symbol (69,0,24,"MapInfo Cartographic",0,0)
Create Point (f4.x, f4.y) Symbol (69,0,24,"MapInfo Cartographic",0,0)
' label of real world coordinates
' Upper left minX*maxY
Create Text str$(minX) (f1.x-0.4, f1.y+1.6) (f1.x+1.95, f1.y+2.7) Font ("Arial",0,8,6316128,16777215) Angle 90
Create Text str$(LmaxY) (f1.x+0.1, f1.y-0.4) (f1.x+2.35, f1.y) Font ("Arial",0,8,6316128,16777215)
' upper right maxX*maxY
Create Text str$(maxX) (f2.x+0.05,f2.y+1.6) (f2.x+2.5, f2.y+2.0) Font ("Arial",0,8,6316128,16777215) Angle 90
Create Text str$(LmaxY) (f2.x-0.6, f2.y+1.6) (f2.x-1.6, f2.y-0.4) Font ("Arial",0,8,6316128,16777215)
' down left minX*minY
Create Text str$(minX) (f3.x-0.4,f3.y-0.1) (f3.x+2.5, f3.y+2.0) Font ("Arial",0,8,6316128,16777215) Angle 90
Create Text str$(LminY) (f3.x+0.1, f3.y-0.45) (f3.x+2.35, f3.y) Font ("Arial",256,8,6316128,16777215)
' down right maxX*minY
Create Text str$(maxX) (f4.x+0.05,f4.y-0.1) (f4.x+2.5, f4.y+2.0) Font ("Arial",0,8,6316128,16777215) Angle 90
Create Text str$(LminY) (f4.x-0.6, f4.y+1.6) (f4.x-1.6, f4.y-0.45) Font ("Arial",256,8,6316128,16777215)
Set Layout Ruler On Pagebreaks On Frame Contents On
' Zoom 82.0466 Center (3.98168,5.6053) Extents To Fit
Set Window FrontWindow() Autoscroll On Snap Mode On Enhanced On
' Run Command uniqueStringName
Set Window FrontWindow() Title " ("+s_Paper+"-"+s_Orient+")"
dim kom as string
kom = "Set Window FrontWindow() Printer Name """+sPrinterName+""" Orientation "+s_Orient+" Copies 1 Papersize "+i_Paper+""
' Print kom
run command kom
End Sub
--------------------------------------------------------------------------------------------------