Create mapbasic loop to move and save window

668 views
Skip to first unread message

RobShaw

unread,
Feb 10, 2012, 9:21:32 AM2/10/12
to MapInfo-L
Hi

I am trying to create bit of mapbasic that will automate the export of
a map I have created. I have a table which contains the name for the
file I want, the lat and long for the centre of the window, and the
zoom scale I want.

My programming is ok but never used mapbasic before so the syntax of
how to interact with tables is muddling things. I have:

Dim i As Integer
For i = 1 to 244
Set Map Window 123456789 Center(mytable.long[i],mytable.lat[i]) Zoom
mytable.zm[i] Units("km")
Save 123456789 As mytable.name[i] Type "EMF" Width 800 Height 600
Next

Can anyone help with how I change the "mytable.xxx.[i]" part above
please?

thanks
Rob

Thomas Bacon

unread,
Feb 10, 2012, 9:50:36 AM2/10/12
to mapi...@googlegroups.com
Hi Rob,

It looks like you haven't fetched any rows so MapInfo doesn't know what
row to get the values from. Also, I would suggest using a 'Do while'
loop, rather than 'For...Next' as the later can produce unwanted results
when looping through an unpacked table for example. Based on your code,
I would imagine you want to do something like this:

Dim i as Integer,
fLong,fLat,fZoom as Float,
sName as String

Fetch first from mytable 'Fetches first row from table
Do while not EOT(mytable)

'Get values from row
fLong = mytable.long
fLat = mytable.lat
fZoom = mytable.zm
sName = mytable.name

Set Map Window 123456789 Center(fLong,fLat) Zoom fZoom Units
"km"
Save Window 123456789 As sName Type "EMF" Width 800 Height 600
Fetch next from mytable 'Fetch next row
Loop

I haven't checked this for errors, but that should point you in the
right direction!

Regards,

Tom Bacon
Graduate GIS Engineer
Asset Management South
Tel: 01444 472380
www.mouchel.com

Hi

thanks
Rob

--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en


The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. Mouchel Limited, Registered in England at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX Registered No : 1686040

Adrian Gray

unread,
Feb 10, 2012, 9:52:41 AM2/10/12
to mapi...@googlegroups.com
You want to loop through the table really. Have a look at the "Fetch"
statement for examples of table handling in MapBasic help.

Regards

Adrian Gray
Viewshed Limited
w: www.viewshed.co.uk
t: 01392 861946
Orchard House Church Road Silverton Exeter EX5 4PD
registered in England and Wales: 5661115 VAT# 876 6186 72

-----Original Message-----
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On
Behalf Of RobShaw
Sent: 10 February 2012 14:22
To: MapInfo-L
Subject: [MI-L] Create mapbasic loop to move and save window

Hi

thanks
Rob

--

Zery

unread,
Feb 10, 2012, 10:13:07 AM2/10/12
to MapInfo-L
Hi,

I just build something like this and it still in progress, one thing that I've noticed that the iteration will move faster then the zoom and pan and save window command to do their job, and what I get is only the last row that got saved to an image, in your case only your mytable.xxx.[244] is exported to EMF.

Regards,
Zery
Powered by Telkomsel BlackBerry®

From: "Thomas Bacon" <Thomas...@mouchel.com>
Date: Fri, 10 Feb 2012 14:50:36 -0000
Subject: RE: [MI-L] Create mapbasic loop to move and save window

Spencer Simpson

unread,
Feb 10, 2012, 10:29:00 AM2/10/12
to mapi...@googlegroups.com

Zery, are you saying you're only getting one EMF *file* out of this?  Or that there is a file for each value of mytable.name and they all have the same view in them?

 

If you're only getting one file, make sure that the save window statement is inside the loop, or that the names in the table are different….

 

 


Spencer

RobShaw

unread,
Feb 10, 2012, 11:07:57 AM2/10/12
to MapInfo-L
Many thanks,
> archives, feature requests, to visit our Wiki, visit the Welcome page athttp://groups.google.com/group/mapinfo-l?hl=en

Zery

unread,
Feb 10, 2012, 11:28:43 AM2/10/12
to MapInfo-L
Yes I only get one EMF or in my case are PNG file which is the last row, and yes the save window statement is inside the loop and the name of the save file was different. I use Do...Loop and For...Next they gave me the same result.

Regards,
Zery
Powered by Telkomsel BlackBerry®

From: "Spencer Simpson" <ssim...@baltometro.org>
Date: Fri, 10 Feb 2012 10:29:00 -0500

Spencer Simpson

unread,
Feb 10, 2012, 12:38:32 PM2/10/12
to mapi...@googlegroups.com

If you're going to keep up guessing about the structure of your code, I'd guess that an Update Window statement between the Set Window and the Save Window might help matters.    And make sure you have a "fetch first" before the loop and are getting your field values from aliases.

Zery

unread,
Feb 10, 2012, 9:25:39 PM2/10/12
to mapi...@googlegroups.com
Sorry, you are right :-)

'---------------------------------------------------------------------------------------------------
 nRowID = realGRTT.ROWID
 j = TableInfo(realGRTT, TAB_INFO_NROWS)
' Do While Not EOT(realGRTT)
     For i = nRowID To j
      Select * From realGRTT Where ROWID = i
      idwin = windowid(2)
Set Window idwin Front
    Run Menu Command M_QUERY_FIND_SELECTION_CURRENT_MAP
idwin = windowid(4)
Set Window idwin Front
Save Window idwin As "D:\file"+Str$(i)+".png" TYPE "PNG"
' nRowID = nRowID + 1
' Loop    
Next
'---------------------------------------------------------------------------------------------------

Regards,
Zery

RobShaw

unread,
Feb 10, 2012, 5:17:48 PM2/10/12
to MapInfo-L
Thanks. This is what I've come up with. I get a compile error
"unrecognised command on the flong = .... line. Any thoughts please?

Thanks
Rob
Declare Sub mytest(windname As string)
Sub mytest(windname As string)
Dim fLat As Float
Dim fLong As Float
Dim fZoom As Float
Dim sname as String
Dim tabname as String

tabname = TableInfo(1,1)
Fetch first from tabname

Do while not EOT(tabname)
fLong = tabname.long
fLat = tabname.lat
fzoom = tabname.dist
sname = tabname.CCG

Set Map Window windname Center(fLong,fLat) Zoom fZoom Units "km"
Save Window windname As sname+".png" Type "PNG" Width 10.8958 Units
"in" Height 9.07292 Units "in" Resolution 150

Fetch next from tabname
Loop
End sub

On Feb 10, 2:50 pm, "Thomas Bacon" <Thomas.Ba...@mouchel.com> wrote:
> archives, feature requests, to visit our Wiki, visit the Welcome page athttp://groups.google.com/group/mapinfo-l?hl=en
Message has been deleted

RobShaw

unread,
Feb 11, 2012, 4:35:35 AM2/11/12
to MapInfo-L
I get an unrecognised command error on this. Any ideas please?

Thanks
Rob
Declare Sub mytest(windname As string)
Sub mytest(windname As string)
Dim fLat As Float
Dim fLong As Float
Dim fZoom As Float
Dim sname as String
Dim tabname as String

tabname = TableInfo(1,1)
Fetch first from tabname

Do while not EOT(tabname)
fLong = tabname.long
fLat = tabname.lat
fzoom = tabname.dist
sname = tabname.CCG

Set Map Window windname Center(fLong,fLat) Zoom fZoom Units "km"
Save Window windname As sname+".png" Type "PNG" Width 10.8958 Units
"in" Height 9.07292 Units "in" Resolution 150

Fetch next from tabname
Loop
End sub

> > ------------------------------------------------------------------------
>
> > Spencer
>
> > *From:* Zery [mailto:zery...@gmail.com]
> > *Sent:* Friday, February 10, 2012 11:29 AM
> > *To:* MapInfo-L
> > *Subject:* Re: [MI-L] Create mapbasic loop to move and save window
>
> > Yes I only get one EMF or in my case are PNG file which is the last
> > row, and yes the save window statement is inside the loop and the name
> > of the save file was different. I use Do...Loop and For...Next they
> > gave me the same result.
>
> > Regards,
>
> > Zery
>
> > Powered by Telkomsel BlackBerry�
>
> > ------------------------------------------------------------------------
>
> > *From: *"Spencer Simpson" <ssimp...@baltometro.org
> > <mailto:ssimp...@baltometro.org>>
>
> > *Sender: *mapi...@googlegroups.com <mailto:mapi...@googlegroups.com>
>
> > *Date: *Fri, 10 Feb 2012 10:29:00 -0500
>
> > *To: *<mapi...@googlegroups.com <mailto:mapi...@googlegroups.com>>
>
> > *ReplyTo: *mapi...@googlegroups.com <mailto:mapi...@googlegroups.com>
>
> > *Subject: *RE: [MI-L] Create mapbasic loop to move and save window
>
> > Zery, are you saying you're only getting one EMF **file** out of
> > this?  Or that there is a file for each value of mytable.name and they
> > all have the same view in them?
>
> > If you're only getting one file, make sure that the save window
> > statement is inside the loop, or that the names in the table are
> > different....
>
> > ------------------------------------------------------------------------
>
> > Spencer
>
> > *From:* Zery [mailto:zery...@gmail.com]
> > <mailto:[mailto:zery...@gmail.com]>
> > *Sent:* Friday, February 10, 2012 10:13 AM
> > *To:* MapInfo-L
> > *Subject:* Re: [MI-L] Create mapbasic loop to move and save window
>
> > Hi,
>
> > I just build something like this and it still in progress, one thing
> > that I've noticed that the iteration will move faster then the zoom
> > and pan and save window command to do their job, and what I get is
> > only the last row that got saved to an image, in your case only your
> > mytable.xxx.[244] is exported to EMF.
>
> > Regards,
>
> > Zery
>
> > Powered by Telkomsel BlackBerry�
>
> > ------------------------------------------------------------------------
>
> > *From: *"Thomas Bacon" <Thomas.Ba...@mouchel.com
> > <mailto:Thomas.Ba...@mouchel.com>>
>
> > *Sender: *mapi...@googlegroups.com <mailto:mapi...@googlegroups.com>
>
> > *Date: *Fri, 10 Feb 2012 14:50:36 -0000
>
> > *To: *<mapi...@googlegroups.com <mailto:mapi...@googlegroups.com>>
>
> > *ReplyTo: *mapi...@googlegroups.com <mailto:mapi...@googlegroups.com>
>
> > *Subject: *RE: [MI-L] Create mapbasic loop to move and save window
> >www.mouchel.com<http://www.mouchel.com>
> > email to mapi...@googlegroups.com <mailto:mapi...@googlegroups.com>
> > To unsubscribe from this group, go to:
> >http://groups.google.com/group/mapinfo-l/subscribe?hl=en
> > For more options, information and links to MapInfo resources (searching
> > archives, feature requests, to visit our Wiki, visit the Welcome page at
> >http://groups.google.com/group/mapinfo-l?hl=en
>
> > --
> > You received this message because you are subscribed to the
> > Google Groups "MapInfo-L" group.To post a message to this group, send
> > email to mapi...@googlegroups.com <mailto:mapi...@googlegroups.com>

Thomas Bacon

unread,
Feb 13, 2012, 4:57:09 AM2/13/12
to mapi...@googlegroups.com
Hi Rob,

You need to use alias variables if you are substituting a table (or column) name with a variable:

Declare Sub mytest(windname As string)
Sub mytest(windname As string)
Dim fLat As Float
Dim fLong As Float
Dim fZoom As Float
Dim sname as String
Dim tabname as String

Dim aFLong, aFLat, aFZoom, aSName as Alias

tabname = TableInfo(1,1)
aFLong = tabname & ".long" '<- Assign alias values
aFLat = tabname & ".lat"
aFZoom = tabname & ".dist"
aSName = tabname & ".CCG"

Fetch first from tabname

Do while not EOT(tabname)
fLong = aFLong '<- Use alias rather than string variable
fLat = aFLat
fzoom = aFZoom
sname = aSName

...


Hope this helps,

Tom Bacon
Graduate GIS Engineer
Asset Management South
Tel: 01444 472380
www.mouchel.com

Reply all
Reply to author
Forward
0 new messages