Making Layout Window Active via Mapbasic code?

113 views
Skip to first unread message

Matthew Hirsch

unread,
Feb 14, 2024, 6:09:07 PMFeb 14
to MapInfo-L
I am trying to rebuild an old MB script that would automatically create and print maps.  

This was written for 32-bit Mapinfo and worked flawlessly.   The issue is we cannot add the ESRI street map layer to those older versions of MIP.

I have a workspace open in 64 bit MIP with a layout page that contains an embedded map.

The Layout has not been renamed so is Layout
I've renamed the layout's embedded map to "Map1"

I need to figure out how to make Map1 active (or the front window) so I can adjust the map, then make the entire layout page active (or the front window) to print via printwin.
 
Is there a command to make a named window active?    And is there a way to make the layout window active?

Thank you.

Matthew Hirsch

Peter Horsbøll Møller

unread,
Feb 18, 2024, 6:01:44 AMFeb 18
to mapi...@googlegroups.com

Hi Matthew

 

As you know, MapInfo Pro uses ID to refer to windows.

The trick is to find the ID from the name.

 

WINDOWLib which is part of the MapBasic Common Libraries on GitHub has a function that allows you to get the ID from a window title/name: WINGetIDFromTitle.

 

You can know use this function to assign the ID to a couple of variables:

 

Dim nLayoutID, nEmbeddedMapID As Integer

 

nLayoutID         = WINGetIDFromTitle("Layout")

nEmbeddedMapID    = WINGetIDFromTitle("Map1")

 

We also have functions that can help you find frames with maps in a layout.

It could look like this:

 

nNumFrames  = LayoutInfo(nLayoutID,LAYOUT_INFO_NUM_ITEMS)

For k = 1 to nNumFrames

      If LayoutItemInfo(nLayoutID, k, LAYOUT_ITEM_INFO_TYPE) = LAYOUT_ITEM_TYPE_MAPPER then

            nMID = LayoutItemInfo(nLayoutID, k, LAYOUT_ITEM_INFO_WIN) 'get mapper frame id

      End If

Next

 

I hope this helps

 

Peter

 

Peter Horsbøll Møller
Principal Sales Engineer - Distinguished Engineer

 

From: mapi...@googlegroups.com <mapi...@googlegroups.com> On Behalf Of Matthew Hirsch
Sent: 15. februar 2024 00:09
To: MapInfo-L <mapi...@googlegroups.com>
Subject: [MI-L] Making Layout Window Active via Mapbasic code?

 

This message originated Externally. Use proper judgement and caution with attachments, links, or responses.

 

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

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapinfo-l/1342c5d7-7c64-425a-9fd9-5285e144128dn%40googlegroups.com.

Matthew Hirsch

unread,
Feb 29, 2024, 12:29:29 PMFeb 29
to MapInfo-L
Peter, 
I have the  WINDOWLib.def file, but am not sure how to activate it in Mapinfo or where to save it.

I need to be able to create an MB file that we can drop into Mapinfo that has these functions working without needing to run additional MBs or MBXs.   

The MB file we use is an all in one that selects a portion of a boundary table, adds the selection as a layer to the map, zooms to that query, then activates the layout window and prints the layout to a PDF.  It then finds the next portion of the boundary file and repeats the process over and over. 


Here is the code with notes and a few of your suggested lines.  (This worked perfectly in 32bit when the map and layout pages were separate.)


!Version 700
!Charset WindowsLatin1

'Make sure window order goes map then layout.

'After running boundmaker, open and include Land or Port here.

Select COL1, COL2, Scale from Land group by COL1, Scale into Layinfo
 
Set CoordSys Layout Units "in"
 
dim ID as string
dim Title as string
dim Lastrow as integer
Dim nLayoutID As Integer
Dim nEmbeddedMapID As Integer
Dim nNumFrames As Integer

---- These do not work as the WINGetIDFromTitle is not defined due to not having the WINDOWLib.def file active. -----

nLayoutID         = WINGetIDFromTitle("Layout")
nEmbeddedMapID    = WINGetIDFromTitle("Map1")
---

fetch first from layinfo
ID=layinfo.COL1
Title=layinfo.COL2
 
select * from land where COL1 = ID into mapex
select * from zones where Fran = ID into select_zones

Add Map Layer select_zones
Add Map Layer select_zones
Add Map Layer mapex
Set Map Window frontwindow() Zoom Entire layer 1
dim Scale as string*3
scale = MapperInfo( FrontWindow(), 2)
Set Map
  Layer 1 Display Off
  Layer 2
    Display Global
    Global Pen (3,65,16711680) Brush (15,16765136) Symbol (35,0,12) Line (1,2,0) Font ("Arial",0,9,0)
    Label Line None Position Center Font ("Arial",0,9,0) Pen (1,2,0)
      With Zone
      Parallel On Auto Off Overlap Off Duplicates On Offset 2
      Visibility On
  Layer 3
    Display Global
    Global Pen (1,2,0) Brush (1,16777215,16777215) Symbol (35,0,12) Line (1,2,0) Font ("Arial",0,9,0)
    Label Line None Position Center Font ("Arial",0,9,0) Pen (1,2,0)
      With Zone
      Parallel On Auto Off Overlap Off Duplicates On Offset 2
      Visibility On

Set Map  Order Layers 2 DestGroupLayer 0 Position 7

================================== NEED TO SELECT OUT OF LAYOUT'S MAP AND ONTO LAYOUT====================================

'Get title (ID) and scale text locations from saved workspace and include here.

run menu command 622
Create Text Title (1.6465,0.1715) (6.0889,0.4) Font ("Arial",1,14,0)
Create Text Scale     (7.5958,0.4347) (7.7,0.5111) Font ("Arial",1,5,0)
Set Window frontwindow() title ID + "_map"

printwin

================================== NEED TO SELECT LAYOUT'S MAP AGAIN ====================================

fetch last from layout1
lastrow = layout1.rowid
select * from layout1 where rowid>lastrow-2
delete from selection

undim ID
undim Title
undim Scale
undim Lastrow

'Replicate this command by land or port rows-1
Run Application "Mult2land.WOR"


-------- Mult2land.WOR

!Workspace
!Version 700
!Charset WindowsLatin1


dim ID as string
dim Title as string
dim Lastrow as integer

fetch next from layinfo
ID=layinfo.COL1
Title=layinfo.COL2
 
select * from land where COL1 = ID into mapex
select * from zones where Fran = ID into select_zones
run menu command 620
Add Map Layer select_zones
Add Map Layer select_zones
Add Map Layer mapex
Set Map Window frontwindow() Zoom Entire layer 1
dim Scale as string*3
scale = MapperInfo( FrontWindow(), 2)
Set Map
  Layer 1 Display Off
  Layer 2
    Display Global
    Global Pen (1,2,0) Brush (2,16765136,16777215) Symbol (35,0,12) Line (1,2,0) Font ("Arial",0,9,0)
    Label Line None Position Center Font ("Arial",0,9,0) Pen (1,2,0)
      With Zone
      Parallel On Auto Off Overlap Off Duplicates On Offset 2
      Visibility On
  Layer 3
    Display Global
    Global Pen (4,65,16711680) Brush (1,16777215,16777215) Symbol (35,0,12) Line (1,2,0) Font ("Arial",0,9,0)
    Label Line None Position Center Font ("Arial",0,9,0) Pen (1,2,0)
      With Zone
      Parallel On Auto Off Overlap Off Duplicates On Offset 2
      Visibility On

Set Map  Order Layers 3 DestGroupLayer 0 Position 6
Set Map  Order Layers 2 DestGroupLayer 0 Position 86

'Get title (ID) and scale text locations from saved workspace and include here.
run menu command 622
Create Text Title (1.6465,0.1715) (6.0889,0.4) Font ("Arial",1,14,0)
Create Text Scale     (7.5958,0.4347) (7.7,0.5111) Font ("Arial",1,5,0)
Set Window frontwindow() title ID + "_map"

printwin

fetch last from layout1
lastrow = layout1.rowid
select * from layout1 where rowid>lastrow-2
delete from selection

undim ID
undim Title
undim Scale
undim Lastrow

Peter Horsbøll Møller

unread,
Mar 5, 2024, 2:20:13 AMMar 5
to mapi...@googlegroups.com

Hi Matthew

 

Ah, you are running this through the MapBasic window.

Well, in that case you can’t use the two methods I referred to. They can only be used through a compiled MapBasic application.

 

But…

 

If you make sure the layout, is the active window, you can get that ID using this statement:

nLayoutWID         = FrontWindow()

And when you have the ID of the layout, you can also get to the frame and the map window in that frame.

For this to work best I would recommand assigning a name to the fram with the map, as you can see below:

 

You can use a MapBasic function to get to a frame with a specific name:

The last parameter 1 equals LAYOUT_ITEM_TYPE_MAPPER

 

nFrameID = LayoutItemID(nLayoutWID, "Map-1", 1

 

Once you have the ID of the frame with the map, you can also get to the Id of the map itself:

The last parameter 5 equals LAYOUT_ITEM_INFO_WIN which will give you the Window ID.

 

nMapWID = LayoutItemInfo(nLayoutWID, nFrameID, 5)

Reply all
Reply to author
Forward
0 new messages