Although the Topobase team may seem to have a god-like prescience anticipating functionality you might need, there may be the odd workflow or function that you feel could be added, improved or enhanced. For those rare occasions, the Topobase API provides a rich environment for customization. This post describes how to augment the functionality of the electric modules. The electric modules differ from other vertical modules in that in addition to a data model, workflows, reports etc. they have the Electric Explorer panel.
The Electric Explorer provides purpose-built functionality to manipulate conductors, ducts, devices etc. for convenience and data consistency.
In this sample, two context menu items are added to the Conductor container. The first merges the geometry of two conductors. Unlike the built in Merge Conductors function, it uses conductors selected in the Conductor container rather than requesting the user to select conductors from the graphics screen. This is useful if you don’t have cross sections displayed on every segment - to be able to pick conductors from.
The second added context menu item operates similar to dragging conductors from the Conductor container onto ducts in the Ducts container. Free standing conductors are assigned to (enclosed in) the ducts, but for this operation the conductor geometry is kept rather than changing it to follow the segment geometry. This provides the ability to have a semi-schematic type of drawing without resorting to a full-blown schematic.
For these menu items, the ‘hook’ into the Topobase system is – as usual – a PlugIn. This DocumentPlugIn monitors the ElectricExplorerDocumentFlyIn waiting for the FlyInInitComplete event. This event is raised after all the configured containers have been initialized. At that point a reference to the Conductor container can be obtained and the new context menu items added.
Adding to the Context menu involves passing an instance of a class to the container's ExtendMenu method. This class must have event handler methods tagged with a FeatureContainerContextMenuItem attribute as shown below. There are similar attributes for tagging New and More menu handlers.
[FeatureContainerContextMenuItem (
"MergeSelectedConductors",
"MergeConductorCaption",
FeatureContainerNames.Conductor,
TBGridViewContextMenuItemState.DelegateToHandler,
DisplayIndex = 200,
GroupName = "21Modify",
ToolTipResourceName = "Merges selected conductors",
IconNameEnum = IconNames.MergeConductors)]
public void MergeSelectedConductors (object sender, MenuItemEventArgs args)
{
...
This attribute has many options which are explained in the help system by pressing F1 in Visual Studio (if you've registered the API help). Of note, the second parameter is the name of a resource in the assembly resources rather than the caption for the menu item directly. This is so the menu item text can be localized by changing the resource associated with the name.
The TBGridViewContextMenuItemState parameter has a number of options that dictate when the menu item should be enabled or disabled. In this case it is set to DelegateToHandler which is slightly more complicated and needs some explanation.
With this option, the handler method is called two ways. The first way is identified when the MenuItemEventArgs.DeclareEnableStatus is set to true. In this case the method should set the MenuItemEventArgs.EnableMenuItem to true or false depending on whether the menu should be enabled or not respectively. The second way is when the method should actually do the work associated with the menu item. For example:
if (args.DeclareEnableStatus)
args.EnableMenuItem = 1 < container.SelectedItems.Count;
else
... (do the needful)
This would enable the menu if there are at least two items selected in the container. Because this test is supposed to execute quickly so that the context menu appears immediately when the user right-clicks, it is best to leave difficult, deep or time consuming criteria tests to when the user clicks the menu item. Of course an error message is required in that case.
Once the user clicks the menu item, the actual work begins. For the Merge Selected Conductors operation, it is relatively straight forward to test if all the selected conductors form a continuous linear path with contiguous end points. If this is the case the new geometry is assigned to the first selected conductor and the others are deleted after any relations to ducts and segments have been redirected.
For the Associate Conductor operation, the operation is much simpler. The original geometry of the conductor is remembered, the out-of-the-box method to move conductors into ducts is called, and then the original geometry is restored.
This demo is available as a ZIP file which you can download using the link below. To build this project, define the environment variable TopobaseClientDirectory to point to the Topobase Client directory and execute the solution file:
C:>set TopobaseClientDirectory=C:\Program Files\Autodesk Topobase Client 2010
C:>ElectricExplorerExtension.sln
Build the solution. Run Topobase client, open an electric workspace and you should see the new menu items when you right click in the conductor container.
AUTODESK DOES NOT GUARANTEE THAT YOU WILL BE ABLE TO SUCCESSFULLY DOWNLOAD OR IMPLEMENT ANY SAMPLE CODE. SAMPLE CODE IS SUBJECT TO CHANGE WITHOUT NOTICE TO YOU.
AUTODESK PROVIDES SAMPLE CODE "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. IN NO EVENT SHALL AUTODESK OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS
OF DATA, OR LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, THAT MAY OCCUR AS A RESULT OF IMPLEMENTING OR USING ANY SAMPLE CODE, EVEN IF AUTODESK OR ITS SUPPLIERS
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.