It's possible to create my own VBA project and use CustemHooks

Hello,

I have two questions:

1. I try to create new VBA Project in BUD which use  XfmStdUtilCustomization.ICustemHook just like x.p. XfmStdElecLib


When edit Configuration file and change "CustomPlacementLib" property on one feature to notify my project when proess this feature.


Unfortunately when I Place or edit this feature nothing is happened.

Any ideas why didn't worked?

2.  It is possible to implement  XfmStdUtilCustomization.ICustemHook in .Net AddIn?

Thanks.

 

I try to create new VBA Project in BUD which use  XfmStdUtilCustomization.ICustemHook just like x.p. XfmStdElecLib


When edit Configuration file and change "CustomPlacementLib" property on one feature to notify my project when proess this feature.


Unfortunately when I Place or edit this feature nothing is happened.

Any ideas why didn't worked?

Parents
  • Hello Nikolay,

    Can you show the code you attempted to execute or explain what change you are attempting to make to features? Please state both the pre-conditions and post-conditions that are expected.

    The code you write can be written in a .NET language. If the custom code is a response to a hook event, the code should be exposed to COM and called from the MVBA custom hooks.

    Thanks,
    Alfredo Contreras, PM

       
    This is a test

  • One additional thing to check is that your new MVBA project exposes a method called InitializeCustomPlacement and that it is included in the list of Custom libraries in the "CustomPlacementLibs" property in the "Properties" section, not just in the feature section. That method just creates an instance of your new class and adds it to the singleton. You should be able to use the examples to see what it does, just remember to change the name that it uses to add to the singleton.
    Thanks,
    Mike


    This is a test

    Answer Verified By: Nikolay Tsonev 

  • Thanks Mike


    I didn't saw CustomPlacementLibs Property because I searched in Model Administrator MA_ConfigurationSetting sheet, but they are in Base fail.


    So now its work!!!


    I have one more question can I do the same thing, but with  .NET AddIn?

  • Hi Nicolay,
    Yes you can do this in a .NET dll. It will have to expose the XfmStdUtilCustomization.ICustomHook COM interface. The only tricky part is that you will have to instantiate an instance of your class, and then add it to the singleton (as the macro InitializeCustomPlacement is doing). The name you add it to the singleton with is the same as in the CustomPlacementLib property on the feature.
    Hope that helps,
    Mike


    This is a test

  • Hi Mike,

    I try with XfmStdUtilCustomization._CustemHook interface *** is already exposed and I instantiate my class and added to Singleton

    class XfmStdCustemHook : _CustomHook

    {

    public int CanDeleteHook(string Context, feature oFeature, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int ExtendedTraceFunctionality(string TraceType, string NetworkName, ref feature oStartFeature, ref NetworkResult NetResult, ref network Network)

    {

    throw new NotImplementedException();

    }

    public int ExtendedTraceFunctionalityEnabled(string TraceType, string NetworkName, ref feature oStartFeature, ref NetworkResult NetResult, ref bool bEnabled)

    {

    throw new NotImplementedException();

    }

    public string GetFeaturePropertyHook(feature oFeature, string propertyname, string PropertyValue)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemCloseHook(string Context, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemElementMovedHook(string Context, string model, int elmID, double x, double y, double z, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemLeftClickHook(string Context, ref string uuid, string model, int lowElmID, int highElmID, double mouseX, double mouseY, double modelX, double modelY, double modelZ, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemLeftDblClickHook(string Context, ref string uuid, string model, int lowElmID, int highElmID, double mouseX, double mouseY, double modelX, double modelY, double modelZ, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemOpenHook(string Context, feature Feature, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemRightClickHook(string Context, ref string uuid, string model, int lowElmID, int highElmID, double mouseX, double mouseY, double modelX, double modelY, double modelZ, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemRightDblClickHook(string Context, ref string uuid, string model, int lowElmID, int highElmID, double mouseX, double mouseY, double modelX, double modelY, double modelZ, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemSetVariableHook(string Context, string Name, string Value, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int GraphicItemUpdateHook(string Context, feature Feature, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int NumberOfChildrenHook(string Context, feature oParentFeature, ref object[] ChildFeatures, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostConnectHook(string Context, string NetworkName, ref feature oSourceFeature, ref feature oTargetFeature, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostCreateParentAssociationHook(string Context, feature oChildFeature, feature oParentFeature, short AssociationType, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostCreatePeerAssociationHook(string Context, feature oFeature1, feature oFeature2, short AssociationType, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostDeleteHook(string Context, ref feature oFeature, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostDeleteParentAssociationHook(string Context, feature oChildFeature, feature oParentFeature, short AssociationType, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostDeletePeerAssociationHook(string Context, feature oFeature1, feature oFeature2, short AssociationType, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostDisconnectHook(string Context, string NetworkName, ref feature oTargetFeature, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostInsertHook(string Context, ref feature oFeature, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostJoinHook(string Context, double SplitCoordX, double SplitCoordY, double SplitCoordZ, ref feature oUpstreamFeature, ref feature oDownstreamFeature, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostMoveGeometryHook(string Context, ref feature oFeature, Element oPreviousGeometry, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostSplitHook(string Context, double SplitCoordX, double SplitCoordY, double SplitCoordZ, ref feature oUpstreamFeature, ref feature oDownstreamFeature, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PostTraceHook(string TraceType, string NetworkName, ref feature oStartFeature, ref NetworkResult NetResult)

    {

    throw new NotImplementedException();

    }

    public int PostUpdateHook(string Context, ref feature oFeature, PropertyEnumerator oPreviousProp, Element oPreviousGeometry, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreConnectHook(string Context, string NetworkName, ref feature oSourceFeature, ref feature oTargetFeature, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreCreateParentAssociationHook(string Context, feature oChildFeature, feature oParentFeature, short AssociationType, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreCreatePeerAssociationHook(string Context, feature oFeature1, feature oFeature2, short AssociationType, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreDeleteHook(string Context, ref feature oFeature, ref bool bCancel, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreDeleteParentAssociationHook(string Context, feature oChildFeature, feature oParentFeature, short AssociationType, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreDeletePeerAssociationHook(string Context, feature oFeature1, feature oFeature2, short AssociationType, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreDisconnectHook(string Context, string NetworkName, ref feature oTargetFeature, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreInsertHook(string Context, ref feature oFeature, ref PropertyEnumerator oProposedProp, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreJoinHook(string Context, ref double SplitCoordX, ref double SplitCoordY, ref double SplitCoordZ, ref feature oUpstreamFeature, ref feature oDownstreamFeature, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreMoveGeometryHook(string Context, ref feature oFeature, ref Element oProposedGeometry, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreSplitHook(string Context, ref feature oFeature, ref double SplitCoordX, ref double SplitCoordY, ref double SplitCoordZ, ref bool Validation, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int PreTraceHook(string TraceType, string NetworkName, ref feature oStartFeature, ref XPathQueryDef oXPathQuery)

    {

    throw new NotImplementedException();

    }

    public int PreUpdateHook(string Context, ref feature oFeature, ref object oProposedProp, ref bool bCancel, ref string Message)

    {

    throw new NotImplementedException();

    }

    public int TreeSelChangedHook(string Context, ref int elmId, ref feature oParentFeature, ref feature oChildFeature, ref string Message)

    {

    throw new NotImplementedException();

    }

    }


    And this is my Run method

    IXfmStdUtilSingletonMap ASingleton = new XfmStdUtilSingletonMap();

    object m_CustomizationClass = new XfmStdCustemHook();

    ASingleton.Set_SingletonObject("TestCustomPlacementCmds", ref m_CustomizationClass);


    When I test only GetFeaturePropertyHook method s called.

     

    Thanks

     

  • Hi Nikolay,
    I'm not sure why only a single method would be called. GetFeaturePropertyHook is called whenever we access the configuration information, so it tends to be the first method called. Perhaps it is just erroring on this method before you get to the other calls?
    Thanks,
    Mike


    This is a test

Reply Children
  • Hi Mike,

    I played some days with that how to add my custemhook instance in Singleton in .NET and I have success.

    In the beginning I tried to add my object in Singleton after the BUISMdlWrapper initialized. when I put my keyin command (CadInputQueue.SendKeyin "mdl load addintestapp" ) in Sub InitializeCustomPlacement()  in any of exiting VBA Projects everything  is work fine.

    The reason maybe is that Microstation try to execute  (vba run TestCustomPlacementCmds.InitializeCustomPlacement) but my instance is in .NET Addin.


    This is my output before I add  keyin command (CadInputQueue.SendKeyin "mdl load addintestapp" ) in Sub InitializeCustomPlacement() 

    *************Added BEConn to Wrapper

    *************Added XFMAssociations to Wrapper

    vba run ElectricCustomPlacementCmds.InitializeCustomPlacement

    vba run GasCustomPlacementCmds.InitializeCustomPlacement

    vba run WaterCustomPlacementCmds.InitializeCustomPlacement

    vba run WasteWaterCustomPlacementCmds.InitializeCustomPlacement

    vba run CommonCustomPlacementCmds.InitializeCustomPlacement

    vba run TestCustomPlacementCmds.InitializeCustomPlacement

    Failed to initialize the Customization Dictionary, Name = TestCustomPlacementCmds. No Custom behavior will be available during this session. The VBA projects and references may be invalid, or the CustomPlacementLibs setting in BentleyUtilityConfiguration.xml may be incorrect.

    InitializeBUISMdlWrapper


    And after:

    The string 3 is 3 as double.

    *************Added BEConn to Wrapper

    *************Added XFMAssociations to Wrapper

    vba run ElectricCustomPlacementCmds.InitializeCustomPlacement

    vba run GasCustomPlacementCmds.InitializeCustomPlacement

    vba run WaterCustomPlacementCmds.InitializeCustomPlacement

    vba run WasteWaterCustomPlacementCmds.InitializeCustomPlacement

    vba run CommonCustomPlacementCmds.InitializeCustomPlacement

    'UtilitiesDesigner.exe' (CLR v2.0.50727: DefaultDomain): Loaded 'C:\Program Files (x86)\Bentley\UtilitiesDesigner V8i\UtilitiesDesigner\mdlapps\addintestapp.dll'. Symbols loaded.

    vba run TestCustomPlacementCmds.InitializeCustomPlacement

    InitializeBUISMdlWrapper


    Thanks.