1

非常感谢谁能花几分钟时间来帮助我,所以在此先感谢!

让自己陷入运行宏的情况VSTA works (vb.net),但从solidworks运行dll文件不起作用。可能忘记了一些非常简单的事情。原则是文本文件与 dll 文件位于同一文件夹中,默认情况下从该文件夹中读取,没有长位置“字符串”

VSTA在构建 dll 中和之后都有效(非常简单)

Partial Class SolidWorksMacro
    Public Sub main()
        Dim Model As ModelDoc2 = swApp.ActiveDoc
        Dim LayerName As String = "Stamp"
        MsgBox(LayerName)
    End Sub
    Public swApp As SldWorks
End Class

不,我想以从文本文件中读取图层名称的方式做同样的事情。从运行时它可以工作VSTA,但是在构建到 dll 并从可靠的工作运行后它会给出错误:无法打开

“位置”\macro.dll。

Partial Class SolidWorksMacro
    Public Sub main()
        Dim Model As ModelDoc2 = swApp.ActiveDoc
        Dim LayerName As String = "Stamp"
        Dim FileName As String = "LayerName.txt"
        Dim LayerName As String
        Dim sr As New StreamReader(FileName)
        LayerName = sr.ReadLine
        MsgBox(LayerName)
    End Sub
    Public swApp As SldWorks
End Class
4

1 回答 1

2

How are you planning on running the code? You will have to build out additional functionality to create a button/taskpane/property page through the API for SOLIDWORKS to know what you want to do. It is a little more complicated than running a macro. What references did you add to your project? You will need to add at least:

  • SolidWorks.Interop.sldworks
  • SolidWorks.Interop.swpublished

Are you properly implementing the ISwAddin interface? Also, I have not had much luck merely opening a DLL with SOLIDWORKS, I use regasm.exe to register the COM DLL or create a wix installer to create the registry entries if distributing to multiple machines.

The Getting Started page in the API help will be a good reference to see some examples and how to configure your environment.

于 2017-02-02T17:04:28.310 回答