Need help with Addin presentation from SW World 2007 - Or Addinstutorials in general

Discussion in 'SolidWorks' started by solidworks311, May 9, 2008.

  1. I'm reviewing a SW World 2007 presentation I attended titled
    "SolidWorks Addins Using .NET".

    The steps are:

    1. Record a simple macro in SolidWorks using VBA.
    2. Verify the macro.
    3. Start Visual Studio.
    4. Create a new SW Addin using SWVBAddin Template.
    5. Open SwAddin.vb
    6. Expand the code region.
    7. Select all of the code in 'Sub CreateCube ()'
    8. Use Ctrl+K C to comment out the code
    9. Swith back to VBA and select all the code in 'Sub main ()'
    10. Copy and paste back to Visual Studio.
    11. Add 'Dim' statements for each object.
    12. Replace 'Applications.SldWorks' with 'GetObject
    (,"SldWorks.Application")'
    13. Build the Addin and Run using F5 to debug SolidWorks.

    I followed all of the steps, but nothing happens in SolidWorks. The
    macro works fine if I run it thru VBA.

    Any ideas? If anyone knows a good tutorial for creating SW Addins
    with VB.NET, please post.

    Below is the code under 'UI Callbacks'


    #Region "UI Callbacks"

    Sub main()
    Dim swApp As Object
    Dim Part As Object
    Dim SelMgr As Object
    Dim boolstatus As Boolean
    Dim longstatus As Long, longwarnings As Long
    Dim Feature As Object
    swApp = GetObject(, "SldWorks.Application")

    Part = SwApp.ActiveDoc
    SelMgr = Part.SelectionManager
    boolstatus = Part.SetUserPreferenceToggle(196, True)
    boolstatus = Part.Extension.SelectByID2("Unknown", "BROWSERITEM", 0,
    0, 0, False, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("Front", "PLANE", 0, 0, 0,
    False, 0, Nothing, 0)
    Part.SketchManager.InsertSketch(True)
    Part.ClearSelection2(True)
    Part.SketchRectangle(-0.08407285067873, 0.06711078431373, 0,
    0.06953393665158, -0.05404683257919, 0, 1)
    Part.SetLineWidth(4)
    Part.SetLineWidth(4)
    Part.SetLineWidth(4)
    Part.SetLineWidth(4)
    Part.SetPickMode()
    Part.ClearSelection2(True)
    Part.SketchManager.InsertSketch(True)
    Part.ClearSelection2(True)
    End Sub
     
    solidworks311, May 9, 2008
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.