以下为Windchill 二次开发新手入门常用的API
/**
* 根据用户名得到用户
* @param name 用户名
* @throws WTException
* return WTUser
*/
public static WTUser getUserFromName(String name) throws WTException {
Enumeration enumUser = OrganizationServicesHelper.manager.findUser(WTUser.NAME, name);
WTUser user = null;
if (enumUser.hasMoreElements())
user = (WTUser) enumUser.nextElement();
if (user == null) {
enumUser = OrganizationServicesHelper.manager.findUser(WTUser.FULL_NAME, name);
if (enumUser.hasMoreElements())
user = (WTUser) enumUser.nextElement();
}
if (user == null) {
throw new WTException("系统中不存在用户名为'" + name + "'的用户!");
}
return user;
}
}
10.windchill 中查询,高级查询,基本查询
QuerySpec qs = new QuerySpec();//构造
Int index = qs.appendClassList(WTPart.class,true);//添加查询类型,获取类型索引,第2个参数表示“要查询的类型、表”
WhereExpression where = new SearchCondition(WTPart.class, WTPart.xx, “=”, xx);//泛型在WC API中的使用
//获取查询条件数目
If(qs.getConditionCount()>0 && qs.getWhere().endsWith(“"))
{
qs.appendAnd();
}
//添加查询条件
qs.appendWhere(where, new int[]{index});
//** 以下是联合查询的API范例。LINK关系//ROLEA、ROLEB的INDEX被使用到。
int linkIndex = qs.appendClassList(XXLink.class, false);
qs.appendJoin(linkIndex, xxLink.RoleA, index_A);
qs.appendJoin(linkIndex, xxLink.RoleB, index_B);
//添加“生命周期”查询条件
LifeCycleConfigSpec lcsp = new LifeCycleConfigSpec();
lcsp.setLifeCycleState(State.toState(state));
qs = lcsp.appendSearchCriteria(qs);
//执行查询
QueryResult qr = PersistenceHelper.manager.find(qs);
//过滤出最新小版本
LatestConfigSpec lcs = new LatestConfigSpec();
qr = lcs.process(qr);
/**
* 根据WTPartMaster对象获得最新的WTPart
* @param partmaster WTPartMaster对象
* @return 最新的WTPart
* @throws WTException
*/
public static WTPart getLastPart(WTPartMaster partmaster) throws WTException{
WTPart part=null;
if(partmaster==null){
return part;
}
ConfigSpec configSpec=ConfigHelper.service.getDefaultConfigSpecFor(WTPart.class);
QueryResult qr=ConfigHelper.service.filteredIterationsOf(partmaster, configSpec);
if(qr!=null){
while(qr.hasMoreElements()){
part=(WTPart) qr.nextElement();
}
}
return part;
}