Subscribe to this thread
Home - General / All posts - User Interface scripting - FileExportImage
firsttube


1,437 post(s)
#19-Sep-18 16:09

I'm trying to script the export of images to PNG image format using UI scripting in M8. I can invoke the command FileExportImage but I can't seem to access the controls to set the file name and type. Can this be done"

'vbscript

Sub Main

 set comps = document.componentset

 set img = comps("Image")

 img.open

 set ui = Application.UserInterface

 ui.InvokeCommand "FileExportImage"

 WaitForDialog "Export Image", ui

 set dlg = ui.ModalDialog

 'errors out on the line below

 dlg.ControlSet.Item("FileName").Text = "Image"

End Sub

Sub WaitForDialog(dlgName, ui)

'wait

 Do:x=x+1: Application.History.Log x & vbnewline

       Loop Until UI.ModalDialog.Caption = dlgName

End sub


"The blessing in life is finding the torture you are comfortable with." - Jerry Seinfeld, 6/26/2013

Sloots

430 post(s)
#19-Sep-18 16:47

I would recommend not to use ui scripting for this. Much easier. There is a plugin that exports all images to a specific directory. That might help you to develop your own script.


http://www.mppng.nl/manifold/pointlabeler

Sloots

430 post(s)
#19-Sep-18 17:18

Here is some useful code:

// C# Code

using Manifold.Interop.Scripts;

using M = Manifold.Interop;

using System.Windows.Forms;

class Script {

 static void Main() {

 M.Application app = Context.Application;

 M.Document doc = (M.Document) app.ActiveDocument;

 M.ExportPng exporter = (M.ExportPng) app.NewExport("png");

 M.ComponentSet comps = doc.ComponentSet;

 FolderBrowserDialog dlg = new FolderBrowserDialog();

 if (dlg.ShowDialog() == DialogResult.OK)

 {

 int counter = 0;

 foreach (M.Component comp in comps)

 {

 if (comp.Type == M.ComponentType.ComponentImage)

 {

 M.Image img = (M.Image) comp;

 if (!img.IsLinked())

 {

 exporter.Export(comp, dlg.SelectedPath + "\\" + comp.Name + ".png", M.ConvertPrompt.PromptNone);

 counter++;

 }

 }

 }

 Context.Application.MessageBox(string.Format("Exported {0} images to {1}.", counter, dlg.SelectedPath), "Script");

 }

 }

}


http://www.mppng.nl/manifold/pointlabeler

firsttube


1,437 post(s)
#19-Sep-18 17:33

Yes, I decided to go that route. Thanks!


"The blessing in life is finding the torture you are comfortable with." - Jerry Seinfeld, 6/26/2013

firsttube


1,437 post(s)
#19-Sep-18 18:21

Actually my original task was to programmatically export all layouts in a M8 project as PNG. Here is the script that did the job. You'd have to add a loop to iterate through all layout components.

'vbscript

Sub Main

 set comps = document.componentset

 set lyt = comps("Layout")

 'make an image component from a layout

 lyt.open

 set ui = Application.UserInterface

 ui.InvokeCommand "ToolsMakeImage"

 WaitForDialog "Make Image", ui

 set dlg = ui.ModalDialog

 dlg.ControlSet.Item("TextBoxName").Text = lyt.Name & " Image"

 dlg.ControlSet.Item("TextBoxResolution").Text = "300"

 dlg.ControlSet.Item("ButtonOK").Push

 application.activewindow.close

 'export the image component as a png file

 set img = comps(lyt.name & " Image")

 set pngexp = application.newexport("PNG")

 pngexp.Interlaced = False

 pngexp.Export img, "C:\Users\username\Documents\" & lyt.Name & " Image.png", PromptNone

End Sub

Sub WaitForDialog(dlgName, ui)

'wait

 Do:x=x+1: Application.History.Log x & vbnewline

       Loop Until UI.ModalDialog.Caption = dlgName

End sub


"The blessing in life is finding the torture you are comfortable with." - Jerry Seinfeld, 6/26/2013

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