简体   繁体   English

SolidWorks API,宏可在VSTA中工作,但不能从dll中工作

[英]SolidWorks API, Macro working in VSTA but not from dll

Really appreciate who can spend couple of minutes to help me out, so thanks in advance ! 非常感谢谁可以花几分钟来帮助我,在此先感谢!

Got myself into situation where running macro in VSTA works (vb.net) , but running dll files from solid works does not work. 使自己陷入VSTA works (vb.net)中运行宏VSTA works (vb.net)运行的情况,但无法通过Solid VSTA works (vb.net)运行dll文件的情况。 Probably forgetting something very simple. 可能忘记了一些非常简单的东西。 Principle is that text file is in same folder as dll files and by default read from that folder without long location "string" 原则是文本文件与dll文件位于同一文件夹中,并且默认情况下从该文件夹中读取该文件而没有长位置“字符串”

This works in VSTA and after building dll (very simple) 这在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

No I want to do same thing in a way that layer name is read from text file. 不,我想通过从文本文件中读取图层名称的方式来做同样的事情。 It works when running from VSTA , but after building to dll and running from solid works it gives error: cannot open VSTA运行时,它可以工作,但是在构建到dll并从Solid Works运行时,它给出了错误:无法打开

"Location"\\macro.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

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. 您将必须构建其他功能,才能通过SOLIDWORKS的API来创建按钮/任务窗格/属性页面,以了解您想做什么。 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.sldworks
  • SolidWorks.Interop.swpublished SolidWorks.Interop.sw已发布

Are you properly implementing the ISwAddin interface? 您是否正确实现了ISwAddin接口? 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. 另外,我没有太多的运气,只是使用SOLIDWORKS打开DLL,如果将其分发到多台计算机,我会使用regasm.exe来注册COM DLL或创建wix安装程序来创建注册表项。

The Getting Started page in the API help will be a good reference to see some examples and how to configure your environment. API帮助中的“ 入门”页面将是一个很好的参考,以查看一些示例以及如何配置您的环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM