Jump to content

Recommended Posts

Posted

Hallo forum,

I would like to have some feedback to my autoit program. It is my first shot, and I wonder if there are better solutions to what I did. So at first the problem set up:

I have a program called yed for drawing graphics. Because I have a lot of these I was looking for a way to automatically export these files to pdf. yed doesn't provide command line functionality. That brought me to autoit.

What I have now is 2 scripts.

One python script which generates a string with all the yed files in a given directory and sub directories and their file sizes.

One autoit script where I copy and paste the results from my python script as (array) variables and which does the magic. Now the script will follow, inside the script I already have some comments and ideas what might be improvable but I will also list the things which bother me most after the code section again:

#comments-start
   Author:  TFTD
   Date:    2014-07-25
   License: Public Domain

   Purpose: This program shall automatically convert graphml-files into pdfs using the program yed
   Remarks: This code is a (not so) minimal working version with no error checks and what so ever
   ToDo:    1. Set the correct working dir while opening yed (at the moment default, last one is used)
               -->yed problem, doesn't see, to work, workaround: use complete directory paths
            2. Is it possible to replace the sleep times with "wait till action is done" constructs?
            2.1 Because some of the times are to short for large graphml FileSaveDialog
                  --> current solution: dynamic wait times according to the file size
            3. The save dialog uses all the defaults, so possibly no pdfs are generated if the last
               export didn't go to PDF
#comments-end

;The string containing the filenames are generated with python, also the FileSize
Local $FileNames[2] = ['.\\FileName1.graphml', '.\\SubDir\\FileName2.graphml']
Local $FileSize[2] = [1648414, 39453]

Local $WorkingDir = "C:\PATH\TO\DIRECTORY\"
Local $FileName     ;tmp variable used for the loop
Local $time

Local $hWnd = Run("C:\Program Files (x86)\yWorks\yEd\yed.exe")  ;yed doesn't seem to care if you try to open it with a given working directory
Local $WindowHandle = WinWaitActive("[CLASS:yEd]","",8)

WinActivate($WindowHandle)      ;this is needed because yed opens in the background

Send("!{F4}")   ;ALT+F4 (Close startup dialog)
Sleep(500)
Send("^{F4}")   ;CTRL+F4 (Close Default Unnamed)
Sleep(500)

For $i=0 to UBound( $FileNames)-1
   $FileName = $FileNames[$i]
   Send("^o")           ;Open File Open Dialog
   Send($WorkingDir)    ;Enter Directory of File
   Send($FileName)      ;Enter Filename
   Sleep(500)           ;is this necessary? Or does the program only keeps going after the send is complete?
   ;ConsoleWrite($FileName)
   ;ConsoleWrite($i)
   Send("{ENTER}")      ;Open that file

   Switch $FileSize[$i] ;Because larger files need more time to be loaded we try to address this problem here.
      Case 0 To 800000
         $time = 500
      Case 800001 To 1600000
         $time = 700
      Case 1600001 To 2400000
         $time = 1000
      Case Else
         $time = 1400
   EndSwitch

   Sleep($time)
   Send("^e")           ;Open Export Dialog and assume the correct stuff (pdf) is chosen
   Sleep(500)
   Send("{ENTER}")      ;Confirm default settings
   Sleep(500)
   Send("{ENTER}")      ;Save file, larger files need more time
   Sleep($time)
   Send("^{F4}")        ;Close file
Next

Send("!{F4}")   ;ALT+F4 (Close Program)
  1.  Is there a simple way to generate the FileName and FileSize with autoit? (Since I know python better than autoit I can easily write the results into the autoit script file.
  2. Is there a better solution for all the "Sleep" commands I'm using? Especially with respect to different loading times for different file sizes?
    Are all my Sleep commands necessary?
  3. At different points I'm assuming that the defaults are correctly chosen. For example that the pdf type is selected in the export dialog.
    I have no idea how to manually select pdf in the export dialog automatically. It is the typical windows dialog for saving/exporting and the filetype is a dropdown menu. I can open the drow down menu but haven't found a way to address the correct selection with keyboard strokes.

I would appreciate any hints, suggestions or pointing to examples which can help me.
As a side node, my brain refuses to understand object orientated code, so I'm trying to avoid it. :)
Thanks for your time and help.

Posted (edited)

1 yes, have fun with _FileListToArrayRec and FileSize

 

The yEd Software License Agreement explicitly forbids to use yEd as part of an automated process, such as a script or a tool pipeline that automatically transforms an input to an output that was generated by yEd.

If you wish to use the layouts or tools provided by yEd in an automated process or through an API, you should have a look at yFiles, a commercially available graph visualization toolkit that forms the basis of all functionality found in yEd.

http://yed.yworks.com/support/qa/6/can-i-invoke-yed-layouts-from-the-command-line

I suggest you tu use an other tool like GIMP

3 just for information, you have to work with Autoit Window Info to know infos about controls

Edited by j0kky
Posted

Thanks for your fast reply.

1 and 3 I will take a look.

2 was about the Sleep function but your link is interesting. But I couldn't find it in the Software License Agreement. I only found "The Software may not be used as part of an automated process." which basically forbids the use of the software. Since people tend to write all kind of stupid, invalid or senseless things in EULAs, claiming rights they just don't have (or worse taking away rights from the user) and which don't survive a minute in a court room, this is just one of the millions invalid clauses out there.

And btw. Inkscape would be the more suitable alternative, unfortunately it is not my call.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...