[PYTHON] Generate Custom Sizes for ArtRage4

In the initial state, ArtRage does not have sizes such as A4 and B5 when creating a new one. However, since it is possible to add it as a custom size, it is not a big problem in itself, but it was a little troublesome to add it one by one, so I wrote a script to automatically generate it as a trial. (The operation was confirmed with ArtRage4 (4.0.4).)

The usage is like this.

$ python artrage_papersize.py A4 A5 B5 --dpi 300

In the above example

File will be generated in the current folder.

Save the generated file to ArtRage's Custom Sizes as needed.

artrage_paparsize.py


#!/usr/bin/env  python
# -*- coding: utf-8 -*-
#
# ------------------------------------------------------------------ import(s)
import  sys
import  struct
import  argparse



# ------------------------------------------------------------------- param(s)
ARTRAGE_HEAD  = u"ARSizePresetFileVersion-1\r\n"
PAPER_SIZE    = {
  "A" : { "X" :  841, "Y" : 1189 },
  "B" : { "X" : 1030, "Y" : 1456 },
}
MM_INCH       = 0.03937



# ---------------------------------------------------------------- function(s)

# ============================================================================
##
#
def calc_size( fX, fY ):

  return( fY / 2, fX )



# ============================================================================
##
#
def export_file( strFilename, fX, fY, nDPI ):

  with open( strFilename, "wb" ) as hFile:
    hFile.write( ARTRAGE_HEAD.encode( "utf-16-le" ) )
    hFile.write( struct.pack( "BBBBIIf", 0x01, 0x34, 0x00, 0xFF, 4, 0,   fX ) )
    hFile.write( struct.pack( "BBBBIIf", 0x02, 0x34, 0x00, 0xFF, 4, 0,   fY ) )
    hFile.write( struct.pack( "BBBBIIf", 0x01, 0x31, 0x00, 0xFF, 4, 0, nDPI ) )
    hFile.write( struct.pack( "BBBBIII", 0x00, 0x34, 0x00, 0xFF, 4, 0,    0 ) )
    hFile.close()



# ============================================================================
##
#
def main():

  oCParser  = argparse.ArgumentParser( description = "ArtRage Paper Generator" )
  oCParser.add_argument(
    "paper",
    help  = "Set paper (ex: A4, B5)",
    nargs = "+"
  )
  oCParser.add_argument(
    "-d", "--dpi",
    help    = "Set dpi",
    default = 300
  )

  oCParams  = oCParser.parse_args( sys.argv[ 1: ] )


  for strPaper in oCParams.paper:

    if( len( strPaper ) != 2 ):
      continue
    if( strPaper[ 0 ].upper() not in ( "A", "B" ) ):
      continue

    try:
      strP  = strPaper[ 0 ].upper()
      nSize = int( strPaper[ 1 ] )
      nDPI  = oCParams.dpi
    except:
      continue


    fX  = PAPER_SIZE[ strP ][ "X" ] * nDPI * MM_INCH
    fY  = PAPER_SIZE[ strP ][ "Y" ] * nDPI * MM_INCH

    for nSplitCount in range( nSize ):
      fX, fY  = calc_size( fX, fY )

    strFilenameP = "%s%d Port.spr"  % ( strP, nSize, )
    strFilenameL = "%s%d Land.spr" % ( strP, nSize, )
    export_file( strFilenameP, fX, fY, nDPI )
    export_file( strFilenameL, fY, fX, nDPI )



if( __name__ == "__main__" ):
  main()



# ---------------------------------------------------------------------- [EOF]

Recommended Posts

Generate Custom Sizes for ArtRage4
Automatically generate EDT for ECHONET telegram