AnsweredAssumed Answered

Open Document in VB.Net

Question asked by James Gannatal on Sep 16, 2011
Latest reply on Sep 16, 2011 by Wayne Matus

I am trying to open a part file using a button in a userform in VB.Net.  I normally code in VBA and know how to accomplish this but I just cant seem to figure it out in VB.Net. I created a simple program that would demonstrate this process and attached it below.  Might just be a friday thing but any help would be appreciated.

 

 

Module:

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System

 

Partial Class SolidWorksMacro

 

    Public Sub main()

 

        Dim swDoc As ModelDoc2 = Nothing

        Dim swPart As PartDoc = Nothing

        Dim swDrawing As DrawingDoc = Nothing

        Dim swAssembly As AssemblyDoc = Nothing

        Dim boolstatus As Boolean = False

        Dim longstatus As Integer = 0

        Dim longwarnings As Integer = 0

      

        Dim form1 As New Form1

        form1.ShowDialog()

       'swDoc = CType(swApp.OpenDoc6("C:\Users\jamesg.METRAFLEX\Desktop\Block.SLDPRT", 1, 0, "", longstatus, longwarnings), ModelDoc2)

        'swApp.ActivateDoc2("Block.SLDPRT", False, longstatus)

        'swDoc = CType(swApp.ActiveDoc, ModelDoc2)

        'swDoc = CType(swApp.ActiveDoc, ModelDoc2)

    End Sub

    ''' <summary>

    ''' The SldWorks swApp variable is pre-assigned for you.

    ''' </summary>

    Public swApp As SldWorks

 

 

End Class

 

Form:

 

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System

 

Public Class Form1

   Public swApp As SldWorks

    Dim swDoc As ModelDoc2 = Nothing

    Dim swPart As PartDoc = Nothing

    Dim swDrawing As DrawingDoc = Nothing

    Dim swAssembly As AssemblyDoc = Nothing

    Dim boolstatus As Boolean = False

    Dim longstatus As Integer = 0

    Dim longwarnings As Integer = 0

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        swDoc = CType(swApp.OpenDoc6("C:\Users\jamesg.METRAFLEX\Desktop\Block.SLDPRT", 1, 0, "", longstatus, longwarnings), ModelDoc2)

        swApp.ActivateDoc2("Block.SLDPRT", False, longstatus)

        swDoc = CType(swApp.ActiveDoc, ModelDoc2)

        swDoc = CType(swApp.ActiveDoc, ModelDoc2)

 

    End Sub

End Class

Attachments

Outcomes