windchill复制bom结构 代码实现
时间: 2023-06-10 21:07:38 浏览: 66
以下是Windchill复制BOM结构的代码实现,其中使用了Windchill API:
```
import wt.fc.*;
import wt.part.*;
import wt.session.*;
import wt.util.WTException;
import wt.vc.*;
import wt.vc.config.*;
import wt.part.WTPart;
import wt.part.WTPartUsageLink;
import wt.part.WTPartMaster;
import wt.part.WTPartConfigSpec;
import wt.part.WTPartStandardConfigSpec;
import wt.part.WTPartUsageLinkInfo;
public class CopyBOM {
public static void copy(WTPart partSrc, WTPart partDest) throws WTException {
// 获取partSrc的BOM结构
WTPartUsageLinkInfo[] usages = WTPartHelper.service.getUsesWTPartMasters(partSrc);
if (usages == null || usages.length == 0) {
return;
}
// 获取partDest的Master
WTPartMaster partMasterDest = partDest.getMaster();
WTPartStandardConfigSpec configSpec = WTPartHelper.service.findWTPartStandardConfigSpec();
WTPartConfigSpec partConfigSpec = configSpec.getWTPartConfigSpec(partMasterDest);
for (int i = 0; i < usages.length; i++) {
WTPartUsageLinkInfo usageLinkInfo = usages[i];
WTPartMaster usagePartMasterSrc = usageLinkInfo.getUses();
WTPartUsageLink usageLinkSrc = usageLinkInfo.getUsageLink();
// 查找partDest是否已经包含了该子件
QueryResult qr = WTPartHelper.service.getUsesWTPartMasters(partDest, usagePartMasterSrc);
if (qr != null && qr.size() > 0) {
continue;
}
// 将子件添加到partDest
WTPartUsageLink usageLinkDest = WTPartUsageLink.newWTPartUsageLink(partDest, usagePartMasterSrc);
usageLinkDest.setQuantity(usageLinkSrc.getQuantity());
usageLinkDest.setRoleAObject(partDest);
usageLinkDest.setRoleBObject(usagePartMasterSrc);
WTPartHelper.service.saveUsageLink(usageLinkDest);
// 递归复制子件的BOM结构
WTPart partSrcChild = usageLinkSrc.getUses();
WTPart partDestChild = WTPart.newWTPart(partMasterDest);
partDestChild.setName(partSrcChild.getName());
partDestChild.setNumber(partSrcChild.getNumber());
partDestChild.setDescription(partSrcChild.getDescription());
WTPartHelper.service.save(partDestChild);
copy(partSrcChild, partDestChild);
}
}
}
```
使用方法:
```
WTPart partSrc = ...; // 原始部件
WTPart partDest = ...; // 目标部件
CopyBOM.copy(partSrc, partDest); // 复制BOM结构
```