How to make a customerized construction tool available only for one feature layer?

2835
4
Jump to solution
06-25-2012 03:25 PM
SuiHuang
Occasional Contributor II
Hi Everybody:

    I am making a customerized feature contructor for a specific feature class. After starting edit, I want it to show up in the Construction Tools only for the template of that feature class (say, it has a unique name). However, the following document of Editor framework customerization doesn't provide this level of control...
http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//0001000002nq000000

The document only tell a way to let the constructor show up for Point feature layers, Polyline feature layers, etc. Is there any trick for me to allow people to see that constructor only for the feature layer with the specific name?

There is an alternative but I don't like it: override the "Enable" property inherited from BaseCommand class to return true if and only if the current template is for the right feature layer. With this approach I can disable the constructor but cannot make it disappear...

Any better idea? Thank you!
0 Kudos
1 Solution

Accepted Solutions
EdgarBejarano
Occasional Contributor
My thought is that you cannot control with which FeatureLayer a custom Construction Tool can be offered in the Construction Tools pane of the Create Features dockable window.  It seems that the only reason why a custom Construction Tool displays is because:

a) that Construction Tool has been registered with a given ESRI Editor Construction Tools component category--e.g. ESRI Editor Point Feature Construction Tools or ESRI Editor Annotation Feature Construction Tools component category--which is determined by the developer in the source code of the construction tool.
b) the enduser has selected a feature template associated with a feature layer whose geometry type corresponds to the geometry type of the editor construction tool.

So if an enduser selects a feature template that is associated with a point feature layer, ArcMap will load all the classes/tools that are registered in the component category called ESRI Editor Point Feature Construction Tools in the Construction Tools pane of the Create Features dockable window.  This is similar to ArcMap loading all the classes/tools that are registered in the component category called ESRI Mx Commands in the Commands tab of the Customize dialog, which one can then drag onto any toolbar.

I think you found a good workaround which is to disable that tool with the Enable property of the BaseCommand class.  That even falls within the expected behavior of all ArcMap tools/commands (built-in or custom) which is for the tool/command to be disabled if the criteria for using it has not been met, e.g. when the Select tool becomes disabled because no feature layers have yet been added to the map.  Such tool would not disappear just because its use does not apply--rather, it becomes disabled.

If for example your construction tool is for using with a point feature layer, is there a specific reason you do not want to offer your custom construction tool with all point feature layers?  Will your "point" construction tool run into some trouble if it is used with a point feature layer that does not have a certain attribute field?  I can only think of the fields being a problem because your "point" construction tool should apply to all point feature layers.

View solution in original post

0 Kudos
4 Replies
EdgarBejarano
Occasional Contributor
My thought is that you cannot control with which FeatureLayer a custom Construction Tool can be offered in the Construction Tools pane of the Create Features dockable window.  It seems that the only reason why a custom Construction Tool displays is because:

a) that Construction Tool has been registered with a given ESRI Editor Construction Tools component category--e.g. ESRI Editor Point Feature Construction Tools or ESRI Editor Annotation Feature Construction Tools component category--which is determined by the developer in the source code of the construction tool.
b) the enduser has selected a feature template associated with a feature layer whose geometry type corresponds to the geometry type of the editor construction tool.

So if an enduser selects a feature template that is associated with a point feature layer, ArcMap will load all the classes/tools that are registered in the component category called ESRI Editor Point Feature Construction Tools in the Construction Tools pane of the Create Features dockable window.  This is similar to ArcMap loading all the classes/tools that are registered in the component category called ESRI Mx Commands in the Commands tab of the Customize dialog, which one can then drag onto any toolbar.

I think you found a good workaround which is to disable that tool with the Enable property of the BaseCommand class.  That even falls within the expected behavior of all ArcMap tools/commands (built-in or custom) which is for the tool/command to be disabled if the criteria for using it has not been met, e.g. when the Select tool becomes disabled because no feature layers have yet been added to the map.  Such tool would not disappear just because its use does not apply--rather, it becomes disabled.

If for example your construction tool is for using with a point feature layer, is there a specific reason you do not want to offer your custom construction tool with all point feature layers?  Will your "point" construction tool run into some trouble if it is used with a point feature layer that does not have a certain attribute field?  I can only think of the fields being a problem because your "point" construction tool should apply to all point feature layers.
0 Kudos
SuiHuang
Occasional Contributor II
Hi edga6340:

    Thank you for your detail information to help me make sure that it is not doable. I need to find some other walkaround.
    The reason why I want to show a point construction tool for only a specific feature layer is that I want to make the construction tool do attribute population and location validation when a point of this layer is created. The logic of calculating attribute values (such as finding the parent feature ID) and verifying locations (such as cannot be too far away from another feature) are specific for the business case, rather than reusable generic logic.
    There are more than 5 such feature layers for me. If I code one point constructor for each layer, then the Construction Tools list will be filled up with non-applicable items to confuse user.
    Since the construction tools cannot be hidden, I will need to use other alternative method to automate attribute population and data verfication on feature creation.
    Thank you!


My thought is that you cannot control with which FeatureLayer a custom Construction Tool can be offered in the Construction Tools pane of the Create Features dockable window.  It seems that the only reason why a custom Construction Tool displays is because:

a) that Construction Tool has been registered with a given ESRI Editor Construction Tools component category--e.g. ESRI Editor Point Feature Construction Tools or ESRI Editor Annotation Feature Construction Tools component category--which is determined by the developer in the source code of the construction tool.
b) the enduser has selected a feature template associated with a feature layer whose geometry type corresponds to the geometry type of the editor construction tool.

So if an enduser selects a feature template that is associated with a point feature layer, ArcMap will load all the classes/tools that are registered in the component category called ESRI Editor Point Feature Construction Tools in the Construction Tools pane of the Create Features dockable window.  This is similar to ArcMap loading all the classes/tools that are registered in the component category called ESRI Mx Commands in the Commands tab of the Customize dialog, which one can then drag onto any toolbar.

I think you found a good workaround which is to disable that tool with the Enable property of the BaseCommand class.  That even falls within the expected behavior of all ArcMap tools/commands (built-in or custom) which is for the tool/command to be disabled if the criteria for using it has not been met, e.g. when the Select tool becomes disabled because no feature layers have yet been added to the map.  Such tool would not disappear just because its use does not apply--rather, it becomes disabled.

If for example your construction tool is for using with a point feature layer, is there a specific reason you do not want to offer your custom construction tool with all point feature layers?  Will your "point" construction tool run into some trouble if it is used with a point feature layer that does not have a certain attribute field?  I can only think of the fields being a problem because your "point" construction tool should apply to all point feature layers.
0 Kudos
EdgarBejarano
Occasional Contributor
[...]
    The reason why I want to show a point construction tool for only a specific feature layer is that I want to make the construction tool do attribute population and location validation when a point of this layer is created. The logic of calculating attribute values (such as finding the parent feature ID) and verifying locations (such as cannot be too far away from another feature) are specific for the business case, rather than reusable generic logic.
    [...]Since the construction tools cannot be hidden, I will need to use other alternative method to automate attribute population and data verfication on feature creation.
    Thank you!


But in addition to wanting to automate attribute writing and data verification, is your construction tool offering a custom way of constructing point features that is different from the built-in ones which are Point and Point at End of Line (for example, our developer sample called "Points along line construction tool" will add a construction tool to that list called Points Along Line)?  If your construction tool is not offering a different, custom way of constructing point features then I would definitely consider a different custom component, such as an Editor Extension or a geodatabase customization, such as a Class Extension or a Workspace Extension.

If your construction tool does offer a different way of constructing point features in addition to automating attribute value writing, perhaps you can combine the custom construction tool with an editor extension with which you can listen for events from IEditEvents, e.g. OnCreateFeature.  But this would still leave you with a construction tool that does not apply to all point feature layers.  However, a construction tool (a class that implements BaseTool, IShapeConstructorTool, ISketchTool) does not need to be added as a Construction Tool, but rather to a toolbar like a regular tool, and a toolbar can be hidden or shown based on whether your editor extension is turned on or off.  But then again, this would still leave you with a tool UI that would still be shown in the toolbar (disabled or enabled).
0 Kudos
SuiHuang
Occasional Contributor II
Hi edga6340:

    Thank you. Yes, seems what you described are the options available for me. Because offering a different way of constructing point geometry will not add a significant value to my application, now I am going with a simple approach: no Construction Tool, no editor extension tool, just use additional event handlers. In the event handler I can check which feature layer is being edit and do the automation.
    Thank you.

But in addition to wanting to automate attribute writing and data verification, is your construction tool offering a custom way of constructing point features that is different from the built-in ones which are Point and Point at End of Line (for example, our developer sample called "Points along line construction tool" will add a construction tool to that list called Points Along Line)?  If your construction tool is not offering a different, custom way of constructing point features then I would definitely consider a different custom component, such as an Editor Extension or a geodatabase customization, such as a Class Extension or a Workspace Extension.

If your construction tool does offer a different way of constructing point features in addition to automating attribute value writing, perhaps you can combine the custom construction tool with an editor extension with which you can listen for events from IEditEvents, e.g. OnCreateFeature.  But this would still leave you with a construction tool that does not apply to all point feature layers.  However, a construction tool (a class that implements BaseTool, IShapeConstructorTool, ISketchTool) does not need to be added as a Construction Tool, but rather to a toolbar like a regular tool, and a toolbar can be hidden or shown based on whether your editor extension is turned on or off.  But then again, this would still leave you with a tool UI that would still be shown in the toolbar (disabled or enabled).
0 Kudos