起因在对SolidWorks进行二次开发的过程中SolidWorks API帮助必不可少然而其中多数实例是用VB和C++实现的本文提供一个利用C#进行SolidWorks二次开发的小实例希望能提供一个敲开这扇门的窗口
环境Windows XP + Visual Studio C# + SolidWorks
目的用C#打开SolidWorks的SLDPRT文件
步骤
安装SolidWorks API包
添加两个COM引用SldWorks Type Library和SolidWorks Constant type library
程序代码如下
using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
using SldWorks; //COM Reference: SldWorks Type Library
using SwConst; //COM Reference: SolidWorks Constant type library
namespace swTest
{
public partial class frmTest : Form
{
public frmTest()
{
InitializeComponent();
}
private void btnTest_Click_(object sender EventArgs e)
{
int IErrors = ;
int IWarnings = ;
SldWorksSldWorks swApp = new SldWorksSldWorks();
swAppOpenDoc(@E:\aSLDPRT(int)SwConstswDocumentTypes_eswDocPART(int)SwConstswOpenDocOptions_eswOpenDocOptions_Silentnull ref IErrors ref IWarnings);
swAppVisible = true;
}
}
}