SDK:Parametric Custom Context Menu

From Vectorworks Developer
Jump to: navigation, search

.SDK|SDK ..SDK:Types|SDK Types ..SDK:Using the SDK|Using the SDK ..VCOM:VCOM (Vectorworks Component Object Model)|VCOM Basics ..VCOM:Class Reference|VCOM Class Reference

By Vladislav Stanev

What's that

The parametric objects can modify the context menu -- the menu that appears on right-click on the object instance in the drawing.

The Custom Context Menu is addition to the context menu that is created by VectorWorks for that object. The Custom Context menu is defined for the parametric type from the plug-in, and is the same of all instances of that parametric type.

Setting up

To enable "Custom Context Menu" for that parametric type your parametric plug-in should have SDK:Parametric Extended Properties enabled through the resources Enabling Extended Properties.

Then you need to handle the kObjOnInitXProperties event inside your SDK:Plug-in Object Main Function.

The plug-in must setup the extended properties and enable "Custom Context Menu". To do that you have to set the following extended properties: kObjXPropHasContextMenu

Note that the extended properties are manipulated though a VCOM (VectorWorks Component Object Model) interface IExtendedProps part of Category:VCOM:VectorWorks:PluginSupport.

case kObjOnInitXProperties: {
  // obtain the interfact for accessing the extended properties
  using namespace VectorWorks::PluginSupport;
  VCOMPtr<IExtendedProps>	pExtProps( IID_ExtendedProps );

  // Enable Custom Menu Command
  pExtProps->SetObjectProperty(objectID, kObjXPropHasContextMenu, true);

Creating the Custom Context Menu

When the user right-clicks on Custom Context Menu enabled plug-in, VectorWorks sends out kObjOnContextMenuInit event to let the plug-in construct the Custom Context Menu.

Note The Custom Context Menu items get merget with the context menu that VectorWorks provides.

case kObjOnContextMenuInit: {
    const ObjectContextMenuEvent* pEventData           = (const ObjectContextMenuEvent*) message;
    IContextMenuProvider*         pContextMenuProvider = (pEventData && pEventData->fData)
                                                   ? (IContextMenuProvider*) pEventData->fData : NULL;
    if ( pContextMenuProvider ) {
        pContextMenuProvider->AddItem( "Item 1" );
        pContextMenuProvider->AddItem( "Item 2" );
        pContextMenuProvider->AddItem( "Item 3" );


The plug-in builds the context menu, using interface:

class IContextMenuProvider
// Context menu provider interface for parametric objects
    virtual Sint16  AddItemSeparator() = 0;
    virtual Sint16  AddItem(const TXString& text) = 0;
    virtual bool    AddItem(const TXString& text, IContextMenuProvider*& outSubMenuProvider) = 0;
    virtual void    EnableItem(Sint16 itemID, bool bEnable) = 0;
    virtual void    CheckItem(Sint16 itemID, bool bChecked) = 0;

Custom Menu Item Select

When the user selects an item from the Custom Context Menu, VectorWorks sends out kObjOnContextMenuEvent event to allow the plug-in to handle it correctly:

case kObjOnContextMenuEvent: {
    const ObjectContextMenuEvent* pEventData    = (const ObjectContextMenuEvent*) message;
    if ( pEventData ) {
        TXString    msg;
        msg.Format( "Menu id=%d", pEventData->fActiveMenuID );
        gSDK->AlertInform( msg );



The sample Custom Context Menu looks like this:

Note The Custom Context Menu items get merget with the context menu that VectorWorks provides.

Custom Context Menu Sample

See also

SDK:Plug-in Object Events | SDK:Parametric Object Plug-in

Personal tools

Advanced Search
See Also