elecman
Topic Author
Posts: 90
Joined: 20 Jul 2014, 04:28

XAML save automation for InkScape

13 Feb 2015, 13:00

I made a script for Inkscape which automates the "Save a Copy" as an xaml. This greatly speeds up the workflow.

Usage:
-Install AutoIt here:
https://www.autoitscript.com/site/autoit/downloads/

-Create a text file, copy this code, and call the file something.au3
;Set an option so that we can always find the window, regardless of the file name in use.
AutoItSetOption ("WinTitleMatchMode", 2)

;Get a handle to the main window.
Local $hWndMain = WinGetHandle(" - Inkscape", "");

;If we can't find the main window, bail out.
If @error Then
	Exit
	
;The main window is found, continue
Else
	;Focus the main window in case it isn't.
	WinActivate($hWndMain)
	
	;"Save a Copy" keyboard shortcut.
	Send("{SHIFTDOWN}{CTRLDOWN}{ALTDOWN}s")
	Send("{SHIFTUP}{CTRLUP}{ALTUP}")
	
	;Wait for the save window to show up.
	Local $hWndSave = WinWait("[CLASS:#32770]")
	
	;Focus the save window in case it isn't.
	WinActivate($hWndSave)
	
	;Click on the "Save as Type" selection box.
	ControlClick($hWndSave, "","[CLASS:ComboBox; INSTANCE:3]")
	
	;Select the xaml option in the selection box, and press Enter.
	ControlCommand($hWndSave, "", "[CLASS:ComboBox; INSTANCE:3]", "SelectString", "Microsoft XAML (*.xaml)")
	Send("{ENTER}")
	
	;Shortcut key for "Save".
	Send("{ALTDOWN}s")
	Send("{ALTUP}")
	
	;A popup box will appear which asks if you want the output to be compatible with Silverlight. 
	;You have to tick the box manually once, without using this script. After that, the setting is remembered.
	Local $hWndSilverlight = WinWait("XAML Output", "")
	WinActivate($hWndSilverlight)
	
	;Shortcut key for "OK" on the Silverlight message box.
	Send("{ALTDOWN}o")
	Send("{ALTUP}")
	
	;If the file already exists, overwrite the it by pressing Enter.
	Local $hWndOverwrite = WinGetHandle("");
	If @error Then
		Exit
	Else
		WinActivate($hWndOverwrite)
		Send("{ENTER}")
	EndIf
EndIf
-Save the xaml once and make sure the Silverlight option is checked, I can't set that in the script. Once it is set it is remembered.
-Make sure InkScape is open (no need to focus the window), and double click on the file.
-Do not move the mouse or click a button while the script is running.

Of course it would be better to use a native Inkscape script, but I haven't got the time to figure out how to do that, if it is possible at all.
 
User avatar
jsantos
Site Admin
Posts: 2903
Joined: 20 Jan 2012, 17:18
Contact:

Re: XAML save automation for InkScape

15 Feb 2015, 00:02

wow! Thanks for this contribution!

Who is online

Users browsing this forum: No registered users and 2 guests