Subscribe to this thread
Home - General / All posts - Some code some may find useful - exporting all layouts, as well as adding elements
djmcbell47 post(s)
#14-Sep-18 06:34

I've just had to export a load of layouts (140+) into pdf. Originally it was export them, fine. I can just right-click and do that.

Then it was add a graticule. Bit of a pain but I can do that without much issue.

Then it was add the company logo. That one is a pain, or at least was at the time, as the map was slow as anything. So I wrote a script, taking liberally from other scripts on here (which I'm now having trouble finding). The only issue is that, at least in Manifold 8, you couldn't alter the x/y coordinates and size of the image (the company logo), so I had to create a separate graphic which was the logo placed in the right place on a transparent surface, which was the same size as the page, to get around Manifold sizing the image to the page. Bit of a pain, especially when some of the layouts are landscape and some portrait.

If anyone finds it useful, feel free to steal it (it's basically what I did).

Sub Main

 Set exporter = Document.NewExport("PDF")

 Set components = Application.ActiveDocument.ComponentSet

 exportPath = "C:\your\destination\path\"

 'allows you to set limits on the amount of files generated - useful for testing

 'CurrentCount - current amount produced, CountMe - limit

 CurrentCount = 0

 CountMe = 9999

 For i = 0 to components.Count-1

 Set theComponent = components(i)

 If theComponent.typeName = "Layout" Then

 if(CurrentCount < CountMe) Then

 'set the graticule - in this case we just wanted coordinates, and no grid

 with theComponent.EntrySet.Item(0)

 .Graticule = LayoutStateOff

 .Border = LayoutBorderCoordinatesGraticule

 .BorderRounding = -2

 end with

 'choose the correct logo image and apply it

 if(theComponent.EntrySet.Item(0).X>theComponent.EntrySet.Item(0).Y) then

 theComponent.EntrySet.AddComponent(components("Logo Landscape bg"))

 end if

 if(theComponent.EntrySet.Item(0).Y>theComponent.EntrySet.Item(0).X) then

 theComponent.EntrySet.AddComponent(components("Logo Portrait bg"))

 end if

 

 'export as pdf

 exporter.Export theComponent, exportPath & theComponent.Name + ".pdf", PromptNone

 'increase our count

 CurrentCount = CurrentCount + 1

 End If

 End If

 Next

 application.messagebox "Complete"

End Sub

adamw


10,447 post(s)
#24-Sep-18 13:27

Nice. :-)

Instead of having the logo be a big image with mostly invisible pixels and just some pixels in the right position, you could have it be a normal logo and resize the layout entry for it that you created with <layout>.EntrySet.AddComponent using LayoutEntry.X / Y / SizeX / SizeY properties.

djmcbell47 post(s)
#25-Sep-18 23:19

That would be much better, thanks. Does that affect position too (would need it to be *near* the top-right)?

adamw


10,447 post(s)
#26-Sep-18 08:04

Well, yes. X / Y control the position, SizeX / SizeY control width and height.

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