|
||
Revision history:
Introduced in QPR 7.3.1
Last changed in QPR 2016.1
Imports the defined model contents or defined child diagram from the model to the currently open process model under process step given by parameter ElementId. When a whole model is imported, all information items, organizations, stores, and resources are imported. Measures and cases are not imported. When a single diagram is imported, only the information items, organizations, stores, and resources that are in use in the diagram (or child diagrams) are imported. When importing a model again, various attributes and elements can be defined to be updated instead of creating a new element. The following elements and attributes can be updated in import:
•Information items
•Name
•Description
•Custom attributes
•Information location
•Embedded information
•Information item type
•Organization items
•Name
•Description
•Custom attributes
•Type
•Stores
•Name
•Description
•Custom attributes
•Resources
•Name
•Description
•Custom attributes
•Resource type
•Units/amount available
•Unit cost
•Unit
•Unit name
•Store size
•Ordering limit
•Order size
•Ordering cost
•Ordering time
Synopsis:
PGModel.ImportModel(ElementId, ImportModel, ImportProcessLevelName|ImportProcessLevelID, Options, out Log)
Parameters:
ElementId: Integer. ID of the diagram type of process step in the target model where the model is imported to. If this is 0, the imported model is created to top level diagram. If given ElementId is not of the type diagram, then an error is returned. In addition, in the case the target level is the main level, also the model description and feedback address are copied from the source model to the target model.
ImportModel: Variant. Server model ID (integer), server model name (string), or a file name (string). Filename can have an absolute or a relative path. If no path is given, function tries to load the import model from the current PG default path. Also server models require the path information to be visible in the case the model is identified by a name string, so for example \\ModelName or \\folder\ModelName are valid values.
ImportProcessLevelName|ImportProcessLevelID: Variant. Name (string) or ID (integer) of source model diagram element. In the case this is empty, the whole model is imported.
Options: String. A ";" separated text list of options. The possible options are:
•ModelDescription. Either Description (which copies the description of the source model or child diagram to the target element's Description field) or the name of the custom attribute to which the imported model's description is copied.
•ModelFeedbackAddress. Either FeedBackAddress (which copies the feedback address of the source model to the target model's Feedback Address field) or the name of the custom attribute to which the imported model's feedback address is copied. Works only when importing full models.
•ModelInformationItems. Defines whether imported information items originally connected to the source model's source level are connected to the target model's target level. TRUE or FALSE. FALSE by default.
•ModelCustomizedProcessStep. Name of a boolean custom attribute that indicates customized child diagrams. In the case the custom attribute's value is TRUE, a child diagram having a matching ID in the source model is not imported, but the customized child diagram is used instead.
•ModelVersionInformation. Defines whether model version information is imported to the target model. In the case a whole model is imported, its version information is copied either to the whole model (in the case the target is a model), or to a child diagram (in the case the target is a child diagram). In the case of a child diagram, version information is also enabled for the child diagram. In the case of importing a child diagram from the source model, version information is copied to the target child diagram only in the case version information is enabled for the child diagram (it is not enabled automatically as in importing a whole model). TRUE or FALSE. FALSE by default.
•ImportedObjectID: String. Name of a custom attribute used for storing the ID of an imported child diagram. In the case this option is omitted, the ID is stored to a custom attribute named ImportedObjectID. In the case the value is empty (i.e. ImportedObjectID=), the ID is not stored to any custom attribute.
•SetAttribute: String. Uses syntax SetAttribute=<Custom attribute name>:Value and sets the value in Value parameter to the custom attibute defined in <Custom attribute name> for all imported elements. This option does not create new custom attributes, i.e. the value is set to only those elements that already have the corresponding custom attribute. The SetAttribute option can be used multiple times to set values for many custom attributes in the same call. Works for boolean, number, text, and memo type of custom attributes.
•UpdateMethod: String. This option defines how elements are updated during import. Note that the matching done in the NONE and ALL options depends on the IdentifyBy option. The possible options are:
•NONE: If a matching element is found in the target model, but attributes are not the same, a conflict message is written to the log. If an element in the source model is not found in the target model, it is created there.
•ALL: If a matching element is found in the target model, but attributes are not the same, the attributes in the target model element are updated to correspond to those in the source model and a notification is written to the log. If an element in the source model is not found in the target model, it is created there.
•BYORIGIN: Update only those elements that originate from the source model (i.e. the model has been imported previously and the imported elements are tagged with the source model ID). In the case the model ID defined in an imported element's custom attribute (the name of which is defined in the UpdateByOrigin option) matches the ID of the model that is being imported, the target element is updated and a notification is written to the log, otherwise a new element is created. This requires that also the UpdateByOrigin option is defined.
•UpdateByOrigin: String. Name of the custom attribute that contains the ID of the source model. This custom attribute must be of type Number.
•IdentifyBy: String. This option defines how duplicate elements are identified from the target model. Note that element types are always identified by the element type symbol. The possible options are:
•NAME (default value): Identifies the duplicates by the element names. In addition, updates the element symbol.
•SYMBOL: Identifies the duplicates by element symbols.
•GenerateChangeList: Boolean. If true, the out Log array is generated on all imported elements. The conflict code and description are empty for those elements that have no conflict. Default value is false.
•DropOutsideConnector: Boolean. If true, when a diagram level is imported, the import drops all connectors that are incoming or outgoing outside of the selected diagram or its child elements, i.e. import only connectors whose both ends are in the imported data. Default value is false.
out Log: Variant array. Log is a two-dimensional variant array containing one entry for each conflict encountered in import. Each entry contains the following information:
•Element ID in the currently open model. Integer.
•Element ID in the imported model. Integer.
•Element name. String.
•Conflict code. Integer.
•Conflict description. String.
Required Rights:
Full rights for the import's target level and all levels below it (they are deleted during the import), and at least view rights for the import's source level. However, in the case the source level has additional diagrams below it and you do not have rights to those levels, the additional levels are ignored in the import.
Return Values:
Below are listed the return values that this function can return:
RV_SUCCESS
RV_MODEL_DOES_NOT_EXIST
RV_UNSUPPORTED_FILE_TYPE
RV_CANNOT_OPEN_MODEL
RV_LOGIN_FAILED
RV_UNKNOWN_ERROR
RV_ELEMENT_NAME_NOT_UNIQUE
RV_ELEMENT_NOT_FOUND
RV_NO_RIGHTS_TO_MODEL
RV_ELEMENT_IS_NOT_SUBPROCESS
RV_CUSTOM_ATTRIBUTE_NOT_FOUND
RV_INVALID_CUSTOM_ATTRIBUTE_TYPE
RV_INVALID_CUSTOM_ATTRIBUTE_NAME
RV_APPLICATION_QUIT_CALLED
RV_MODEL_NOT_OPEN
RV_PARAMETER_MISSING
RV_FUNCTION_CANNOT_BE_USED_IN_VALIDATION_SCRIPT
RV_CANNOT_IMPORT_FROM_DEMO_MODEL
Example Procedure:
Sub Main()
Dim iResult
Dim avLog
Dim sMessage
Dim i
iResult = PGModel.ImportModel(0, "C:\Source\Misc\Scripting\source.qprdam", "", _
"ModelInformationItems=true;ModelDescription=Description; _
ModelFeedBackAddress=FeedBackAddress;ImportedObjectId=R5. Imported Id; _
SetAttribute=Customized:false;SetAttribute=Model Id:123456; _
SetAttribute=Custom Description:new custom description", avLog)
If (iResult <> 0) Then
MsgBox "Could not import model: " + PGApplication.GetErrorMessage(iResult)
End If
If (VarType(avLog) <> 0) Then
sMessage = "Import conflicts:" + vbLf + vbLf
For i = 0 To UBound(avLog, 1)
sMessage = sMessage + avLog(i, 2) + " (" + CStr(avLog(i, 0)) + ") - " + _
avLog(i, 4) + vbLf
Next
MsgBox sMessage
End If
End Sub