You can use scripts to create and open models, and to manipulate objects and symbols in PowerDesigner.
Creating a Model by Script
You create a model using the CreateModel (modelkind As Long, filename As String = "", flags As Long =omf_Default) As BaseObject global function together with the cls_Model constant prefixed with the Module name to identify the type of model you want to create.
Opening a Model by Script
You open a model using the OpenModel (filename As String, flags As Long =omf_Default) As BaseObject global function.
Creating an Object by Script
It is recommended to create an object directly from the collection to which it belongs in order to directly obtain a valid state for the object. When you do so, you only create the object but not its graphical symbol.
Creating a Symbol by Script
You create the associated symbol of an object by attaching it to the active diagram using the following method: AttachObject(ByVal Obj As BaseObject) As BaseObject.
Positioning a Symbol next to Another by Script
You position a symbol next to another using the X and Y (respectively Abscissa and Ordinate) points, together with a combination of method (Position As Apoint) and function (NewPoint(X As Long = 0, Y As Long = 0) As Apoint)).
Retrieving an Object by Script
The following example illustrates how you can retrieve an object by its code in the model
Creating a Shortcut by Script
You create a shortcut in a model using the CreateShortcut(ByVal NewPackage As BaseObject, ByVal ParentCol As String = "") As BaseObject method.
Creating a Link Object by Script
You create a link object using the CreateNew(kind As Long = 0) As BaseObject method, then you have to declare its ends.
Browsing a Collection by Script
All collections can be iterated through the usual "For Each variable In collection" construction.
Manipulating Objects in a Collection by Script
In the following example, we are going to manipulate objects in collections by creating business rule objects and attaching them to a class object. To do so, we :
Extending the Metamodel by Script
When you import a file using scripts, you can import as extended attributes or extended collections some properties that may not correspond to standard attributes. In the following example, we:
Creating an Object Selection by Script
Object Selection is a model object that is very useful to select other model objects in order to apply to them a specific treatment. You can for example add some objects to the Object Selection to move them to another package in a unique operation instead of repeating the same operation for each and every objects individually.