Accessing and Modifying Objects and Properties (Scripting)

You can access and modify any PowerDesigner object and its properties by script. Objects include not only standard design objects (such as tables, classes, processes, and columns), but also diagrams and symbols and functional objects (such as a report or repository). An object belongs to a metaclass of the PowerDesigner metamodel and inherits properties, collections and methods from its metaclass.

Root objects, such as models, are accessed using global properties and functions (see Manipulating Models, Collections, and Objects (Scripting)), while standard objects are accessed by browsing collections (see Browsing and Modifying Collections (Scripting)) or individually through the following methods: The following parameters are available:
Parameter Description
Name / Code / Path Specifies the name or code of, or the path to the object. For example, to find the column Address in the table Customer in the package Sales from the context of the model node, you could search by name Address or by path Sales/Customer/Address.
Kind Specifies the metaclass of the object to find in the form cls_PublicName. For example, to find a column, select cls_Column.

These metaclass ids are unique within their model library but, in cases such as packages, which appear in multiple types of models, you must prefix the id with the name of the module (PdOOM.cls_Package). When you create a model, you must use the module prefix (for example PdPDM.cls_Model).

OptionalParams The following parameters are optional:
  • "Stereotype" - Specifies that the object to find must bear the specified stereotype.
  • "LastFound" - Specifies to begin the search after this object. This parameter is used when several objects have the same path value, and can be used to launch a find in a while loop that uses the previous match as the last found parameter.
  • CaseSensitive=y|n - [default: y] Specifies that the search is case sensitive.
  • IncludeShortcuts - [default: n] Specifies that shortcuts can be found.
  • UseCodeInPlaceOfName - [ByPath, default: n] Specifies that the object can be found by its code (Default=n).
  • PathSeparator - [ByPath, default= /, \, or ::)] Specifies the character to separate nodes in the path.
You can get standard attribute values using the dot notation (object.attribute) or using the following methods: You can set attribute values using the dot notation (object.attribute=value) or using the following methods:
Note: For information about getting and setting extended attribute values see Creating and Accessing Extensions (Scripting)
The following script opens a sample OOM, finds a class by name and a parameter by path, and then prints and modifies some of their properties:
Dim MyModel, C, P
'Open model file
Set MyModel=OpenModel(EvaluateNamedPath("%_EXAMPLES%\" & "UML2 Sample.oom"))
'Obtain class and parameter
Set C=MyModel.FindChildByName("OrderManager",cls_Class)
Set P=Mymodel.FindChildByPath("SecurityManager/CheckPassword/login",PdOOM.cls_Parameter)

'Print initial values
Output "Initial Values:"
PrintProperties C, P
'Modify values
C.Comment="This class controls orders."
C.SetAttributeText "Visibility", "private"
P.Name="LoginName"
'Print revised values
Output "Revised Values:"
PrintProperties C, P

'Procedure for printing values
Sub PrintProperties(MyClass, MyParam)
 output "Class: " & MyClass.Name
 output vbTab & "Comment: " & MyClass.Comment
 output vbTab & "Visibility: " & MyClass.GetAttributeText("Visibility")
 output vbTab & "Persisted as: " & MyClass.GetAttributeText("PersistentGenerationMode")
 output "Parameter: " & MyParam.Parent & "." & MyParam.Name
 output vbTab & "Data type: " & MyParam.DataType
 output vbTab & "Parameter type: " & MyParam.GetAttributeText("ParameterType")
End Sub