[mapguide-users] IronPython - automate Maestro
Bart Oostdam
bart at giskit.nl
Wed Jul 24 02:32:34 PDT 2024
Hello Jackie,
I ran into a problem trying your code.
This Line does not seem to work:
vectorScaleRange.PointStyle.AddRule(pointRule)
Error when running the code:
[cid:image001.png at 01DADDBD.2CF4D050]
I ran a dir() on the vectorScaleRange variable and it shows no AddRule.
I will take a better look at the API documentation
[cid:image002.png at 01DADDBD.2CF4D050]
Met vriendelijke groet,
GISkit BV
Bart Oostdam
Van: mapguide-users <mapguide-users-bounces at lists.osgeo.org> Namens Jackie Ng via mapguide-users
Verzonden: dinsdag 23 juli 2024 11:25
Aan: MapGuide Users Mail List <mapguide-users at lists.osgeo.org>
CC: Jackie Ng <jumpinjackie at gmail.com>
Onderwerp: Re: [mapguide-users] IronPython - automate Maestro
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/20240724/222a842e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 9598 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20240724/222a842e/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 14651 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20240724/222a842e/attachment-0001.png>
More information about the mapguide-users
mailing list