From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Map generated by the script and transfered into REPORT

Solved!
Go to solution

Hello everybody.

 

I am wondering whether it is possible to use a script to generate a map in VIEW with our test route, transfer it to REPORT and then set the "Keep aspect ratio" setting for the map object? I found a script for the transfer between the VIEW and REPORT here on the forum but the rest keeps a mystery for me. I tried to record a script via Macro Recording tool when doing this process in GUI but I got only 

call View.Sheets("Sheet 1").Areas("Area : 1").SplitLeft("",-1)
View.Sheets("Sheet 1").Areas("Area : 2").DisplayObjType = "Map"
' Call WndShow("VIEW")
Call ScriptStart("C:\PROGRAM FILES\NATIONAL INSTRUMENTS\DIADEM 2020\Resource\VwLayTrans", "VWTransViewRep", False)

 Can you please help how to select channels for longitude, latitude, how to select zoom level and so on?

 

Thank you

 

Marek

0 Kudos
Message 1 of 12
(4,853 Views)

Hi Marek,

 

You need to programmatically set the Map properties while it's still in VIEW, because what gets transported over to REPORT is just an image of the current map area state.  Then in REPORT you can programmatically set any image properties you want, such as original aspect ratio, like this:

Set Sheet = View.Sheets(1)
Set Area = Sheet.Areas(3)
Set Map = Area.DisplayObj
AreaName = Area.Name
Map.MapType = "Cache"
Map.ZoomLevel = 17
Map.ShowTrack = True
Map.MapMovingMode = "Pan"
Map.UseCache = True
Map.CachePath = "\Examples\Documents\MapCache\"
Map.SynchronisationChannelName = "[1]/TimeStamp"
Map.LongitudeChannelName = "[1]/Longitude"
Map.LatitudeChannelName = "[1]/Latitude"
Map.ColorChannelName = "[2]/Speed"
Map.SynchronisationDimension = "X-Cursor"
Map.LongitudeDimension = "Y-Cursor"
Map.LatitudeDimension = "Z-Cursor"

Call ScriptStart(ProgramDrv & "Resource\VwLayTrans", "VWTransViewRep", False)

Set Sheet = Report.Sheets(Report.Sheets.Count)
Set Image = Sheet.Objects(AreaName)
Image.UseOriginalRatio = TRUE

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 2 of 12
(4,809 Views)

Hello Brad,

 

thank you very much for your quick reply.

I must admit that your code didn't work for me (copy/paste method), I guess I am still learning. But it showed me a way to go. I succeeded in creating one big area with a map in VIEW but I don't know how to follow. I used this code for this:

Dim oMySheet, oMyChart, oMyArea, oMyNewArea, oMyCurve
Call View.NewLayout()
Set oMySheet = View.ActiveSheet
oMySheet.Name = "RouteMap"
Set oMyArea = oMySheet.ActiveArea
oMyArea.Active = True
oMyArea.DisplayObjType = "Map"

 

How do I connect your code to mine?

 

Thank you

Marek

0 Kudos
Message 3 of 12
(4,753 Views)

Hi Marek,

 

It looks like you're programmatically turning the active Area on the active Sheet into a map Area.  So to edit the script I sent you before to connect with that scenario, try replacing the first 2 lines of the script with these commands to use the active Area on the active Sheet in VIEW: 

Set Sheet = View.ActiveSheet
Set Area = Sheet.ActiveArea

If that doesn't work, please post the error message you get.  Also, can you remind me which DIAdem version you're using?

 

Brad Turpin

Principal Technical Support Engineer
NI

Message 4 of 12
(4,745 Views)

Hi Brad.

 

I tried replacing the two lines as you suggested but it didn't help. I got a map in the VIEW but it shows some generic location and the route is missing. My version of DIAdem is DIAdem 20.0.0f7762 (64-bit), Packet 1 is Professionalk edition. I didn't get any error message. Here is the complete code for reference: 

Dim oMySheet, oMyChart, oMyArea, oMyNewArea, oMyCurve
Call View.NewLayout()
Set oMySheet = View.ActiveSheet
oMySheet.Name = "RouteMap"
Set oMyArea = oMySheet.ActiveArea
oMyArea.Active = True
oMyArea.DisplayObjType = "Map"

Set Sheet = View.ActiveSheet
Set Area = Sheet.ActiveArea
Set Map = Area.DisplayObj
AreaName = Area.Name
Map.MapType = "Cache"
Map.ZoomLevel = 12
Map.ShowTrack = True
Map.MapMovingMode = "Pan"
Map.UseCache = True
Map.CachePath = "C:\Users\Public\Documents\National Instruments\DIAdem\MAP Cache\"
Map.SynchronisationChannelName = "[9]/TripTime"
Map.LongitudeChannelName = "[9]/GPS_Longitude"
Map.LatitudeChannelName = "[9]/GPS_Latitude"
Map.ColorChannelName = "[10]/imGPS_GROUND_SPEED"
Map.SynchronisationDimension = "X-Cursor"
Map.LongitudeDimension = "Y-Cursor"
Map.LatitudeDimension = "Z-Cursor"

Call ScriptStart(ProgramDrv & "Resource\VwLayTrans", "VWTransViewRep", False)

Set Sheet = Report.Sheets(Report.Sheets.Count)
Set Image = Sheet.Objects(AreaName)
Image.UseOriginalRatio = TRUE

The VIEW looks like this:

DIAdem_VIEW_MAP_ScreenShot.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Marek 

0 Kudos
Message 5 of 12
(4,727 Views)

Hi Marek,

 

Can you perhaps post the data file you're trying to reference with this script?  You get a generic map tile like that when you don't have successfully linked coordinates from channels in the Data Portal--- unless your GPS data really is from the area around Aachen, Germany.

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 6 of 12
(4,683 Views)

Hello Brad,

 

I don't think it is because of the data - when I create the route map manually via GUI in VIEW, the map looks like this:

 

DIAdem_VIEW_MAP_ScreenShot2.pngThere must be something in the code I am missing.

I don't feel comfortable about sharing these data here, maybe through an e-mail or something.

 

Marek

0 Kudos
Message 7 of 12
(4,577 Views)

Hi Marek,

 

You can email me directly at brad.turpin@ni.com

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 8 of 12
(4,417 Views)

Hi Marek,

 

Here's the script that works for me with the data set you provided.  The map rendering can either proceed from a fresh download or from a cached set of map tiles.  Unless you know for sure that you've cached the map tiles you need, it's safest to download fresh each time.  Rendering from locally cached tiles performs much faster and can occur without internet access, but the cache path has to be set before you assign Map.MapType = "Cache":

 

OPTION EXPLICIT
Dim Sheet, Area, Map, AreaName, Image

Call View.NewLayout()
Set Sheet = View.ActiveSheet
Set Area = Sheet.ActiveArea
Area.DisplayObjType = "Map"
AreaName = Area.Name
Set Map = Area.DisplayObj

Map.CachePath = ProgramDrv & "Examples\Documents\MapCache"
'Map.MapType = "Cache"
Map.MapType = "OSM Mapnik"
Map.ZoomLevel = 12
Map.ShowTrack = True
Map.MapMovingMode = "Pan"
'Map.UseCache = True
Map.UseCache = False
Map.SynchronisationChannelName = "[1]/TripTime"
Map.LongitudeChannelName = "[1]/GPS_Longitude"
Map.LatitudeChannelName = "[1]/GPS_Latitude"
Map.ColorChannelName = "[1]/imGPS_GROUND_SPEED"
Map.SynchronisationDimension = "X-Cursor"
Map.LongitudeDimension = "Y-Cursor"
Map.LatitudeDimension = "Z-Cursor"

View.Sheets(1).Cursor.P1 = 1
if Map.MapType = "OSM Mapnik" then
  Do While Map.isBusy
    Call Pause(0.1)
  Loop
end if
Call WndShow("VIEW")
Call View.Refresh()

Call ScriptStart(ProgramDrv & "Resource\VwLayTrans", "VWTransViewRep", False)
Set Sheet = Report.Sheets(Report.Sheets.Count)
Set Image = Sheet.Objects(AreaName)
Image.UseOriginalRatio = TRUE

 

This script is also waiting until all the map tiles have been received before requesting the VIEW==>REPORT transfer.  You can thank Walter Rick for providing these details.

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 9 of 12
(4,228 Views)
Solution
Accepted by MarekNebyla

Hello Brad.

Thank you very much for your last update. We made it work with little bit of tweaking. the biggest challenge for us was that the map always appeared on a new report page instead of the one we wanted. We made a little workaround - the map is saved as a picture, then inserted into the page and place we wanted and then the extra page is deleted. A bit cumbersome but it is the best solution we could find and it works.

Another challenge was that the map wasn't centered as we wanted and some parts of the route weren't displayed - they were outside of the picture. We couldn't figure out how to set it automatically so we had to do it manually. But we are fine with that.  

 

Here I add our code for others who might be interested.

 

 

'-------------------------------------------------------------------------------------------------
' Route map added to the report
'-------------------------------------------------------------------------------------------------
'default cache for map data: C:\PROGRAM FILES\NATIONAL INSTRUMENTS\DIADEM 2020\Examples\Documents\MapCache\

Dim Sheet, Area, Map, AreaName, Image
Dim oMyObjects, oMyPosition

Call View.NewLayout()
Set Sheet = View.ActiveSheet
Set Area = Sheet.ActiveArea
Area.DisplayObjType = "Map"
AreaName = Area.Name
Set Map = Area.DisplayObj

Map.CachePath = ProgramDrv & "Examples\Documents\MapCache"
Map.MapType = "OSM Mapnik"
Map.ZoomLevel = 12
Map.ShowTrack = True
Map.MapMovingMode = "center"
Map.UseCache = False
Map.SynchronisationChannelName = "[9]/TripTime"
Map.LongitudeChannelName = "[9]/GPS_Longitude"
Map.LatitudeChannelName = "[9]/GPS_Latitude"
Map.ColorChannelName = "[10]/imGPS_GROUND_SPEED"
Map.SynchronisationDimension = "X-Cursor"
Map.LongitudeDimension = "Y-Cursor"
Map.LatitudeDimension = "Z-Cursor"

View.Sheets(1).Cursor.P1 = 2800
if Map.MapType = "OSM Mapnik" then
Do While Map.isBusy
Call Pause(0.1)
Loop
end if
Call WndShow("VIEW")
Call View.Refresh()

Call ScriptStart(ProgramDrv & "Resource\VwLayTrans", "VWTransViewRep", False)
Set Sheet = Report.Sheets(Report.Sheets.Count)
Set Image = Sheet.Objects(AreaName)
Image.UseOriginalRatio = TRUE

Report.Settings.ImageExport.JPG.Quality = 1
Report.Settings.ImageExport.JPG.Width = 794
Report.Settings.ImageExport.JPG.Progressive = 5
Report.Settings.ImageExport.JPG.UseRatio = True

Call Image.ExportToImage(sPathDocuments & sPathFolder & ".jpg", eImageExportTypeJPG) 'Export the file

Report.Sheets("Map").Objects("Metafile2").FileName = sPathDocuments & sPathFolder & ".jpg"
Call Report.Sheets.Remove("VIEW-REPORT")

 

 

 

0 Kudos
Message 10 of 12
(2,348 Views)