Creating an XML File Add-in

You can create your own menu items in PowerDesigner menus by using an XML file.

Note: To use your add-in, save it to the Add-ins directory beneath your PowerDesigner installation directory and enable it through the PowerDesigner General Options window (see Core Features Guide > The PowerDesigner Interface > Customizing Your Modeling Environment > General Options > Managing Add-Ins).

The following illustration helps you understand the XML file structure:



The Profile is the root element of the XML file add-in descriptor. It contains the following parts:

<!ELEMENT Profile ((Shared)?, (Metaclass)*)>.

Shared

The Shared element defines the menus that are always available and their associated methods (Menus, and Methods elements) and the shared methods (GlobalScript attribute).

The GlobalScript attribute is used to specify an optional global script (VBS) that can contain shared functions.

The Menus element contains menus that are always available for the application. A Location can be specified to define the menu location. It can take the following values:

  • FileImport

  • File reverse

  • Tools

  • Help

You can only define one menu per location.

The Methods defines the methods used in the menus described in the Menus element and that are available for the application.

Metaclass

The Metaclass element is used to specify menus that are available for a specific PowerDesigner metaclass. A metaclass is identified by a name. You must use the public name.

The Menus element contains menus available for a metaclass.

The Menu element describes a menu available for a metaclass. It contains a series of commands, separators or popups. A location can be specified to define the menu location. It can take the following values:

  • FileExport

  • Tools

  • Help

  • Object

Object is the default value for the Location attribute.

The Methods element contains a series of method available for a metaclass.

The Method element defines a method. A method is identified by a name and a VB script.

The Command element defines a command menu item. Its name must be equal to the name of a Method in order to be implemented.

The Popup element defines a sub-menu item that may contain commands, separators or popups.

The Caption is the displayed value in the menu.

A separator indicates that you want to insert a line in the menu.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<Profile>
	<Metaclass Name="PdOOM.Model">
	<Menus>
	<Menu Location="Tools">
		<Popup Caption="Perforce">
			<Command Name="CheckIn" Caption="Check In"/>
			<Separator/>
			<Command Name="CheckOut" Caption="Check Out"/>
		</Popup>
	</Menu>
	</Menus>
	<Methods>
		<Method Name="CheckIn">
Sub %Method%(obj)
execute_command( p4, submit %Filename%, cmd_PipeOutput)
End Sub
		</Method>
		<Method Name="CheckOut">
Sub %Method%(obj)
execute_command( p4, edit %Filename%, cmd_PipeOutput)
End Sub
		</Method>
	</Methods>
</Metaclass>
</Profile>

A method defined under a metaclass is supposed to have the current object as parameter; its name is calculated from the attribute name of the method tag.

Example:

<Method Name="ToInt" >
Sub %Method%(obj)
 Print obj
 ExecuteCommand(&quot;%MORPHEUS%\ToInt.vbs&quot;, &quot;&quot;, cmd_InternalScript)
End Sub

Each metaclass name must be prefixed by its Type Library public name like PdOOM.Class.

Inheritance is taken into account: a menu defined on the metaclass PdCommon.NamedObject will be available for a PdOOM.Class.

You can only define one menu for a given location. If you define several locations only the last one will be preserved.

Menus defined in the Shared section can refer to "FileImport" "Reverse" and "Help" locations.

These menus can only refer to method defined under Shared and no object is put in parameter in the methods defined under Shared.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<Profile>
	<Shared>
	<GlobalScript>
Option Explicit
Function Print (obj)
Output obj.classname &amp; &quot; &quot; &amp; obj.name
End Function
	/GlobalScript>
	</Shared>
	<Metaclass Name="PdOOM.Class">
	<Menus>
	<Menu>
		<Popup Caption="Transformation">
			<Command Name="ToInt" Caption="Convert to interface"/>
			<Separator/>
		</Popup>
	</Menu>
	</Menus>
	<Methods>
		<Method Name="ToInt" >
Sub %Method%(obj)
 Print obj
 ExecuteCommand(&quot;%MORPHEUS%\ToInt.vbs&quot;, &quot;&quot;, cmd_InternalScript)
End Sub
		</Method>
	</Methods>
	</Metaclass>
</Profile>

You can find the DTD in the Add-ins folder of the PowerDesigner directory.

Note: You can retrieve in this example the same syntax used in the creation of a menu using a resource file.

Note: You can use the interface of the resource editor to visualize in the XML page the syntax of a menu you created in the Menu page that will help you construct the same XML syntax.