问题
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