Cause: In the process of two development of SolidWorks, SolidWorks API help is essential, but most of these instances are implemented in VB6.0 and C + +, this article provides a small example of SolidWorks two development using C #. Hope to provide a window to knock the door open.
Environment: Windows XP + Visual Studio C # + SolidWorks 2008
Objective: To open a SolidWorks. sldprt file with C #.
Steps:
1, install SolidWorks2008 API package;
2, add two COM references: Sldworks 2008 type library and SolidWorks 2008 Constant type library;
3, the program code is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SldWorks; //COM Reference: SldWorks 2008 Type Library.
using SwConst; //COM Reference: SolidWorks 2008 Constant type library.
namespace swTest
{
public partial class frmTest : Form
{
public frmTest()
{
InitializeComponent();
}
private void btnTest_Click_1(object sender, EventArgs e)
{
int IErrors = 0;
int IWarnings = 0;
SldWorks.SldWorks swApp = new SldWorks.SldWorks();
swApp.OpenDoc6(@"E:\a.SLDPRT",(int)SwConst.swDocumentTypes_e.swDocPART,(int)SwConst.swOpenDocOptions_e.swOpenDocOptions_Silent,null, ref IErrors, ref IWarnings);
swApp.Visible = true;
}
}
}
Link: http://www.cnblogs.com/liong/archive/2008/05/21/1204404.html