[nbos] [FM] Layer control (Part 3 of 3)
Christopher Rodrigues Macias
Tue Mar 20th, 2007
(and here is the final instalment)

Controlling Layering (Z-order) in Complex FM7 Maps (concluded)
by Christopher Rodrigues Macias

[ Continued from the previous email ]

The last piece of the puzzle is a script that, when run, will arrange
the z-order of objects to match the order of the layer they are on.
Here is the script:

' LayerSort by Christopher Rodrigues Macias

' Sets the relative z-ordering of objects on a map according to the
layer each
' object is on. That is, objects on layer 7 will appear 'above'
objects on layer
' 8 (and all higher numbered layers). The script does not affect z-
order *within*
' a given layer. That is, where one object on layer x is shown 'on
top' of
' another object on layer x, this will be maintained after the script
is run.

Sub Main()
Dim oMap ' the current map
Dim o ' a dummy object used to select each layer
Dim i ' index of object o when added to the map
Dim currentLayer ' loop variable representing the number of the
current layer

oMap = GetCurrentMap()

'create a dummy object used to set the current layer
o = CreateMapObject( "Polygon" )

'add the dummy object to the map
i = oMap.AddObject(o)

'loop through the valid layer numbers in reverse order
for currentLayer = 0 to 255 step 1

'deselect all objects on the map
oMap.SelectAll(false)

'initialise the dummy object's layer
o.Layer = currentLayer

'select the dummy object
o.Selected = true

'select all objects on the same layer as the dummy object
oMap.SelectMatching("Layer")

'send the selected objects to the back
'must be done twice, to maintain z-order of objects w/in the layer
oMap.SendSelectedToBack()
oMap.SendSelectedToBack()

next

'finally, remove the dummy object from the map
oMap.SelectAll(false)
o.Selected = true
oMap.DeleteSelected()

End Sub

Copy this into a text document and save it (in text format) as
“LayerSort.vbs”, then place this file in the Scripts subdirectory of
wherever you have installed FM. Selecting Scripts|Run scripts from
file…” from the menu should display the contents of this directory,
and all you have to do is select the file and click “Open” to run it.
Caution: while this script is unlikely to mess up most existing maps,
don’t run it on one that uses several layers unless you are ready to
have everything reordered in this way.

Now, whenever you’ve finished adding a few objects to the map, and
want to see everything layered correctly, you can just hit the F9 key
to quickly pull up the “Run script from file…” dialog and then hit
Enter to run the script.

I should mention that there is (was?) a bug in FM that causes some
problems here. If you select a bunch of objects, then do Edit|Bring
to Front or Edit|Send to Back, then the z-ordering of the entire
group will be inverted. The things at the back will move to the
front, and vice versa. The solution to this is to just run the exact
same command (e.g. Edit|Bring to Front) a second time and this will
put them back in the correct relative order. The script uses this
technique to avoid the bug, which may have been fixed in the current
version.

I make no warranties about the script beyond “it works on my
machine”, but if you find any bugs or would like to suggest any
improvements then please post to this forum to let me know.

HTH

- Christopher
_______________________________________________
Nbossoftware mailing list



Copyright © 2003-2007, NBOS Software. All rights reserved. 'Fractal Mapper', 'ScreenMonkey', 'Character Sketcher', 'Inspiration Pad', 'Fractal World Explorer', 'Goblin API', 'AstroSynthesis' are trademarks of NBOS Software. 'Dwarven Beserker' art by V. Shane.
Member contributed resources