Button_Click
Try
验证输入数据 VerificationInput()
获取值 Length、width、height
连接SolidWorks ConnectSw()
新建零件 NewPart()
文档框最大化 FrameMax()
生成矩形 GenerageModel(length, width, height);
Catch
private void VerificationInput()
{
string length = this.tbChangdu.Text;
string width = this.tbKuandu.Text;
string height = this.tbGaodu.Text;
if (!VerificationIsDigital(length))
{
throw new Exception("长度值不是有效数字,请重新输入!");
}
if (!VerificationIsDigital(width))
{
throw new Exception("宽度值不是有效数字,请重新输入!");
}
if (!VerificationIsDigital(height))
{
throw new Exception("高度值不是有效数字,请重新输入!");
}
}
public void ConnectSw()
{
//尝试连接已打开的Solidworks
if (swApp == null)
{
Process[] processArr = null;
processArr = Process.GetProcessesByName("SLDWORKS");
if (processArr.Length > 0)
{
//通过SldWorks.Application方式
try
{
swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
}
catch (Exception)
{
}
//通过SldWorks.Application.18方式,.18=2010版,.19=2011版,.20=2012版,.21=2013版,.22=2014版,.23=2015版
if (swApp == null)
{
for (int i = 18; i < 28; i++)
{
try
{
swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application." + i.ToString());
if (swApp != null)
{