CorelDRAW Community
CorelDRAW Community
  • Site
  • User
  • Site
  • Search
  • User
Wikis
Wikis
How-to and Tips&Tricks How to create a menu or a button for your macro with XML in CorelDRAW X5 automatically
  • Wikis
  • Tags
  • More
  • Cancel
  • New
  • The Clone Tool
  • +Corel DRAW: Halftone
  • +Corel PHOTO-PAINT
  • Corel PHOTO-PAINT for Adobe PhotoShop users
  • +CorelDRAW
  • CorelDRAW for Adobe Illustrator users
  • +CorelDRAW.com
  • Designer's Guide to Color Management
  • Exporting ai files from CDX6 to Adobe InDesign CS6 - not working!
  • GDG Macros VBA Lessons
  • +Hidden Gems, Keyboard Tricks in CorelDRAW Graphics Suite
  • +How to show Thumbnail Preview
  • +Making flag in CD/PP by Jesus Cota
  • MANUAL FLATTENING
  • Mesh fill tool structure on circular shapes
  • Selection Groups
  • SHEKHAR
  • Soft Bevel Macro for CorelDRAW
  • Thumbnails Everywhere
  • Troubleshooting - Computer says No
  • +USING PHOTOSHOP AS A BITMAP EDITOR FOR COREL DRAW
  • -VBA
    • Getting Started in VBA
    • getting-started
    • How do I make a macro easily accessible
    • How to create a menu or a button for your macro with XML in CorelDRAW X5 automatically
    • how-do-i-make-a-macro-easily-accessible
    • What is VBA
    • Where can I find exisiting Macros?
  • Vetorizar
  • +Water Effect by Jesus Cota

How to create a menu or a button for your macro with XML in CorelDRAW X5 automatically

First what we have to know is:

  1. Before a starting the process we have to make an backup the file: \Users\LOGIN_NAME\AppData\Roaming\Corel\CorelDRAW Graphics Suite X5\Draw\Workspace\YOUR_WORKSPACE_NAME\DRAWUIConfig.xml
  2. The best way test your files is use default UI.
  3. If you had changes in files and no changes in UI after the program is restarted, just delete the (test) UI file and run app again.
  4. For your new items you have to create a new ID (guidRef). You can create them on http://www.guidgenerator.com/ for example

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:

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

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)

  • VBA
  • xslt
  • Macros
  • Share
  • History
  • More
  • Cancel
Related
Recommended

© Corel Corporation. All rights reserved. The content herein is in the form of a personal web log ("Blog") or forum posting. As such, the views expressed in this site are those of the participants and do not necessarily reflect the views of Corel Corporation, or its affiliates and their respective officers, directors, employees and agents. Terms of Use / Privacy​ ​/ ​Cookies / Terms and Conditions / User Guidelines.