User Tools

Site Tools


DzScript

Encapsulates a DAZ Script script.

More...

Inherits :

Enumerations

Static Methods

Constructors

DAZ Script
DzScript ()
DzScript ( DzScript script )

Methods

DAZ Script
voidaddCode ( String code )
voidaddLine ( String line, Number indentLevel=0 )
voidaddLines ( String code, Number indentLevel=0 )
Booleancall ( String function, Array args )
BooleancheckSyntax ()
voidclear ()
BooleanconvertToDAZScript2 ()
NumbererrorLine ()
StringerrorMessage ()
Booleanexecute ()
Booleanexecute ( Array args )
DzAuthorgetAuthor ()
StringgetCode ()
StringgetFilename ()
BooleangetLastStatus ()
ScriptLanguagegetScriptLanguage ()
StringgetScriptType ()
DzVersiongetScriptVersion ()
BooleangetShouldReuseInterpreter ()
BooleanisEmpty ()
BooleanisEncrypted ()
BooleanloadFromFile ( String filename, Boolean convert=true )
voidmakeEncrypted ()
Objectresult ()
DzErrorsaveFile ( String filename, ScriptFileMode mode, String filetype=“DAZ Script”, DzVersion version=DzApp::getVersion() )
DzErrorsaveFile ( String filename )
voidsetCode ( String code )
voidsetReuseInterpreter ( Boolean onoff )
ArraystackTrace ()
BooleanwasConverted ( DzScript::ScriptLanguage language=DAZScript1 )
Methods (Deprecated)
DzErrorsaveToFile ( String filename, ScriptFileMode mode=UseExtension, String filetype=“DAZ Script” )

Detailed Description

TODO: Add detailed description.

Enumerations


: ScriptFileMode

Save mode for saving the script to file.

  • UseExtension - If the file extension is .dsb, the file is saved as DAZScriptFile, otherwise as TextScriptFile
  • TextScriptFile - Plain text file - no Unicode support
  • DAZScriptFile - Binary DAZ file format - supports Unicode characters
  • EncDAZScriptFile - Encrypted Binary DAZ file format - supports Unicode characters

—–

: ScriptLanguage

Script language of the file.

  • Unknown - Unknown language.
  • DAZScript1 - DAZ Script 1 (QSA) language.
  • DAZScript2 - DAZ Script 2 (QtScript) language.

Static Methods


void : addScriptBinaryExtensionsAsMultipleFilters( DzFileFilter filter )

Parameter(s):

  • filter - The filter to add the binary extensions to.

void : addScriptBinaryExtensionsToFilter( DzFileFilter filter )

Parameter(s):

  • filter - The filter to add the binary extensions to.

void : addScriptOpenExtensionsAsMultipleFilters( DzFileFilter filter )

Parameter(s):

  • filter - The filter to add the open extensions to.

void : addScriptOpenExtensionsToFilter( DzFileFilter filter )

Parameter(s):

  • filter - The filter to add the open extensions to.

void : addScriptSaveExtensionsAsMultipleFilters( DzFileFilter filter )

Parameter(s):

  • filter - The filter to add the save extensions to.

void : addScriptSaveExtensionsToFilter( DzFileFilter filter )

Parameter(s):

  • filter - The filter to add the save extensions to.

void : addScriptTextExtensionsAsMultipleFilters( DzFileFilter filter, Boolean includeDeprecated=false )

Parameter(s):

  • filter - The filter to add the plain text extensions to.
  • includeDeprecated - Whether or not to include the deprecated extension(s).

void : addScriptTextExtensionsToFilter( DzFileFilter filter, Boolean includeDeprecated=false )

Parameter(s):

  • filter - The filter to add the plain text extensions to.
  • includeDeprecated - Whether or not to include the deprecated extension(s).

Object : evaluate( String code, QObject context=null )

This function is provided as a quick method of evaluating DAZ Script statements without needing to create a DAZ Script object.

Parameter(s):

  • code - The text string to evaluate as a script.
  • context - The QObject instance (if any) that will provide the script's context.

Return Value:

  • The value returned from the script's execution.

Array : getScriptExtensions()

Return Value:

  • A list of the script file extensions supported by the application.

String : getScriptFile( String filenameWithoutExtension )

Parameter(s):

  • filenameWithoutExtension - The path to the file, minus the '.' and the extension.

Return Value:

  • The path of the file, with extension, of the script found. Otherwise, an empty String.

Boolean : isScriptBinaryExtension( String extension )

Parameter(s):

  • extension - The file extension (minus the '.') to check.

Return Value:

  • true if extension is a supported binary script extension, otherwise false.

Boolean : isScriptBinaryFile( String filename )

Parameter(s):

  • filename - The name of the file to check.

Return Value:

  • true if filename ends with a supported binary script extension, otherwise false.

Boolean : isScriptExtension( String extension )

Parameter(s):

  • extension - The file extension (minus the '.') to check.

Return Value:

  • true if extension is a supported script extension, otherwise false.

Boolean : isScriptFile( String filename )

Parameter(s):

  • filename - The name of the file to check.

Return Value:

  • true if filename ends with a supported script extension, otherwise false.

Boolean : isScriptTextExtension( String extension )

Parameter(s):

  • extension - The file extension (minus the '.') to check.

Return Value:

  • true if extension is a supported [ascii] plain text script extension, otherwise false.

Boolean : isScriptTextFile( String filename )

Parameter(s):

  • filename - The name of the file to check.

Return Value:

  • true if filename ends with a supported [ascii] plain text script extension, otherwise false.

String : legalizeName( String str )

Return Value:

  • A converted version of a string (which may contain special characters) that would be legal as a variable name in script. If the string contains no special characters, the result will be identical to the input.

Constructors


DzScript()

Default constructor.


DzScript( DzScript script )

Copy Constructor.

Parameter(s):

  • script - The script to copy.

Methods


void : addCode( String code )

Appends the given code to the end of the current script.

Parameter(s):

  • code - The text to append to the current script.

void : addLine( String line, Number indentLevel=0 )

Appends the given string and a newline character to the script.

Parameter(s):

  • line - The text to add to the script.
  • indentLevel - The number of tab characters to insert in front of the line.

void : addLines( String code, Number indentLevel=0 )

Appends the given code to the end of the current script.

Parameter(s):

  • code - The text to append to the current script.
  • indentLevel - The number of tab characters to insert in front of each line.

Boolean : call( String function, Array args )

Calls a function in the script.

Parameter(s):

  • function - The name of the function to call.
  • args - A list of arguments to pass to the function.

Return Value:

  • true if the function was called successfully, false if there was an error.

Attention:

  • The entire script is evaluated before the function call is made.

Boolean : checkSyntax()

Checks the syntax of the script for errors using the current interpreter.

Return Value:

  • true if the syntax is valid, otherwise false.

void : clear()

Clears any code in the current script, and clears the encryption state if the script was read from an encrypted file.


Boolean : convertToDAZScript2()

Converts the script to DAZ Script 2 syntax.


Number : errorLine()

Return Value:

  • The line number that the last error occurred on.

String : errorMessage()

Return Value:

  • The last error message gathered from a call to execute(). An empty string if no error has been encountered for this script.

Boolean : execute()

Execute the script.

Attention:

  • This can be called from a thread outside of the GUI thread, however the script will not be executed until the GUI thread processes events. It returns when execution is complete.

Return Value:

  • true if the script was executed successfully, false if there was an error.

Boolean : execute( Array args )

Execute the script with an argument list.

Attention:

  • This can be called from a thread outside of the GUI thread, however the script will not be executed until the GUI thread processes events. It returns when execution is complete.

Parameter(s):

  • args - The list of arguments to pass to the script.

Return Value:

  • true if the script was executed successfully, false if there was an error.

DzAuthor : getAuthor()

Return Value:

  • The author of this script if it was loaded from a file that provides authorship information.

String : getCode()

Return Value:

  • The code of the current script.

String : getFilename()

Return Value:

  • The name and path of the file associated with this script. An empty string is returned if this script is not associated with a file.

Boolean : getLastStatus()

Return Value:

  • true if the last execution was successful, otherwise false.

ScriptLanguage : getScriptLanguage()

Return Value:

  • An enumerated value indicating the scripting language of the script.

String : getScriptType()

Return Value:

  • A string describing the kind of script that this script is

DzVersion : getScriptVersion()

Return Value:

  • The version of DAZ Studio that this script was saved from. The current version if the script was not loaded from a file.

Boolean : getShouldReuseInterpreter()

Return Value:

  • true if the same context is used between uses of call(); otherwise false (default).

See Also:


Boolean : isEmpty()

Return Value:

  • true if the script is empty; otherwise false.

Boolean : isEncrypted()

Return Value:

  • true if the contents of the script are encrypted (i.e. read from an encrypted file); otherwise false.

Attention:

  • If the script is encrypted, getCode() returns '[Content Encrypted]', addLine(), addCode(), and setCode() have no effect, saveToFile() and saveFile() save nothing and will return DZ_OPERATION_FAILED_ERROR. Calling clear() will clear the encryption state and the code from the script.

Boolean : loadFromFile( String filename, Boolean convert=true )

Loads the script from a file.

Parameter(s):

  • filename - The path of the script file to load.
  • convert - If true (default), converts the file to DAZ Script 2.

Return Value:

  • true if the script was successfully loaded, otherwise false.

void : makeEncrypted()

Sets the script to be encrypted.

Attention:

  • This process is not reversible!!! Once a script has been encrypted its original text cannot be extracted. Encrypted scripts can not be edited or modified.

Object : result()

Return Value:

  • The result of the last script execution.

DzError : saveFile( String filename, ScriptFileMode mode, String filetype=“DAZ Script”, DzVersion version=DzApp::getVersion() )

Save the script to a file.

Parameter(s):

  • filename - The filename of the file to save to.
  • mode - The type of file to save.
  • filetype - The filetype that is saved as part of the file information.
  • version - The version of the file to be written.

Return Value:

  • DZ_NO_ERROR on success, otherwise an appropriate error code.

Attention:

  • It is the developer's responsibility to ensure that the data being written to file is compatible with the version specified.

Since:

  • 4.11.0.129

DzError : saveFile( String filename )

Save the script to a file.

Parameter(s):

  • filename - The filename of the file to save to.

Since:

  • 4.11.0.129

void : setCode( String code )

Replaces the existing code of the script with code.

Parameter(s):

  • code - The new text for the script.

void : setReuseInterpreter( Boolean onoff )

Sets whether the same context is used between uses of call().

Parameter(s):

  • onOff - If true, the same context is used between calls. If false a new context is used for each call.

Attention:

  • Use of this function clears the context, regardless of whether onOff is set to true or false.

See Also:


Array : stackTrace()

Return Value:

  • The stack trace for the last time an error was reported during a call to execute(). An empty list if no error has been encountered.

Boolean : wasConverted( DzScript::ScriptLanguage language=DAZScript1 )

Access to whether or not the script was converted from the enumerated value specified.

Return Value:

  • true if the script was converted

DzError : saveToFile( String filename, ScriptFileMode mode=UseExtension, String filetype=“DAZ Script” )

Deprecated

Exists only to keep old code working. Do not use in new code. Use saveFile() instead.