VB.NET Addin Example

Hi Guys,

i am trying to make a vb.net addin, however, i cant seem to get everything set up right...

I am trying to use this wiki page http://communities.bentley.com/products/microstation/microstation_v8i/w/microstation_v8i_programming_wiki/addin-development-using-vb.net.aspx

Does anyone have any small working example projects?

 

Thanks!

  • To be more specific, i am crashing whenever i load the dll in microstation...

    Imports Bentley.MicroStation.WinForms

    Imports Bentley.Interop.MicroStationDGN

    Imports Bentley.MicroStation

    Imports Bentley.Windowing

    Imports System.Windows.Forms

    Imports System.Runtime.InteropServices

    Imports Bentley.MicroStation.InteropServices

    Namespace TestApp

       <Bentley.MicroStation.AddInAttribute(KeyinTree:="TestAddin.commands.xml", MdlTaskId:="TestAddin")> _

       Public Class TestAddin

           Inherits Bentley.MicroStation.AddIn

           Private Shared s_App As TestAddin

           Sub New(ByVal mdlDesc As System.IntPtr)

               MyBase.New(mdlDesc)

               s_App = Me

           End Sub

           Public Shared Function GetApp() As TestAddin

               GetApp = s_App

           End Function

           Protected Overrides Function run(ByVal cmdLine() As String) As Integer

               run = 0

           End Function

       End Class

       Public Class KeyinCommands

           Public Shared Sub Open(ByVal unparsed As String)

           End Sub

           Public Shared Sub Close(ByVal unparsed As String)

           End Sub

           Public Shared Sub Scan(ByVal unparsed As String)

           End Sub

       End Class

    End Namespace

    <?xml version="1.0" encoding="utf-8" ?>

    <keyinTree xmlns="www.bentley.com/.../keyinTree.xsd">

     <RootkeyinTable ID="root">

       <Keyword SubtableRef="ProjectReviewAppVBID" CommandClass="MacroCommand" CommandWord="TestApp" />

     </RootkeyinTable>

     <SubkeyinTables>

       <keyinTable ID="ProjectReviewAppVBID">

         <Keyword SubtableRef="DialogID" CommandWord="DIALOG" />

         <Keyword SubtableRef="ScanID" CommandWord="Scan" />

       </keyinTable>

       <keyinTable ID="DialogID">

         <Keyword CommandWord="OPEN" />

         <Keyword CommandWord="CLOSE" />

       </keyinTable>

       <keyinTable ID="ScanID">

         <Keyword CommandWord="FILE" />

       </keyinTable>

     </SubkeyinTables>

     <keyinHandlers>

       <keyinHandler keyin="TestApp DIALOG OPEN" Function="TestApp.keyinCommands.Open"/>

       <keyinHandler keyin="TestApp DIALOG CLOSE" Function="TestApp.keyinCommands.Close"/>

       <keyinHandler keyin="TestApp SCAN FILE" Function="TestApp.keyinCommands.Scan"/>

     </keyinHandlers>

    </keyinTree>

    any ideas?

  • Validating TestADDIN AddIn: TestAddin.TestAddin.TestAddin
    TestAddin.commands.xml is well-formed and schema valid against KeyinTree.xsd
    System.InvalidOperationException: There is an error in XML document (2, 2). --->
     System.InvalidOperationException: <keyinTree xmlns='http://www.bentley.com/sche
    mas/1.0/MicroStation/AddIn/keyinTree.xsd'> was not expected.
       at Bentley.MicroStation.XmlObjectModels.CommandTables.XmlSerializationReaderK
    eyinTree.Read8_KeyinTree()
       at Bentley.MicroStation.XmlObjectModels.CommandTables.KeyinTreeSerializer.Des
    erialize(XmlSerializationReader reader)
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, St
    ring encodingStyle, XmlDeserializationEvents events)
       --- End of inner exception stack trace ---
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, St
    ring encodingStyle, XmlDeserializationEvents events)
       at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
       at Bentley.Internal.MicroStation.CommandTables.LoadKeyinTablesFromStream(Stre
    amReader inStream)
       at Bentley.MicroStation.XmlObjectModels.AddInValidator.ValidateSingleAddInTyp
    e(Type addInTypeToValidate, Stream instanceStream)
       at Bentley.MicroStation.XmlObjectModels.AddInValidator.ValidateSingleAddIn(Ty
    pe addInType)
       at Bentley.MicroStation.XmlObjectModels.AddInValidator.ValidateAddInAssembly(
    Boolean verbose, String addInAssemblyName)
       at Bentley.MicroStation.XmlObjectModels.UstnXOM.ValidateAddInAssembly(Boolean
     verbose, String addInAssemblyName)
       at Bentley.MicroStation.XmlObjectModels.UstnXOM.ParseArguments(String[] args)

  • XML Syntax

    The three dots in the second line of your keyin XML file don't look right. That line specifies the URL of the Schema Definition (.xsd) file. I don't believe that three dots in a file path make a valid URL.

    You also need to pay attention to the exact case of each element name in an XML document: capitalisation is important (i.e. This is not the same as this). Try this …

    <?xml version="1.0" encoding="utf-8"?>
    <KeyinTree 
    xmlns="http://www.bentley.com/schemas/1.0/MicroStation/AddIn/KeyinTree.xsd">
      <RootKeyinTable ID="root">
        <Keyword SubtableRef="ProjectReviewAppVBID" CommandClass="MacroCommand" CommandWord="TestApp"/>
      </RootKeyinTable>
      <SubkeyinTables>
          <KeyinTable ID="ProjectReviewAppVBID">
            <Keyword SubtableRef="DialogID" CommandWord="DIALOG"/>
            <Keyword SubtableRef="ScanID" CommandWord="SCAN"/>
          </KeyinTable>
          <KeyinTable ID="DialogID">
            <Keyword CommandWord="OPEN"/>
            <Keyword CommandWord="CLOSE"/>
          </KeyinTable>
          <KeyinTable ID="ScanID">
            <Keyword CommandWord="FILE"/>
        </KeyinTable>
      </SubkeyinTables>
      <KeyinHandlers>
        <KeyinHandler Keyin="TESTAPP DIALOG OPEN" 
                     Function="TestApp.keyinCommands.Open"/>
        <KeyinHandler Keyin="TESTAPP DIALOG CLOSE" 
                     Function="TestApp.keyinCommands.Close"/>
        <KeyinHandler Keyin="TESTAPP SCAN FILE" 
                     Function="TestApp.keyinCommands.Scan"/>
      </KeyinHandlers>
    </KeyinTree>
    

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Attached is a sample that will (with a little work from you) compile in VisualStudio 2005.  You will need to go in to the references and first delete them and save the project.  Next go in and re add the references (and make sure to set copy local to FALSE!).  You will also have to fix the StandardPostBuild.bat file to point to your MicroStation and MicroStationSDK. 

     

    HTH,

     

    iifuzz.zip
  • Hi,

    when i check my keyin dll (compiled in vb.net 2010) by ustnxom I alwaya see error static methor ... not found for kein...

    Below is definitio of keyin and class in VB

     <KeyinHandlers>

       <KeyinHandler Keyin="snggis CreateElement ShowToolbar"

           Function="SNGgis.CreateElements.ShowToolbar"/>

     </KeyinHandlers>

    Namespace SNGgis

       Public Class CreateElements

           Shared Sub ShowToolbar(ByVal unparsed As String)

               Dim tlbDlg As New Toolbar()

               tlbDlg.TopMost = True

               tlbDlg.Show()

               tlbDlg.Focus()

           End Sub

       End Class

    End Namespace

    The same example in C# is ok and looks like this:

    namespace SNGgis

    {

       public class CreateElements

       {

           public static void ShowToolbar(string unparsed)

           {

               ToolBar tlbDlg = new ToolBar();

               tlbDlg.TopMost = true;

               tlbDlg.Show();

               tlbDlg.Focus();

           }

       }

    }

    Where is the bug? How can I implement method for keyin in vb.net?

    Thanks,

    Martin.

  • Did you look at the ifuzz example?  It is complete and has the keyin class as part of the project.  Are you starting from blank?  There is a wizard that you can add to Visual Studio to make getting started easier.  If you have a project and all the sources set up then check the project properties to turn off the default namespace.

    HTH,

  • I looked at ifuzz, but it had the same error with validateaddin. Where could I find the wizard?

  • You will still see the same issue in that you need to set the default namespace in the project properties.  You can get the wizard from the MicroStationSDK look in the examples that are delivered in the VisualStudioWizards directory.  There are also instructions on how to set them up  in the Programmer's Guide.  

    HTH,

  • Hi MKK,

    Compared your code with ifuzz's, I found you missed a Pulbic keyword before Shared keyword. Maybe this is the reason why you code can't work correctly.

    HTH, Yongan