Subscribe to this thread
Home - General / All posts - Automatically run a script
djmcbell24 post(s)
#24-Sep-18 05:41

I've got a .map file which is called by various services. It will start, get fed a number, perform an AOI update, and output a pdf (from a layout) that will be emailed to the sender.

My current problem is that there are two layers that we're interested in, but the map should only display one. They are lines (contours). We should basically say, if Con_A has some records, show Con_B, otherwise show Con_B.

At the moment my default understanding is to always show Con_A. If it has nothing in then that's fine. However, if it does have any records at all (after the AOI update), then Con_B is made invisible.

Would anyone know, for instance, if it's possible to add a script to the layouts so that it makes this judgement when they're loaded, or any other viable alternative? Or to the map the layouts refer to (where the visibility would be set anyway)?

djmcbell24 post(s)
#24-Sep-18 07:28

No worries, I think I've found it.

In my map, I leave Con_A on. I keep Con_B but make it invisible. This way, it still gets updated by the AOI.

I then created a linked drawing using the following query:

SELECT

 [geom (i)]

from [Con_B]

where [Altitude] <

 case when (select count(*) from [Con_A]) = 0 then 9999999

 else -9999999

end

Seems to work - if there is anything in the AOI from Con_A then nothing from Con_B will be displayed. Just doing a bit of tidying up.

vincent

1,733 post(s)
#24-Sep-18 14:27

With a script in the map file, every map layer can be reached programmatically and turned on or off before rendering to PDF. Almost everything in a layout can be reached and modified in fact.

djmcbell24 post(s)
#24-Sep-18 23:13

Oh yeah, scripts are great and I've started using them for a lot of things. But is there a way to automatically trigger a script, rather than having to manually run it? The .map file I inherited had numerous scripts in, but none of them ran automatically - they were just there for setup.

djmcbell24 post(s)
#25-Sep-18 02:19

Well gosh and darn it! The query works a treat, but once I've created a linked drawing, it won't keep it up to date. I'd need to refresh it after the AOI.

I could have sworn it was working (kind-of) yesterday, but the PC I was trying it on was slow as anything. Trying it on mine and, unless the linked drawing is refreshed on the map, nothing will appear on it after the AOI update.

Does anyone know if there's a way for a linked drawing to keep itself up to date on a map (such as, for instance, the tables that generate them changing their results due to an AOI), or a way to automatically refresh a drawing on the map when a layout is opened?

adamw


8,259 post(s)
#25-Sep-18 07:18

There is an option in Tools - Options, Miscellaneous to 'Refresh linked components after opening [MAP] file', and you can refresh any linked component programmatically using Component.Refresh(), but there is no option to refresh linked components when you open a window.

adamw


8,259 post(s)
#25-Sep-18 07:21

Also, regarding automatically running a script - there is a command line option to do so (that is, you can run a command that will both open a specific MAP file and run a script with the name you specify), see this topic in Help: Command-Line Options.

djmcbell24 post(s)
#25-Sep-18 07:40

I suspect that is the one I'll be picking. As I say, the map is automated - it runs from a VS project. A service calls it, it opens up, performs the AOI update and then loads up a layout, exports it and closes.

I have, however, managed to locate the code the previous developer made in the VS project that calls the map. That actually has some options for refreshing queries and drawings, which I should be able to use.

vincent

1,733 post(s)
#25-Sep-18 14:32

If you can reach components, you can trigger a script with its .Run() method isn't ?

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.