Jump to content

Batch import jpeg/png convert to image resource


Recommended Posts

Hi there, 

 

can anyone help me change this script to import a image resource rather than a symbol into the resource browser?

 

import os

major, minor, maintenance, platform = vs.GetVersion()
isMac = False
if platform == 1: isMac = True

# define a location to import the images
importPt = (0,0)

symCreatedCnt = 0

err, dirPath = vs.GetFolder( 'Select a Folder' )
if err == 0: # no-error
    hsfDirPath = dirPath
    if isMac: ok, hsfDirPath = vs.ConvertPosix2HSFPath( dirPath )

    fileIndex = 1
    while True: # loop the files
        fileName = vs.GetFilesInFolder( hsfDirPath, fileIndex )
        fileIndex += 1

        if fileName == '': # no more files
            break

        name, ext = os.path.splitext( fileName )
        if ext.lower() == '.png' or ext.lower() == '.jpg':
            imagePath = os.path.join( dirPath, fileName )

            vs.BeginSym( name )
            hImage = vs.ImportImageFile( imagePath, importPt )
            vs.EndSym()
            symCreatedCnt += 1

vs.AlrtDialog( 'Done! Created ', symCreatedCnt , ' symbols.' )

 

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...