QPR Knowledge Base 2017.1

CreateModel

CreateModel

Previous topic Next topic No directory for this topic  

CreateModel

Previous topic Next topic Topic directory requires JavaScript Mail us feedback on this topic!  

Revision history:

Introduced in QPR 7.2.1

Last changed in QPR 2012.2

 

Creates a new model. Can be used for creating both file and server models. If a server connection is open, a server model is created. A file model is created if there is no active server connection.

 

Synopsis:

 

PGApplication.CreateModel(DefaultSettings, Template | Base Model, out Model)

 

Parameters:

 

DefaultSettings: boolean flag indicating whether default settings are used.

Template | Base Model: Defines the template or a base model that is used with the new model. With file models only a file template can be used, and with server models only a server template or a base model can be used. For server templates and base models the value can be either the path of the template/base model (for example "\\Folder\Folder2\Template") or the ID of the template/base model.

out Model: Name of the variant where the model will be stored. This variant can be used with the SaveFileModelAs and SaveServerModelAs commands.

 

Required Rights:

 

Rights to use the base model.

 

Return Values:

Below are listed the return values that this function can return:

 

RV_SUCCESS

RV_APPLICATION_QUIT_CALLED

RV_CANNOT_CLOSE_MODEL

RV_CANCELLED

RV_NOT_AUTHENTICATED

RV_MODEL_DOES_NOT_EXIST

RV_INVALID_PARAMETER

RV_NO_RIGHTS_TO_MODEL

RV_UNSUPPORTED_FILE_TYPE

RV_CANNOT_READ_FROM_FILE

RV_ERROR_IN_MODEL

RV_CANNOT_OPEN_FILE

RV_UNSUPPORTED_FILE_VERSION

RV_FUNCTION_CANNOT_BE_USED_IN_VALIDATION_SCRIPT

 

Example Procedure:

 

Sub CreateAndSaveFileModels()

 Dim iResult

 Dim oModel

 iResult = PGApplication.CreateModel(True, "", oModel)

 If (iResult <> 0) Then

   MsgBox "Create file model 1 failed: " + PGApplication.GetErrorMessage(iResult)

 End If

 

 iResult = oModel.SaveFileModelAs("C:\Temp\Scripting\DefaultSettings.qprdam")

 If (iResult <> 0) Then

   MsgBox "Save file model 1 as failed: " + PGApplication.GetErrorMessage(iResult)

 End If

 

 iResult = oModel.CloseModel(1)

 If (iResult <> 0) Then

   MsgBox "Close file model 1 failed: " + PGApplication.GetErrorMessage(iResult)

 End If

 Set oModel = Nothing

 

 iResult = PGApplication.CreateModel(False, "C:\Temp\Scripting\Template.qprdat", oModel)

 If (iResult <> 0) Then

   MsgBox "Create file model 2 failed: " + PGApplication.GetErrorMessage(iResult)

 End If

 

 iResult = oModel.SaveFileModelAs("C:\Temp\Scripting\UsesTemplate.qprdam")

 If (iResult <> 0) Then

   MsgBox "Save file model 2 as failed: " + PGApplication.GetErrorMessage(iResult)

 End If

 

 iResult = oModel.CloseModel(1)

 If (iResult <> 0) Then

   MsgBox "Close file model 2 failed: " + PGApplication.GetErrorMessage(iResult)

 End If

 Set oModel = Nothing

End Sub