First what we have to know is:
Lets start :)
Create a new folder (for example 'MyNewCoolMacro') in Program Files (x86)\Corel\CorelDRAW Graphics Suite X5\Programs\Addons. In the new folder, create a new empty text file 'coreldrw.addon'. This will tell Draw that your add-on will be loaded by CorelDRAW.
Now need to create other new text file in UTF-8 (without signature) with the name 'AppUI.xslt'. We define our items inside this file. Add the following code:
<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:frmwrk="Corel Framework Data"><xsl:output method="xml" encoding="UTF-8" indent="yes"/><frmwrk:uiconfig><frmwrk:applicationInfo userConfiguration="true" /></frmwrk:uiconfig>
<xsl:template match="node()|@*"><xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy></xsl:template>
<xsl:template match="uiConfig/items"><xsl:copy><xsl:apply-templates select="node()|@*"/>Here we have to define our items and menu which we want.</xsl:copy></xsl:template>
<xsl:template match="uiConfig/commandBars"><xsl:copy><xsl:apply-templates select="node()|@*"/>And here we have to define how it will be in UI.</xsl:copy></xsl:template>
</xsl:stylesheet>
As you can see, we have two places where we have to add our code. In the first place we have to define items what we need. For example we can define buttons or menus here.
In next sample code I create a fly out menu where I will collect my buttons.
<itemData guid="9387393f-8a16-4ee5-9ef5-ef9f4f8eb5b9" flyoutBarRef="919643bf-a3a6-46b7-9544-8aebbf4263a3"userCreated="true"noBmpOnMenu="true"userToolTip="CdrPreflight"userCaption="CdrPreflight"/>
To define a button you must write this code:
<itemData guid="df8e36f9-f0e4-4159-9df8-85addc5ddb6f" dynamicCommand="CdrPreflight.cp_Info.CdrPreflight_start" dynamicCategory="2cc24a3e-fe24-4708-9a74-9c75406eebcd" userCaption="CdrPreflight" userToolTip="CdrPreflight"></itemData>
DinamicCommand is a command which can call your macro by using the format: NameOfMacro.NameOfModule.NameOfSub. DynamicCategory ID "2cc24a3e-fe24-4708-9a74-9c75406eebcd" will place the button in customization under VBA Macro UI category.
And now is time to create a menu and place our new button in it.
<commandBarData guid="919643bf-a3a6-46b7-9544-8aebbf4263a3" type="menu" nonLocalizableName="CdrPreflight" flyout="true"><container><item guidRef="df8e36f9-f0e4-4159-9df8-85addc5ddb6f"/></container></commandBarData>
Above we’ve create a menu with the name ‘CdrPreflight’, which contains one menu item.
Next, you have to create a new text file with name 'UserDraw.xslt' in UTF-8 (without signature).
In this file you tell the CorelDRAW where you want to add your menu or a macro button. Add following code in the file.
<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:frmwrk="Corel Framework Data"><xsl:output method="xml" encoding="UTF-8" indent="yes"/>
The following code defines which command bar you want add your items into.
<frmwrk:uiconfig><frmwrk:applicationInfo name="CorelDRAW" framework="CorelDRAW" userConfiguration="true" /><frmwrk:compositeNode xPath="/uiConfig/commandBars/commandBarData[@guid='f3016f3c-2847-4557-b61a-a2d05319cf18']"/><frmwrk:compositeNode xPath="/uiConfig/frame"/></frmwrk:uiconfig>
Guid 'f3016f3c-2847-4557-b61a-a2d05319cf18' is Menu Bar. So, as you understand, we want to add our item in standard Menu Bar.
The xslt file is a transform which runs on the main UI configuration file, we need to first copy over all of the existing UI. Add the following code to do this:
Now is time to show to CorelDRAW where in the Menu Bar you want to add your item(s).
<xsl:template match="uiConfig/commandBars/commandBarData[@guid='f3016f3c-2847-4557-b61a-a2d05319cf18']/container/container[@modeID='76d73481-9076-44c9-821c-52de9408cce2']/item[@guidRef='6c91d5ab-d648-4364-96fb-3e71bcfaf70d']"><xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy><item guidRef="9387393f-8a16-4ee5-9ef5-ef9f4f8eb5b9"/></xsl:template></xsl:stylesheet>
As you see we again have to write a path for Menu Bar, but now we add an exact path. The @modeID='76d73481-9076-44c9-821c-52de9408cce2' mean the full mode of Menu Bar (when any document is opened) and the @guidRef='6c91d5ab-d648-4364-96fb-3e71bcfaf70d' mean Window menu. This means we want to add our items exactly after Window menu in Menu Bar.
Note: all of these ids I found in Program Files (x86)\Corel\CorelDRAW Graphics Suite X5\Draw\UIConfig\DrawUI.xml.
BUT don't make any changes in this file!!!
The line <item guidRef="9387393f-8a16-4ee5-9ef5-ef9f4f8eb5b9"/> is the item we want to add. In this sample I added my fly out menu which I created in AppUI.xslt file.
In the this file you will find working sample.
p.s. Thanks to Hendrik for help :)
Regards,Sancho (cdrpro.ru)