2012-07-17 3 views
0

매우 비슷합니다. Solidworks API and Winforms C# swApp (Standalone) 그러나 내 응용 프로그램에서 솔루션을 얻는 것 같지 않습니다. 나는 실행되는 새로운 그림을 만드는 Macro를 만들었지 만, 두 개의 단추가있는 winform을 얻었습니다. 하나의 단추는 다른 매크로를 수행하고 다른 단추는 다른 것을 수행합니다. 버튼이 작동하지 않는 것 같습니다.Solidworks API 및 WinForms VB.NET swApp

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 

    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 
    swDoc = CType(swApp.ActiveDoc, ModelDoc2) 
    swDoc.ClearSelection2(True) 
    Dim skSegment As SketchSegment 
    skSegment = CType(swDoc.SketchManager.CreateLine(-0.053838, 0.028482, 0, -0.003395, -0.060241, 0), SketchSegment) 
    skSegment = CType(swDoc.SketchManager.CreateLine(-0.003395, -0.060241, 0, 0., 0.028482, 0), SketchSegment) 
    skSegment = CType(swDoc.SketchManager.CreateLine(0., 0.028482, 0, 0.09885, -0.060241, 0), SketchSegment) 
    swDoc.ClearSelection2(True) 

End Sub 
Public swApp As SldWorks 

나는 =에서는 CType (swApp 라인 swDoc에 null 참조 예외가 계속 등을 사전에

감사

답변

0
Dim swApp As SldWorks 
    swApp = Nothing 
    Try 
     swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks) 
    Catch ex As Exception 
     MsgBox(ex.Message) 
     Exit Sub 
    End Try