[mapguide-users] IronPython - automate Maestro

Jackie Ng jumpinjackie at gmail.com
Tue Jul 23 02:24:55 PDT 2024


Hi Bart,

Here's an example

# Get connection (assuming single active connection in Site Explorer)
conn = app.GetConnection(app.GetConnectionNames()[0])
# Get Layer
layer =
conn.ResourceService.GetResource("Library://Samples/Sheboygan/Layers/Trees.LayerDefinition")
# Get the first scale range
vectorScaleRange = layer.SubLayer.GetScaleRangeAt(0)
# The layer definition is also a factory for sub-elements you can add. In
this case a new point rule
pointRule = layer.CreateDefaultPointRule()
# Set various properties of this new rule
pointRule.LegendLabel = "New Point Rule"
#pointRule.Filter = "<my FDO filter expression>"
# Add the new rule
vectorScaleRange.PointStyle.AddRule(pointRule)
# Save the layer
conn.ResourceService.SaveResource(layer)


Some general tips to help writing scripts:

1. The IronPython console is a REPL, so don't be afraid of writing
exploratory code fragments to inspect various variables and objects. You
don't have to get the script code correct the first time round.
Unfortunately, as I myself just discovered, there's an annoying bug where
you can't copy the current console contents to the clipboard (to paste into
a reusable script) so building reusable scripts is a bit of a pain atm.
This is a known issue that I'll look at a later time:
https://github.com/jumpinjackie/mapguide-maestro/issues/152

2. This decade-old blog post of mine has some useful tips around the
IronPython console:
https://themapguyde.blogspot.com/2013/08/maestro-ironpython-console-tips-and.html

3. The objects you are interacting with are part of the Maestro .net API
exposed to the IronPython engine, so it's useful to always have the .net
API reference on hand when you want to know what a particular class or
interface is: https://jumpinjackie.github.io/mapguide-maestro/api/

Hope this helps!

- Jackie

You wrote:

Hello,

Maybe I am posting in the incorrect forum, still I hope someone can help me.

I have been studying the (Iron)Python code examples that show how to
alter existing items in Maestro.

However, I would like to ‘add’  for instance new filters like point filters etc.

After a few days trying I ran into something called ‘iPoint’.

I have low-level programming skills.

Could someone please provide an example of how to ADD a NEW filter ?

Kine regards,

Bart Oostdam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20240723/ae4accc8/attachment.htm>


More information about the mapguide-users mailing list