-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicCode.cs
More file actions
81 lines (72 loc) · 3.65 KB
/
Copy pathBasicCode.cs
File metadata and controls
81 lines (72 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
namespace SolidWorksSecDev
{
public class BasicCode
{
/// <summary>
/// 编辑零件
/// </summary>
/// <param name="swApp">SW程序</param>
public void EditSwModel(SldWorks swApp)
{
ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;//获取当前打开的零件
//判断为零件时继续执行,否则跳出
if (swModel.GetType() != (int)swDocumentTypes_e.swDocPART) return;
PartDoc swPartDoc = (PartDoc)swModel;
//修改参数,注意SW中单位为米,换算成mm应当除以1000
swModel.Parameter("D2@Sketch2").SystemValue = 200 / 1000m;
//压缩特征
Feature swFeat = swPartDoc.FeatureByName("Edge-Flange1");
swFeat.SetSuppression2(1, 2, null); //参数1:1解压,0压缩,2解压缩这个特征的子特征
//设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
swModel.ForceRebuild3(true);
swModel.Save();//保存,很耗时间
}
/// <summary>
/// 编辑装配体
/// </summary>
/// <param name="swApp">SW程序</param>
public void EditSwAssy(SldWorks swApp)
{
ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;//获取当前打开的零件/装配体
//判断不是装配体直接跳出
//if (Path.GetExtension(swModel.GetPathName()).ToUpper()!=".SLDASM") return;
if (swModel.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY) return;
AssemblyDoc swAssy = (AssemblyDoc)swModel;
//修改装配体顶层参数
swModel.Parameter("D1@Distance1").SystemValue = 300 / 1000m;
//修改装配体顶层特征
Feature swFeat = swAssy.FeatureByName("LocalLPattern1");
swFeat.SetSuppression2(0, 2, null); //参数1:1解压,0压缩
//压缩装配体中的零件
Component2 swComp = swAssy.GetComponentByName("Part1-3");
swComp.SetSuppression2(0); //2解压缩(包含子装配内部),0压缩,3只解压子装配本身. .
swModel.ForceRebuild3(true);
swModel.Save();//保存,很耗时间
}
/// <summary>
/// 编辑子装配体
/// </summary>
/// <param name="swApp">SW程序</param>
public void EditSubAssy(SldWorks swApp)
{
ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;//获取当前打开的零件/装配体
//判断不是装配体直接跳出
if (swModel.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY) return;
AssemblyDoc swAssy = (AssemblyDoc)swModel;
Component2 swComp = swAssy.GetComponentByName("Assem1-1");//获取子装配
ModelDoc2 swSubModel = swComp.GetModelDoc2(); //打开零件
swSubModel.Parameter("D1@LocalLPattern1").SystemValue = 3;//阵列数量
swSubModel.Parameter("D3@LocalLPattern1").SystemValue = 500 / 1000m;//阵列距离
AssemblyDoc swSubAssy = (AssemblyDoc)swSubModel;
swComp = swSubAssy.GetComponentByName("Part2-1");
ModelDoc2 swPart = swComp.GetModelDoc2(); //打开零件
swPart.Parameter("D7@边线-法兰2").SystemValue = 100 / 1000m;
Feature swFeat = swComp.FeatureByName("Cut-Extrude1");
swFeat.SetSuppression2(0, 2, null); //参数1:1解压,0压缩
swModel.ForceRebuild3(true);
swModel.Save();//保存,很耗时间
}
}
}