Visual Components' Community

New Thinking for Factory Simulation
Welcome to Visual Components' Community Sign in | Help
in Search

Visual Basic: Your first COM application in Visual Studio

Last post ke, loka 22 2008 5:11 by leonarul. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • pe, elo 15 2008 15:14

    • Janne
    • Top 10 Contributor
    • Joined on pe, helmi 22 2008
    • Visual Components HQ
    • Posts 21

    Visual Basic: Your first COM application in Visual Studio

    Lets start simple. Open 3DCreate and drop a few components form the eCat to the layout (make sure you have only one session open). Set up a new Visual Basic Console Application project (see Setting Up). After setup go to the module1.vb Tab, which should be the default name of your code, and you will notice the tab is pre-filled with:

    Module Module1

    Sub Main()

    End Sub

    End Module

    The code will go between the Sub Main() and End Sub statement. For brevity fo reading i will be omitting showing the entire code until very last, and all of the code spinets are assumed to be after the Sub Main(). The first thing you need to do is to connect up to the visual components application. For this we need to open up a com connection. To do this fill in:

    Dim vcApp As vcCOM.IvcApplication
    vcApp = New vc3DCreate.vcc3DCreate

    This creates a variable of type and IvcApplication and fills it with a handle to the open 3dCreate session. This gives you a object that can access all the things in the manual under COM Reference->Base COM API->IvcApplication. If you would have wanted to use IvcApplication2 you would just have said so and the object would have been casted to appropriate. Next let's do something moderately useful lets list each item in the scene and print its name out to the sytem console.

    For i = 0 To vcApp.ComponentCount - 1  
    System.Console.Out.WriteLine(vcApp.getComponent(i).getProperty("Name"))
    Next

    Now we are done, all that remains is to execute the code. To do so hit F5, you may notice that something happens very fast. That's okay it's supposed to be fast, it would however be nice if we had time to react, and we can instruct the code to stop at a certain place. Move the cursor to the line End Sub and press F9 this creates a ball on the left, this is a break point. A break point instructs the code to wait for user input mid run (see Debugging COM). If you now hit F5 a new window opens with a list of all component names.

    And the final Complete code:

    Module Module1

    Sub Main()
    Dim vcApp As vcCOM.IvcApplication
    vcApp = New vc3DCreate.vcc3DCreate
    For i = 0 To vcApp.ComponentCount -1
    System.Console.Out.WriteLine(vcApp.getComponent(i).getProperty("Name"))
    Next
    End Sub

    End Module
  • ke, loka 22 2008 5:11 In reply to

    Re: Visual Basic: Your first COM application in Visual Studio

    Thanks you for the post.This is really helpfull.gracias!:))

    "ENGINEERING THE NEXT BREAKTHRU"
Page 1 of 1 (2 items)