Solidworks API and Winforms C# swApp (Standalone)

南楼画角 提交于 2019-12-12 01:38:10

问题


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;

回答1:


Figured it out thanks for the help everyone.

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



回答2:


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.



来源:https://stackoverflow.com/questions/7420697/solidworks-api-and-winforms-c-sharp-swapp-standalone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!