Scripting
Scripting
Note!
Don’t place any non script files direct into script language subdirectories !
All files e.g. in VBScript subrirectory are consider as script and non script file causes compilation error.
modules library
You can write own library and share function from library in other scripts. Unique module_name is identifier.
To call function from other module, place module name before function name:
myLibrary.someFunction()
global functions/subroutines
echo(text: string)
information box with text and button OK
sleep(ms: integer)
stops script execution for number of miliseconds
setWaitCursor([boolean])
sets screen cursor to HourGlass (true parameter) and Default one (false parameter)
inputText(label [, default_value [, cancel_value]]: string): string
input text dialog. Cancel_value is returned after press Cancel button.
setClipboardText(text: string)
stores text into clipboard
getClipboardText(): string
returns text from clipboad
runPSPadAction(ActionName: string)
allows to run any PSPad editor action. List of actions follows.
getVarValue(name: string)
returns value of variable passed as parameter. You can use PSPad or system variable as well.
reloadClips
reloads all code clip files
logClear
clears whole LOG window content
logAddLine(test: string)
adds new line into LOG
logGetLine(index: integer): string
returns line from LOG, identified by index parameter (numbered from 0)
logSetLine(index: integer, test: string)
sets log line, identified by index
logLinesCount(): Integer
returns current number of LOG window lines
logLineIndex([index: integer]): Integer
sets or returns (if no parameter) current line index of LOG window
logSetTypeMemo
sets LOG window type to memo style - you are able to make free selection, byt without error marks
logSetTypeList
sets LOG window type to list style - only line by line selection, but with error marks
logIsVisible(): Boolean
returns if LOG window is visible or not
logSetParser(expression: string): string
sets LOG parser expression
pspadVersion(): string
returns PSPad version
moduleExists(name: string):boolean
returns True if script module exists
moduleVersion(name: string):string
returns version of module, if module doesn't exists, returns empty string
moduleFileName(name: string):string
returns file name of module, if module doesn't exists, returns empty string.
modulePath():string
returns module file path include last backslash
mainWindowHandle():HWND
returns main PSpad window handle (HWND)
projectFilesCount: integer
returns number of files (not folders) in project. Use cycle from 0 to projectFilesCount-1
projectFiles(index: integer): string
returns file name for index. If file doesn't exists, returns empty string
projectItemsCount: integer
returns number of all items (files and folders) in project. Use cycle from 0 to projectItemsCount-1
projectItems(index: integer): string
returns item name for index. If item doesn't exists, returns empty string
projectItemType(index: integer): integer
returns project item type. 1: folder, 2: file, -1: item doesn't exists
projectFileName: string
returns project file name
projectSave
saves project
sample vb script
' it will create new editor window, copy all text from first window into new
' and save new file as C:\SAMPLE.TXT
const module_name = "sample" 'this name must be unique !!!
const module_desc = "Sample script" 'script description
const module_ver = "0.001a" 'version
sub Main 'main procedure
dim s 'variable definition
pspadVersion
msgbox "PSPad version : " & pspadVersion()
msgbox "Module version: " & moduleVersion("sample")
set obj1 = newEditor() 'new editor object
set obj2 = newEditor() 'new editor object
obj2.assignEditorByIndex(0) 'assign PSPad window 1 to obj2
obj1.NewFile() 'opens new file in PSPad and assign to
obj2
s = obj2.getText 'returns all text from window 1
obj1.settext(s) 'replaces all text in new window
' here is presented access to editor lines line by line
dim item
for each item in obj1
MsgBox item
next
obj1.saveFileAs("C:\sample.txt") 'save as new editor
obj1.closeFile 'close copy file
end sub
sub Demo1
msgbox "You run Demo1 from sample script"
end sub
sub Demo2
msgbox "You run Demo2 from sample script"
end sub
sub Procedure
set obj = NewEditor()
for i = 0 to editorsCount - 1
obj.assignEditorByIndex(i)
obj.activate
if i = 0 then 'for first file we call user convertor selector
runPSPadAction "aUserConvertors"
else 'for all other files we run last used convertor
runPSPadAction "aLastUserConvertor"
end if
next
end sub
' name "Init" is required, its called automatically during initialization to
create menu items
sub Init
addMenuItem "Run action demo (convert all open files)","", "Procedure"
end sub