Sign in to follow this  
Followers 0
james3mg

Word 2007 documents written with AutoIt

8 posts in this topic

#1 ·  Posted (edited)

Hello all,

It's unfortunately unlikely that anyone else will be able to use this script, but here's (a sterilized version-no company info) a script I recently completed to allow our employees to create Word Photo Logs quickly and easily for documenting our projects. I just submit it here so everyone can see how to create the new .docx file format in Word 2007 (open-able with the MS plugin for Office 2000+, I believe). Anyone should be able to run this and see its results, just drag a directory with pictures directly inside (not in sub-directories) onto the .exe or simply launch the program and browse to such a folder. It will allow you to select pictures in bulk by the date they were taken as well as individually, then rearrange the order they're in, before compiling them into a word document. (Rearranging pictures in large lists is a pain-I don't recommend it in this program).

Attached are all the files you need for this script - _ZipFunctions.au3 and docx.zip are required for PhotoLogMaker2.au3 to be run/compiled. PhotoLogMaker2.exe is a compiled self-contained program - no additional files required, and is included for your convenience, should you want it.

One problem I had to solve in this script that I want to get out there in the public mind - I used Simucal's _GetExtProperty() function in this script, and found that Vista has changed which elements of the array are used to store the data. For instance, under XP element 26 is dimensions and 25 is date picture taken, but under Vista, the same data can be found in 31 and 12, respectively, and has to have question marks removed with StringReplace().

The biggest challenge with this script was obviously to create a word .docx document from scratch that I could pull apart and manipulate as required - it took a while since there's no good support for the Word-specific xml tags. Once I got everything working, I stripped all the sidR tags out of all the documents so that Word will create its own unique tags the first time the document is saved. I seem to have gotten it down to a managable base package, and you should be able to read the script to find the lines it adds and files it writes from scratch to figure out how to modify the look of the template to your liking.

I've also noticed that the pictures never show up the first time the document is launched, you have to launch it manually to see the images. I don't know why, and other than the lack of error-checking and comments throughout the script, this is the only outstanding issue I have with this script, and it's unlikely to get resolved.

Have fun! (The core script is also included below). BTW, thanks also to everyone who contributed to the _ZipFunctions.au3 UDF I got from elsewhere on the forum). This isn't my most complex script by far, but it's sure the first one I feel this good about leaving in its final state-I don't think I have anything in mind for future improvements. That being said, I'm sure there's a lot of mud that's able to be slung at it from far better programmers than I :whistle:

EDIT: Please see post#7 in this topic for the latest code and downloads, as well as an explanation of what/why it changed.

;(Code Deleted)
Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Thanks for the encouragement, ptrex!

I know, a UDF would be ideal, but I can't figure out how to do it. It would be awfully clunky to have a script with functions like

_docxDocumentStart($file)
_docxSectionstart($file)
_docxTableStart($file,$width,$height)
_docxTableRowStart($file,$height)
_docxTableCellStart($file,$width)
_docxTextNewlineStart($file)
_docxText($text,[$style])
_docxTextLineEnd($file)
_docxTableCellEnd($file)
_docxTableRowEnd($file)
_docxTableEnd($file)
_docxSectionConfig($file,[$leftmargin,[$rightmargin,[$topmargin,[$bottommargin,[$headersize,[$footersize,[$numCols]]]]]]])
_docxSectionend($file)
_docxDocumentEnd($file)
just to write a document with a single line of text into a single-cell table :whistle: (yes, all these elements would be required, maybe a few more config-this-element type functions that I forgot). And that's without inserting pictures, which will require some kind of graphic-editing tool to resize the picture as required and stick it in the media subfolder of the document, then writing the reference into the appropriate .refs file (depending on if you inserted it into the header, body or footer, etc).

The work of writing the functions doesn't scare me, but I don't think the typical AutoIt scripter is used to having to have a function to close a function later in the script that HAS to be called in the correct order (to write the closing xml tags in the correct order), so I don't like that solution. I think it would lead to too many "This UDF doesn't work"-type forum topics by people who forgot to close an earlier function in the right order.

The only other way I can think of that it could be done would be to have a single function to parse an HTML file (<tr> gets translated with the code for _docxTableRowStart(), etc) but there's so many parameters in HTML tags that I don't know the word equivalent for, (and I'm pretty bad at writing code to parse other scripts like HTML...I've tried before) that I don't think I've got the skills.

If anyone else wants to get started, I can supply chunks of Word xml code that would fit functions similar to those above that they can do anything they want with...but I don't think I'm up to the task. I was hoping that just showing it's possible now under the Word 2007 format would encourage someone looking for that type of function and give them a place to start in creating their own docx-writing scripts. :P

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Seems very tempting to build that in a kind of UDF using the _XMLDomWrapper.au3

Nice, never heard of _XMLDomWrapper.au3 . Maybe I'll search for it and see what I can use from it too. Probably would have saved me some time writing this script! :whistle::P Oh well.

Interested to see what you come up with for docx UDF! I'd love to have something that worked well for other applications, but for now...building from scratch!

Thanks


"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

In a reply to an old question that I'd posted at microsoft's newsgroups, another user told me they were having problems with linking in pictures with spaces in the filenames. In testing, I found that my script also suffered from this problem. After much dialog back and forth, we arrived at a new way of linking the pictures in, which required a bit of tweaking on my code.

Fortunately, a side effect of the new method is that the problem with the pictures not always resolving, pictures being artificially lightened on the screen, and a few other minor annoyances disappeared.

So here is my new code and everything needed to compile it, along with a pre-compiled .exe file, same as before. I'm going to take the old download links down(on the first message) now.

Outstanding issues? I've confirmed that Word can resolve pictures in sub-folders with no modifications, so I'd like to include all pictures in all subfolders of the initially selected folder, rather than just pictures in the immediate folder. Worst case, I'll run a command-line dir *.jpg /S>list.txt and parse that to get the list, but I'd like to find a nicer way to get all the files and subfolders/files into the array. I'm not aware of any other issues for now however, so have fun!

#NoTrayIcon
#include <GUIConstants.au3>
#include <File.au3>
#include <GUITreeView.au3>
#include <_ZipFunctions.au3>
;Opt("TrayIconDebug",1)
Opt("GUIOnEventMode",1)

Global $IncludedPicsListString=""

$GetListGUI=GUICreate("Choose photos to include",640,480)
GUISetOnEvent($GUI_EVENT_CLOSE,"Exiter")
$DateListTreeview=GUICtrlCreateTreeView(10,20,310,390,$TVS_HASBUTTONS+$TVS_HASLINES+$TVS_LINESATROOT+$TVS_DISABLEDRAGDROP+$TVS_CHECKBOXES)

Global $TreeViewItems[1][3]=[[0]];[ctrl id][text][selected]
Global $PhotoFolder=""
If $CmdLine[0]>0 Then
    $PhotoFolder=$CmdLine[1]
    For $i=2 To $CmdLine[0]
        $PhotoFolder&=$CmdLine[$i]
    Next
EndIf
If NOT FileExists($PhotoFolder) Then
    $PhotoFolder=FileSelectFolder("Please select the folder containing the photos","C:\",6)
    If @error Then Exit
EndIf
SplashTextOn("Please wait","Please wait while the window is opened",320,240)

$TreeViewRoot=GUICtrlCreateTreeViewItem($PhotoFolder,$DateListTreeview)
GUICtrlSetOnEvent(-1,"EventHandler")
Global $TreeViewRootChecked=0
$TreeViewLabel=GUICtrlCreateLabel("Finding Files...",10,410,620,20)
$Thumbnail=GUICtrlCreatePic("",330,20,200,200,$BS_BITMAP)
$IncludedPicsList=GUICtrlCreateList("",330,223,200,190,$WS_BORDER+$WS_VSCROLL)
GUICtrlSetOnEvent(-1,"EventHandler")
$MoveUpButton=GUICtrlCreateButton("Move Up",530,240,100,20)
GUICtrlSetOnEvent(-1,"EventHandler")
$MoveDownButton=GUICtrlCreateButton("Move Down",530,378,100,20)
GUICtrlSetOnEvent(-1,"EventHandler")
GUICtrlCreateLabel("Date on Photo Log:",10,435)
$DateInput=GUICtrlCreateInput("",10,450,150,20)
GUICtrlCreateLabel("Project:",175,435)
$ProjectInput=GUICtrlCreateInput("",175,450,150,20)
GUICtrlCreateLabel("Observations by:",340,435)
$ObservationsInput=GUICtrlCreateInput("",340,450,150,20)
$GoButton=GUICtrlCreateButton("Build Photo Log",530,450,100,20)
GUICtrlSetOnEvent(-1,"EventHandler")
GUISetState(@SW_SHOW,$GetListGUI)
SplashOff()

$FileListArray=_FileListToArray($PhotoFolder,"*.jpg",1)
If @error Then
    GUISetState(@SW_HIDE)
    MsgBox(16,"Error","Sorry, no valid pictures were found")
    Exit
EndIf

GUICtrlSetData($TreeViewLabel,"Please Wait...")

Global $FileArray[UBound($FileListArray)][2];[filename][date]
$FileArray[0][0]=$FileListArray[0]
For $i=1 To $FileListArray[0]
    dim $ThisProp=""
    $FileArray[$i][0]=$FileListArray[$i]
    If @OSVersion="WIN_95" OR @OSVersion="WIN_98" OR @OSVersion="WIN_ME" OR @OSVersion="WIN_NT4" OR @OSVersion="WIN_2000" OR @OSVersion="WIN_XP" OR @OSVersion="WIN_2003" Then
        $ThisProp=StringSplit(StringReplace(_GetExtProperty($PhotoFolder & "\" & $FileArray[$i][0],25),"?","")," ")
    Else
        $ThisProp=StringSplit(StringReplace(_GetExtProperty($PhotoFolder & "\" & $FileArray[$i][0],12),"?","")," ")
    EndIf
    $FileArray[$i][1]=$ThisProp[1]
    
    $found=0
    For $n=1 To $TreeViewItems[0][0]
        If $FileArray[$i][1]=$TreeViewItems[$n][1] Then
            $found=1
            ReDim $TreeViewItems[$TreeViewItems[0][0]+2][3]
            $TreeViewItems[0][0]+=1
            $TreeViewItems[$TreeViewItems[0][0]][0]=GUICtrlCreateTreeViewItem($FileArray[$i][0],$TreeViewItems[$n][0])
            GUICtrlSetOnEvent(-1,"EventHandler")
            $TreeViewItems[$TreeViewItems[0][0]][1]=$FileArray[$i][0]
            $TreeViewItems[$TreeViewItems[0][0]][2]=0
            ExitLoop
        EndIf
    Next
    If $found=0 Then
        ReDim $TreeViewItems[$TreeViewItems[0][0]+2][3]
        $TreeViewItems[0][0]+=1
        $TreeViewItems[$TreeViewItems[0][0]][0]=GUICtrlCreateTreeViewItem($FileArray[$i][1],$TreeViewRoot)
        GUICtrlSetOnEvent(-1,"EventHandler")
        $TreeViewItems[$TreeViewItems[0][0]][1]=$FileArray[$i][1]
        $TreeViewItems[$TreeViewItems[0][0]][2]=0
        GUICtrlSetState($TreeViewRoot,$GUI_EXPAND)
        
        ReDim $TreeViewItems[$TreeViewItems[0][0]+2][3]
        $TreeViewItems[0][0]+=1
        $TreeViewItems[$TreeViewItems[0][0]][0]=GUICtrlCreateTreeViewItem($FileArray[$i][0],$TreeViewItems[$n][0])
        GUICtrlSetOnEvent(-1,"EventHandler")
        $TreeViewItems[$TreeViewItems[0][0]][1]=$FileArray[$i][0]
        $TreeViewItems[$TreeViewItems[0][0]][2]=0
    EndIf
Next

GUICtrlSetData($TreeViewLabel,"")
Global $Rearranged=0

Func EventHandler()
    $callingID=@GUI_CtrlId
    Switch $callingID
        Case $MoveUpButton
            If $Rearranged=1 OR MsgBox(36,"Are you sure?","If you rearrange the list, then check or uncheck some boxes, your changes will be lost.  Are you sure you're done selecting pictures?")=6 Then
                $Rearranged=1
                $IncludedPicsListArray=StringSplit($IncludedPicsListString,"|")
                If NOT @error AND $IncludedPicsListArray[1] <> GUICtrlRead($IncludedPicsList) Then
                    $reselectItem=GUICtrlRead($IncludedPicsList)
                    For $i=1 To $IncludedPicsListArray[0]
                        If $IncludedPicsListArray[$i]=GUICtrlRead($IncludedPicsList) Then ExitLoop
                    Next
                    $IncludedPicsListArray[$i]=$IncludedPicsListArray[$i-1]
                    $IncludedPicsListArray[$i-1]=GUICtrlRead($IncludedPicsList)
                    $IncludedPicsListString=""
                    For $i=1 To $IncludedPicsListArray[0]
                        If $IncludedPicsListArray[$i] <> "" Then $IncludedPicsListString&=$IncludedPicsListArray[$i]&"|"
                    Next
                    GUICtrlSetData($IncludedPicsList,"")
                    GUICtrlSetData($IncludedPicsList,$IncludedPicsListString,$reselectItem)
                EndIf
            EndIf
        Case $MoveDownButton
            If $Rearranged=1 OR MsgBox(36,"Are you sure?","If you rearrange the list, then check or uncheck some boxes, your changes will be lost.  Are you sure you're done selecting pictures?")=6 Then
                $Rearranged=1
                $IncludedPicsListArray=StringSplit($IncludedPicsListString,"|")
                If NOT @error AND $IncludedPicsListArray[$IncludedPicsListArray[0]] <> GUICtrlRead($IncludedPicsList) Then
                    $reselectItem=GUICtrlRead($IncludedPicsList)
                    For $i=1 To $IncludedPicsListArray[0]
                        If $IncludedPicsListArray[$i]=GUICtrlRead($IncludedPicsList) Then ExitLoop
                    Next
                    $IncludedPicsListArray[$i]=$IncludedPicsListArray[$i+1]
                    $IncludedPicsListArray[$i+1]=GUICtrlRead($IncludedPicsList)
                    $IncludedPicsListString=""
                    For $i=1 To $IncludedPicsListArray[0]
                        If $IncludedPicsListArray[$i] <> "" Then $IncludedPicsListString&=$IncludedPicsListArray[$i]&"|"
                    Next
                    GUICtrlSetData($IncludedPicsList,"")
                    GUICtrlSetData($IncludedPicsList,$IncludedPicsListString,$reselectItem)
                EndIf
            EndIf
        Case $TreeViewRoot
            If $TreeViewRootChecked=0 AND BitAnd(GUICtrlRead($TreeViewRoot),$GUI_CHECKED) Then
                $TreeViewRootChecked=1
                For $i=1 To $TreeViewItems[0][0]
                    GUICtrlSetState($TreeViewItems[$i][0],$GUI_CHECKED)
                    $TreeViewItems[$i][2]=1
                Next
                RebuildList()
            ElseIf $TreeViewRootChecked=1 AND BitAnd(GUICtrlRead($TreeViewRoot),$GUI_UNCHECKED) Then
                $TreeViewRootChecked=0
                For $i=1 To $TreeViewItems[0][0]
                    GUICtrlSetState($TreeViewItems[$i][0],$GUI_UNCHECKED)
                    $TreeViewItems[$i][2]=0
                Next
                RebuildList()
            EndIf
        Case $IncludedPicsList
            GUICtrlSetImage($Thumbnail,$PhotoFolder & "\" & GUICtrlRead($IncludedPicsList))
        Case $GoButton
            GUICtrlSetState($GoButton,$GUI_DISABLE)
            GUICtrlSetData($GoButton,"Working...")
            ;;build the glorious word document!
            $IncludedPicsListArray=StringSplit($IncludedPicsListString,"|")
            GUICtrlSetData($TreeViewLabel,"Deleting old files")
            For $i=1 To 100
                DirRemove(@TempDir & "\PhotoLogBuilder",1)
                If NOT FileExists(@TempDir & "\PhotoLogBuilder") Then ExitLoop
                sleep(100)
            Next
            If FileExists(@TempDir & "\PhotoLogBuilder") Then
                run(@comspec & ' /c start "" "%tmp%"',"",@SW_HIDE)
                MsgBox(16,"Error","The program can't delete the PhotoLogBuilder in your temp file.  Please delete it manually or else Word will prompt you to recover the document once the file is built.  Click OK when you're ready to continue.")
            EndIf
            DirCreate(@TempDir & "\PhotoLogBuilder")
            $root=@TempDir & "\PhotoLogBuilder\Docx"
            
            GUICtrlSetData($TreeViewLabel,"Unzipping files")
            FileInstall("docx.zip",@TempDir & "\PhotoLogBuilder\Docx.zip")
            _Unzip(@TempDir & "\PhotoLogBuilder\Docx.zip",$root)
            GUICtrlSetData($TreeViewLabel,"Writing table of contents")
            FileWriteLine($root & '\word\_rels\document.xml.rels','<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> ')
            FileWriteLine($root & '\word\_rels\document.xml.rels','<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">')
            FileWriteLine($root & '\word\_rels\document.xml.rels','  <Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" Target="footer1.xml" />')
            FileWriteLine($root & '\word\_rels\document.xml.rels','  <Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header1.xml" />')
            For $i=1 To $IncludedPicsListArray[0]
                If $IncludedPicsListArray[$i]<>"" Then
                    FileWriteLine($root & '\word\_rels\document.xml.rels','  <Relationship Id="MGId'&$i&'" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target=".\'&StringReplace($IncludedPicsListArray[$i],' ','%20')&'" TargetMode="External" />')
                EndIf
            Next
            FileWriteLine($root & '\word\_rels\document.xml.rels','</Relationships>')
            
            GUICtrlSetData($TreeViewLabel,"Writing header")
            _FileWriteToLine($root & "\word\header1.xml",489,StringReplace(FileReadLine($root & "\word\header1.xml",489),"xx\xx\xxxx",GUICtrlRead($DateInput)),1)
            _FileWriteToLine($root & "\word\header1.xml",558,StringReplace(FileReadLine($root & "\word\header1.xml",558),"___________________",GUICtrlRead($ProjectInput)),1)
            _FileWriteToLine($root & "\word\header1.xml",603,StringReplace(FileReadLine($root & "\word\header1.xml",603),"___________________",GUICtrlRead($ObservationsInput)),1)
            
            GUICtrlSetData($TreeViewLabel,"Writing metadata")
            $tmpFilecontents=FileRead($root & "\docProps\core.xml")
            $TmpFile=FileOpen($root & "\docProps\core.xml",2)
            $tmpFilecontents=StringReplace($tmpFilecontents,"{date}",GUICtrlRead($DateInput))
            $tmpFilecontents=StringReplace($tmpFilecontents,"{job}",GUICtrlRead($ProjectInput))
            $tmpFilecontents=StringReplace($tmpFilecontents,"{username}",@UserName)
            FileWrite($TmpFile,$tmpFilecontents)
            FileClose($TmpFile)
            
            GUICtrlSetData($TreeViewLabel,"Writing document")
            $documentfile=FileOpen($root & '\word\document.xml',2)
            FileWriteLine($documentfile,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>')
            FileWriteLine($documentfile,'<w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:o12="http://schemas.microsoft.com/office/2004/7/core" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">')
            FileWriteLine($documentfile,'  <w:body>')
            FileWriteLine($documentfile,'  <!--Image divider mark for future use-->')
            $PicPartFile=FileOpen($root & '\word\PicPart.xml',0)
            For $i=1 To $IncludedPicsListArray[0]
                If $IncludedPicsListArray[$i]<>"" Then
                    $PicPart=FileRead($PicPartFile)
                    GUICtrlSetData($TreeViewLabel,"Writing picture "&$i)
                    If @OSVersion="WIN_95" OR @OSVersion="WIN_98" OR @OSVersion="WIN_ME" OR @OSVersion="WIN_NT4" OR @OSVersion="WIN_2000" OR @OSVersion="WIN_XP" OR @OSVersion="WIN_2003" Then
                        $SizeProp=StringSplit(StringReplace(_GetExtProperty($PhotoFolder & "\" & $FileArray[$i][0],26),"?","")," x ",1)
                    Else
                        $SizeProp=StringSplit(StringReplace(_GetExtProperty($PhotoFolder & "\" & $FileArray[$i][0],31),"?","")," x ",1)
                    EndIf
                    If Number($SizeProp[2]) < Number($SizeProp[1]) Then $PicPart=StringReplace($PicPart,'<v:group style="width:162pt;height:216pt;','<v:group style="width:216pt;height:162pt;')
                    $PicPart=StringReplace($PicPart,'<v:imagedata r:id="MGId1" /> ','<v:imagedata r:id="MGId'&$i&'" /> ')
                    $PicPart=StringReplace($PicPart,'<w:t>1)</w:t>','<w:t>'&$i&')</w:t>')
                    $PicPart=$PicPart&@CRLF
                    FileWrite($documentfile,$PicPart)
                EndIf
            Next
            FileClose($PicPartFile)
            GUICtrlSetData($TreeViewLabel,"Writing end of document")
            FileWriteLine($documentfile,'    <w:sectPr>')
            FileWriteLine($documentfile,'      <w:headerReference w:type="default" r:id="rId6"/>')
            FileWriteLine($documentfile,'      <w:footerReference w:type="default" r:id="rId7"/>')
            FileWriteLine($documentfile,'      <w:pgMar w:top="1440" w:right="1080" w:bottom="720" w:left="1080" w:header="720" w:footer="720" w:gutter="0"/>')
            FileWriteLine($documentfile,'      <w:cols w:num="2" w:space="720"/>')
            FileWriteLine($documentfile,'    </w:sectPr>')
            FileWriteLine($documentfile,'  </w:body>')
            FileWriteLine($documentfile,'</w:document>')
            FileClose($documentfile)
            FileDelete($root & "\word\PicPart.xml")
            
            GUICtrlSetData($TreeViewLabel,"Compiling document")
            _ZipAdd(@TempDir & "\PhotoLogBuilder\PhotoLogZip.zip",$root)
            GUICtrlSetData($TreeViewLabel,"Moving document to "&$PhotoFolder & "\Photo Log "& StringReplace(GUICtrlRead($DateInput),"/","-") & ".docx")
            FileMove(@TempDir & "\PhotoLogBuilder\PhotoLogZip.zip",$PhotoFolder & "\Photo Log "& StringReplace(GUICtrlRead($DateInput),"/","-") & ".docx",1)
            GUICtrlSetData($TreeViewLabel,"Done!  Please wait while the document is launched.")
            RunWait(@ComSpec & ' /c start "" "'&$PhotoFolder & '\Photo Log '& StringReplace(GUICtrlRead($DateInput),"/","-") & '.docx"',"",@SW_HIDE)
            Exit
            
            ;;/build the glorious word document!
        Case Else
            For $i=1 To $TreeViewItems[0][0]
                If $TreeViewItems[$i][0]=$callingID Then
                    If StringInStr($TreeViewItems[$i][1],"/") OR $TreeViewItems[$i][1] = "0" Then;it's a date folder
                        If GUICtrlRead($DateInput)="" AND BitAND(GUICtrlRead($TreeViewItems[$i][0]),$GUI_CHECKED) Then GUICtrlSetData($DateInput,$TreeViewItems[$i][1])
                        If $TreeViewItems[$i][2]=1 AND BitAnd(GUICtrlRead($callingID),$GUI_UNCHECKED) Then
                            For $n=1 To $TreeViewItems[0][0]
                                If _GUICtrlTreeViewGetParentID($DateListTreeview,$TreeViewItems[$n][0]) = $callingID Then
                                    $TreeViewItems[$n][2]=0
                                    GUICtrlSetState($TreeViewItems[$n][0],$GUI_UNCHECKED)
                                EndIf
                            Next
                            $TreeViewItems[$i][2]=0
                            RebuildList()
                        ElseIf $TreeViewItems[$i][2]=0 AND BitAnd(GUICtrlRead($callingID),$GUI_CHECKED) Then
                            For $n=1 To $TreeViewItems[0][0]
                                If _GUICtrlTreeViewGetParentID($DateListTreeview,$TreeViewItems[$n][0]) = $callingID Then
                                    $TreeViewItems[$n][2]=1
                                    GUICtrlSetState($TreeViewItems[$n][0],$GUI_CHECKED)
                                EndIf
                            Next
                            $TreeViewItems[$i][2]=1
                            RebuildList()
                        EndIf
                    Else;it's a file itself
                        GUICtrlSetImage($Thumbnail,$PhotoFolder & "\" & $TreeViewItems[$i][1])
                        If $TreeViewItems[$i][2] = 1 AND BitAND(GUICtrlRead($TreeViewItems[$i][0]),$GUI_UNCHECKED) Then
                            $TreeViewItems[$i][2] = 0
                            RebuildList()
                        ElseIf $TreeViewItems[$i][2] = 0 AND BitAND(GUICtrlRead($TreeViewItems[$i][0]),$GUI_CHECKED) Then
                            $TreeViewItems[$i][2] = 1
                            RebuildList()
                        EndIf
                    EndIf
                    ExitLoop
                EndIf
            Next
    EndSwitch
EndFunc

Func RebuildList()
    $Rearranged=0
    $IncludedPicsListString=""
    GUICtrlSetData($IncludedPicsList,"")
    For $rebuildCheck=1 To $TreeViewItems[0][0]
        If $TreeViewItems[$rebuildCheck][2] = 1 AND NOT StringInStr($TreeViewItems[$rebuildCheck][1],"/") AND $TreeViewItems[$rebuildCheck][1]<>"0" Then
            $IncludedPicsListString &= $TreeViewItems[$rebuildCheck][1] & "|"
        EndIf
    Next
    GUICtrlSetData($IncludedPicsList,$IncludedPicsListString)
EndFunc

Func Exiter()
    Exit
EndFunc

While 1
    sleep(2000)
WEnd

;===============================================================================
; Function Name:    GetExtProperty($sPath,$iProp)
; Description:      Returns an extended property of a given file.
; Parameter(s):     $sPath - The path to the file you are attempting to retrieve an extended property from.
;                   $iProp - The numerical value for the property you want returned. If $iProp is is set
;                       to -1 then all properties will be returned in a 1 dimensional array in their corresponding order.
;                     The properties are as follows:
;                     Name = 0
;                     Size = 1
;                     Type = 2
;                     DateModified = 3
;                     DateCreated = 4
;                     DateAccessed = 5
;                     Attributes = 6
;                     Status = 7
;                     Owner = 8
;                     Author = 9
;                     Title = 10
;                     Subject = 11
;                     Category = 12
;                     Pages = 13
;                     Comments = 14
;                     Copyright = 15
;                     Artist = 16
;                     AlbumTitle = 17
;                     Year = 18
;                     TrackNumber = 19
;                     Genre = 20
;                     Duration = 21
;                     BitRate = 22
;                     Protected = 23
;                     CameraModel = 24
;                     DatePictureTaken = 25
;                     Dimensions = 26
;                     Width = 27
;                     Height = 28
;                     Company = 30
;                     Description = 31
;                     FileVersion = 32
;                     ProductName = 33
;                     ProductVersion = 34
; Requirement(s):   File specified in $spath must exist.
; Return Value(s):  On Success - The extended file property, or if $iProp = -1 then an array with all properties
;                   On Failure - 0, @Error - 1 (If file does not exist)
; Author(s):        Simucal (Simucal@gmail.com)
; Note(s):
;
;===============================================================================
Func _GetExtProperty($sPath, $iProp)
    Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
    $iExist = FileExists($sPath)
    If $iExist = 0 Then
        SetError(1)
        Return 0
    Else
        $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
        $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
        $oShellApp = ObjCreate("shell.application")
        $oDir = $oShellApp.NameSpace ($sDir)
        $oFile = $oDir.Parsename ($sFile)
        If $iProp = -1 Then
            Local $aProperty[35]
            For $i = 0 To 34
                $aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i)
            Next
            Return $aProperty
        Else
            $sProperty = $oDir.GetDetailsOf ($oFile, $iProp)
            If $sProperty = "" Then
                Return 0
            Else
                Return $sProperty
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_GetExtProperty

_ZipFunctions.au3

docx.zip

PhotoLogMaker2.au3

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

This reply is for 2 purposes:

1) to let you know that there seems to be a problem with the "minimalist" style of coding I used to create the .docx documents with this program - it opens the document fine under Word 2007, but any earlier versions (which require the Office 2007 filetype compatibility plugin by Microsoft) will choke when converting the document and tell you that your compatibility plugin can only open pre-release word documents (not true, in fact, just the opposite...strange). I'm working on a new .zip package that will resolve this issue.

2) to include the below (very basic) script, which really comes in handy when you're working with xml files Word has created itself - it tends to not include any line breaks or spaces for keeping the code organized in outline fashion. This script will 'tidy' an entire xml or rels format file to a more user-friendly layout, and won't break the file if it's already 'tidy'.

Happy coding...I still think this might be the beginning of really nice functionality - writing Word documents in Autoit!

$FilePath=FileOpenDialog("Choose an xml file to tidy","","XML files (*.xml)|RELS files (*.rels)|All files (*.*)")
$TheFileString=FileRead($FilePath)

$TheFileString=StringReplace($TheFileString,@CR,"")
$TheFileString=StringReplace($TheFileString,@LF,"")
Do
    $TheFileString=StringReplace($TheFileString,"  "," ")
Until @extended = 0
$TheFileString=StringReplace($TheFileString,"> <","><")

;;;
$TheFileString=StringSplit($TheFileString,"><",1)
;;;

$TheFileString[1]=$TheFileString[1]&">"
For $i=2 To $TheFileString[0]-1
    $TheFileString[$i]="<"&$TheFileString[$i]&">"
Next
$TheFileString[$TheFileString[0]]="<"&$TheFileString[$TheFileString[0]]

$TheFileHandle=FileOpen($FilePath,2)

Global $spaces=""
For $i=1 To $TheFileString[0]
    If StringLeft($TheFileString[$i],2) = "</" Then; this line is the end of a 'section' like </tag>
        $spaces=StringTrimRight($spaces,2)
        FileWriteLine($TheFileHandle,$spaces&$TheFileString[$i])
    ElseIf StringRight($TheFileString[$i],2) = "/>" OR StringLeft($TheFileString[$i],2) = "<?" Then; it's a self-closing line of code like <tag attrib=0 /> or it's the <?xml> descriptor line at the top which doesn't get closed at the end
        FileWriteLine($TheFileHandle,$spaces&$TheFileString[$i])
    Else
        If StringInStr(StringMid($TheFileString[$i],2,StringLen($TheFileString[$i])-2),"</") Then;this line is another form of a self-closing line of code like <tag attrib=0>text</tag>
            FileWriteLine($TheFileHandle,$spaces&$TheFileString[$i])
        Else;this line must be the beginning of a new 'section' like <tag attrib=0>
            FileWriteLine($TheFileHandle,$spaces&$TheFileString[$i])
            $spaces &= "  "
        EndIf
    EndIf
Next
MsgBox(0,"Tidy complete!","All done!")

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0