Solidworks API 和 Winforms C# swApp(独立)

发布于 2024-12-04 14:22:28 字数 616 浏览 0 评论 0原文

这就是 solidworks 告诉您引用 swApp 时要做的事情,但我在引用它的行上不断收到 NullReferenceException

有谁知道为什么吗?或者我该如何修复?

我可以稍后引用它,例如 swApp = ????

private void button5_Click(object sender, EventArgs e)
{
    //Save Drawing
    ModelDoc2 swDoc = null;
    int longstatus = 0;
    swDoc = ((ModelDoc2)(swApp.ActiveDoc));
    longstatus = swDoc.SaveAs3(
            @"C:\Engineering\Engineering\SW Automation\Linear Actuator Technology\MLD Series\Prints\Configured Prints\" + 
            textBox1.Text + ".SLDDRW", 0, 2);
}

public SldWorks swApp;

This is what solidworks tells you to do to reference swApp, but I keep getting NullReferenceException on the line that it is referenced.

Does anyone have any idea why? or How I go about repairing?

Can I reference it later on such as swApp = ????

private void button5_Click(object sender, EventArgs e)
{
    //Save Drawing
    ModelDoc2 swDoc = null;
    int longstatus = 0;
    swDoc = ((ModelDoc2)(swApp.ActiveDoc));
    longstatus = swDoc.SaveAs3(
            @"C:\Engineering\Engineering\SW Automation\Linear Actuator Technology\MLD Series\Prints\Configured Prints\" + 
            textBox1.Text + ".SLDDRW", 0, 2);
}

public SldWorks swApp;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贩梦商人 2024-12-11 14:22:28

弄清楚了谢谢大家的帮助。

SldWorks swApp = null;
swApp = (SldWorks)Activator.CreateInstance(
            Type.GetTypeFromProgID("SldWorks.Application"));

Figured it out thanks for the help everyone.

SldWorks swApp = null;
swApp = (SldWorks)Activator.CreateInstance(
            Type.GetTypeFromProgID("SldWorks.Application"));
薔薇婲 2024-12-11 14:22:28

在某个地方,您将不得不填充Swapp。我不使用SOLIDWORKS,所以我不能给您确切的代码,而是在其示例代码的构造函数中查看。也许您可以找到一个示例,说明如何在那里填充Swapp。

Somewhere you're going to have to populate swApp. I don't use SolidWorks so I can't give you the exact code but look in the constructor of their example code. Maybe you can find an example of how swApp is populated there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文