How to make your own icon packs

Share icons for use on toolbars, etc.
Tenebrous
Registered Opus Pro User
Posts: 181
Joined: 05 Nov 2016, 13:22
OS: Windows 10 64-bit
Opus: Latest Beta
You need:



Instructions:


  • Put montage.exe, zip.exe, doicon.bat and your icons somewhere useful on your machine, so you have:
    montage.exe
    zip.exe
    doicons.bat
    + bunch of icons

  • Use doicon.bat file in the same location, and run it like this:
    doicon.bat sourcefiles destinationname

    for example
    doicon.bat *.png MyAmazingIcons


  • Watch with amazement as your icons get squished into a 22x22 version and a 32x32 version and wrapped up into a Directory Opus .dis file

  • If you didn't bother getting zip.exe then you will receive:
    MyAmazingIcons.xml
    MyAmazingIcons-22.png
    MyAmazingIcons-32.png
    - you'll need to zip these up yourself and rename the resulting zip file to .dis, which Directory Opus can then use

  • Import into Directory Opus

  • PROFIT!!


Hope this comes in useful to someone!

  • 2016-11-23 Fixed error where zipped file would contain paths, and added a 1px border around the tiles
  • 2016-11-23 Updated batch file so that it doesn't include the -22.png and -32.png inside themselves.
Attachments
doicon.zip
(840 Bytes) Downloaded 40 times
Last edited by Tenebrous on 23 Nov 2016, 08:02, edited 3 times in total.

User avatar
kundal
H&P
Posts: 897
Joined: 07 Apr 2010, 10:06
OS: Windows 10 64-bit
Opus: Directory Opus 12
Location: Germany
Nice idea, but it adds lines for "test-22.png" and "test-32.png" to "test.xml" and "test-22.png" will appear as an icon in "test-32.png". Montage.exe should probably create these images outside the source folder.

Tenebrous
Registered Opus Pro User
Posts: 181
Joined: 05 Nov 2016, 13:22
OS: Windows 10 64-bit
Opus: Latest Beta
Very true, I'll update

Edit: I've fixed this
Last edited by Tenebrous on 23 Nov 2016, 01:45, edited 1 time in total.

User avatar
kundal
H&P
Posts: 897
Joined: 07 Apr 2010, 10:06
OS: Windows 10 64-bit
Opus: Directory Opus 12
Location: Germany
You can run the batch from a button type "MSDOS batch function". This button code requires montage.exe and optionally zip.exe located in a path thats present in the PATH environment variable of windows. Otherwise you'll have to provide the path to montage.exe in line 8 and 9 and for zip.exe in line 47. Montage exe will create the images in %temp% and they are moved to sourcepath when writing the XML was finished. You will be asked for the required values for files and the name of the iconset by a dialog.

Code: Select all

@externalonly
@runmode hide
@set files = {dlgstring|Select files:|*.png}
@set name = {dlgstring|Enter name of Iconset:}
cd {sourcepath}
chcp 65001
    @echo off
    setlocal EnableDelayedExpansion

    montage {$files} -geometry 20x20+1+1 -tile 16 -background transparent %temp%\{$name}-22.png
    montage {$files} -geometry 30x30+1+1 -tile 16 -background transparent %temp%\{$name}-32.png

    echo. > {$name}.tmp
    set row=1
    set col=1
    for %%i in ({$files}) do ( 
        echo         ^<icon row="!row!" col="!col!" name="%%~ni"/^>                           >> {$name}.tmp
        set /A col=col+1
        if !col! GTR 16 (
            set col=1
            set /A row=row+1
        )
    )
    echo. >> {$name}.tmp

    echo ^<?xml version="1.0" encoding="UTF-8"?^>                                             > {$name}.xml
    echo ^<iconset name="{$name}"^>                                                      >> {$name}.xml
    echo ^<display_name^>{$name}^</display_name^>                                             >> {$name}.xml
    echo      ^<copyright^>^</copyright^>                                                     >> {$name}.xml
    echo      ^<artist^>^</artist^>                                                           >> {$name}.xml

    echo      ^<set filename="{$name}-22.png" height="22" size="small" width="22"^>           >> {$name}.xml
    type {$name}.tmp >> {$name}.xml
    echo      ^</set^>                                                                        >> {$name}.xml

    echo      ^<set filename="{$name}-32.png" height="32" size="large" width="32"^>           >> {$name}.xml
    type {$name}.tmp >> {$name}.xml
    echo     ^</set^>                                                                         >> {$name}.xml

    echo ^</iconset^>                                                                         >> {$name}.xml

    del {$name}.tmp

    move %temp%\{$name}-22.png {sourcepath}
    move %temp%\{$name}-32.png {sourcepath}

    if exist zip.exe (
    zip {$name}.dis {$name}-22.png {$name}-32.png {$name}.xml
    del {$name}-22.png
    del {$name}-32.png
    del {$name}.xml
    )
    goto :eof
Last edited by kundal on 27 Nov 2016, 04:41, edited 1 time in total.

Tenebrous
Registered Opus Pro User
Posts: 181
Joined: 05 Nov 2016, 13:22
OS: Windows 10 64-bit
Opus: Latest Beta
Nicely done - I'm using my version to quickly re-generate the same icon set with minor changes without having to select the PNGs or re-enter the icon set name.

You could put montage.exe and zip.exe in a /dopusdata/Tools subfolder then you'd be able to find them via that alias.

Also, will "cd {sourcepath}" work if the path is on a different drive?

User avatar
kundal
H&P
Posts: 897
Joined: 07 Apr 2010, 10:06
OS: Windows 10 64-bit
Opus: Directory Opus 12
Location: Germany
I think since DOpus 11 the default working folder for functions called by toolbar buttons is /system (\Windows\system32). cd {sourcepath} is needed to make the command working on the current active tab. It should work everywhere if the tool you called supports this.
There's an advanced option in Preferences=>Miscellaneous=>Advanced which allows changing the default working folder to {sourcepath}: def_func_cd_sourcedir

User avatar
leo
GPSoftware
Posts: 36498
Joined: 07 Nov 2004, 01:30
OS: Windows 10 64-bit
Opus: Directory Opus 12
Location: London, UK
Contact:
I think Tenebrous was asking if you wanted to use "cd {sourcepath}" or "cd /D {sourcepath}" since the DOS CD command (unlike the Opus CD command) can't change both drive and folder at once unless /D is specified.

In this particular case, it may not matter. Even with a DOS Batch button type and @externalonly specified, if the cd command before any other external commands in the batch file (ignoring any Opus @modifiers and any other cd commands), then Opus will handle it specially, and it does not matter if it has /D or not. If it was lower down then you would need the /D if you were changing to another drive.

(In normal buttons, when not using the DOS Batch type, you shouldn't use /D at all.)

Tenebrous
Registered Opus Pro User
Posts: 181
Joined: 05 Nov 2016, 13:22
OS: Windows 10 64-bit
Opus: Latest Beta
Yeah that's what I meant, and you're right since the cd is so high that's fine - I had forgotten/not known that Opus had a special CD.

User avatar
kundal
H&P
Posts: 897
Joined: 07 Apr 2010, 10:06
OS: Windows 10 64-bit
Opus: Directory Opus 12
Location: Germany
The button code I provided above produced invalid XML files if an icon name contained german Umlauts like ü or ä. DOpus didn't show the resulting iconsets. I added the line chcp 65001 to the code to make it working correctly.

User avatar
leo
GPSoftware
Posts: 36498
Joined: 07 Nov 2004, 01:30
OS: Windows 10 64-bit
Opus: Directory Opus 12
Location: London, UK
Contact:
Will still go wrong with other languages, of course.

Using JScript or VBScript instead of DOS batch would avoid the problem, since they use Unicode.

User avatar
kundal
H&P
Posts: 897
Joined: 07 Apr 2010, 10:06
OS: Windows 10 64-bit
Opus: Directory Opus 12
Location: Germany
Using JScript or VBScript instead of DOS batch would avoid the problem, since they use Unicode.

Here we go:
button type: script function. zip.exe isn't needed because DOpus can do that.

Code: Select all

Option Explicit
Function OnClick(data)
Dim all, archive, cmd, col, files, i, name, objStream, objOutputFile, row, text
files = DOpus.Dlg.GetString("Select files:","*.png")
name = DOpus.Dlg.GetString("Enter name of Iconset:")
Set cmd = data.Func.Command
Set text = DOpus.FSUtil.Resolve(cmd.sourcetab.path & "\" & name & ".xml")
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
row=1
col=1
   
    objStream.WriteText "<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "UTF-8" & """" & "?>" & vbCrLf &_
        "<iconset name=" & """" & name & """" & ">" & vbCrLf & vbTab &_
        "<display_name>" & name & "</display_name>" & vbCrLf & vbTab &_
        "<copyright></copyright>" & vbCrLf & vbTab &_
        "<artist></artist>" & vbCrLf & vbCrLf & vbTab &_
        "<set filename=" & """" & name & "-22.png" & """" &" height=" & """" & "22" & """ size=" & """" & "small" & """ width =" & """" & "22" & """" & ">" & vbCrLf

    For i=0 To cmd.sourcetab.all.count -1
        objStream.WriteText vbTab & vbTab & "<icon row=" & """" & row & """" & " col=" & """" & col & """" & " name=" & """" & cmd.sourcetab.all(i).name_stem & """" & "/>" & vbCrLf
        col=col+1
        If col > 16 Then
         col=1
           row=row+1
      End If
    Next
   row=1
   col=1

   objStream.WriteText  vbTab & "</set>" & vbCrLf & vbCrLf & vbTab &_
      "<set filename=" & """" & name & "-32.png" & """" &" height=" & """" & "32" & """ size=" & """" & "large" & """ width =" & """" & "32" & """" & ">" & vbCrLf

    For i=0 To cmd.sourcetab.all.count -1
        objStream.WriteText vbTab & vbTab & "<icon row=" & """" & row & """" & " col=" & """" & col & """" & " name=" & """" & cmd.sourcetab.all(i).name_stem & """" & "/>" & vbCrLf
        col=col+1
        If col > 16 Then
         col=1
           row=row+1
      End If
    Next
   objStream.WriteText vbTab & "</set>" & vbCrLf & "</iconset>"
   objStream.SaveToFile text,2
   objStream.Close

   cmd.SetModifier "runmode","hide"
   cmd.AddLine("CD {sourcepath}")
   cmd.AddLine("Select " & files)
    cmd.AddLine("montage {allfile} -geometry 20x20+1+1 -tile 16 -background transparent " & name & "-22.png")
    cmd.AddLine("montage {allfile} -geometry 30x30+1+1 -tile 16 -background transparent " & name & "-32.png")
    cmd.AddLine("Copy MOVE TO {sourcepath} " & """" & name & ".xml" &"""" & " ARCHIVE=.dis CreateFolder " & """" & name & """")
    cmd.AddLine("Copy MOVE TO {sourcepath} " & """" & name & "-22.png" & """" & " ARCHIVE=.dis CreateFolder " & """" & name & """")
    cmd.AddLine("Copy MOVE TO {sourcepath} " & """" & name & "-32.png" & """" & " ARCHIVE=.dis CreateFolder " & """" & name & """")
    cmd.AddLine("Select DESELECTNOMATCH " & name & ".dis MAKEVISIBLE")
   cmd.Run
End Function


Return to “Icons”