文章目录
一、更新日志
2020-10-19
2020-11-16
略微细化介绍,补充部分代码
2020-11-19
补充说明,错别字修改
Ⅰ、开发DLL环境
一、 第一步安装SolidWorks API SDK.msi
在SW软件里找到SolidWorks API SDK.msi
不过我这里有2014的
提取码:1123
二、 第二步得到SW开发文档"API"获取模版
可以用一些方式从SolidWorks API SDK.msi中得到
不过我这里有2014的,放到指定路径就能直接使用
安装地址参考
提取码:1123
三、 第三步找到需要引用的DLL文件
总之我这里有2014的
提取码:1123
Ⅱ、使用
一、获取当前工作区"盒子"X,Y,Z,并且调用插入方法(通用)
模版SwAddin.cs中编写(未精减)
public static double GetMax(double Val1, double Val2, double Val3)
{
double functionReturnValue = 0;
// 找到3个值的最大值
// Finds maximum of 3 values
functionReturnValue = Val1;
if (Val2 > functionReturnValue)
{
functionReturnValue = Val2;
}
if (Val3 > functionReturnValue)
{
functionReturnValue = Val3;
}
return functionReturnValue;
}
public static double GetMin(double Val1, double Val2, double Val3)
{
double functionReturnValue = 0;
// 找到3个值的最小值
// Finds minimum of 3 values
functionReturnValue = Val1;
if (Val2 < functionReturnValue)
{
functionReturnValue = Val2;
}
if (Val3 < functionReturnValue)
{
functionReturnValue = Val3;
}
return functionReturnValue;
}
public static void Main(string ModelFile)
{
const double MaxDouble = 0;
const double MinDouble = 0;
ModelDoc2 swModel = default(ModelDoc2);
AssemblyDoc swAssy = default(AssemblyDoc);
Configuration swConfig = default(Configuration);
ConfigurationManager swConfigurationMgr = default(ConfigurationManager);
Component2 swRootComp = default(Component2);
object[] vChild = null;
Component2 swChildComp = default(Component2);
object Box = null;
double[] BoxArray = new double[6];
double X_max = 0;
double X_min = 0;
double Y_max = 0;
double Y_min = 0;
double Z_max = 0;
double Z_min = 0;
SketchPoint[] swSketchPt = new SketchPoint[9];
SketchSegment[] swSketchSeg = new SketchSegment[13];
int i = 0;
if (iSwApp.GetDocumentCount() == 0)
{