非常相似 Solidworks API and Winforms C# swApp (Standalone) 但我似乎无法在我的应用程序上运行解决方案。我创建了一个宏来创建一个运行的新绘图,然而你得到一个有两个按钮的winform,一个按钮执行另一个宏而另一个执行不同的宏。我似乎无法让按钮工作。
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.012312, 0.028482, 0), SketchSegment)
skSegment = CType(swDoc.SketchManager.CreateLine(0.012312, 0.028482, 0, 0.09885, -0.060241, 0), SketchSegment)
swDoc.ClearSelection2(True)
End Sub
Public swApp As SldWorks
我一直在swDoc = CType(swApp etc
)行上得到一个空引用异常提前致谢
答案 0 :(得分: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