Windchill常见开发API
持久化管理
- wt.fc.Persistable接口:所有持续化的对象都实现这个接口。
- lwt.fc.PersistenceHelper :有一个PersistenceManager属性:manager 。
- lwt.fc.PersistenceManager接口:提供一系列的方法,对持续化对象进行操作;如:delete(),find()等。
- wt.fc.StandardPersistenceManager:实现PersistenceManager接口。
示例
l查询对象示例:
l更新一个对象示例:
说明:QuerySpec定义查询对象;SearchCondition定义查询条件;QueryResult是查询结果
文档相关对象
wt.doc.WTDocument
wt.epm.EPMDocument
wt.doc.WTDocumentMaster
wt.epm.EPMDocumentMaster
创建文档
HashMap<String, String> inputdata = new HashMap<String, String>();
inputdata.put("name", doc_name);
inputdata.put("folderRef", folderRef);
inputdata.put("container", containerRef);
TypeIdentifier typeidentifier = FdnWTContainerHelper.toTypeIdentifier("wt.doc.WTDocument");
WTDocument document = ApplicationIntegrationFactory.createDocument(typeidentifier,inputdata,false,SessionHelper.manager.getLocale(), "html");
//保存挂载附件
ontentHolder ch = (ContentHolder) document;
ApplicationData ap = ApplicationData.newApplicationData(ch);
ap.setRole(ContentRoleType.PRIMARY);
StringfilePath = doc_path;
ap= ContentServerHelper.service.updateContent(ch, ap, filePath);
ap= (ApplicationData) PersistenceHelper.manager.save(ap);
查询文档
QuerySpec querySpec = new QuerySpec(WTDocument.class);
WhereExpression where = new SearchCondition(WTDocument.class,
WTDocument.NAME,SearchCondition.EQUAL,name);
QueryResult result = PersistenceHelper.manager.find((StatementSpec) querySpec);
/**
* 查询最新版本的状态为已发布的文档
* @param state
*
* sql:
*
* SELECT A0.*
* FROM WTDocument A0
* WHERE (A0.statestate = 'RELEASED') AND (A0.idA2A2 IN (SELECT MAX(A0.idA2A2) FROM WTDocument A0 GROUP BY A0.idA3masterReference))
* @return
*/
public static QueryResult querydocumentByState(String state) throws WTException {
QuerySpec qs= new QuerySpec();
qs.setAdvancedQueryEnabled(true);
int classIndex=qs.appendClassList(WTDocument.class,true);
SearchCondition sc =new SearchCondition(WTDocument.class,WTDocument.LIFE_CYCLE_STATE,SearchCondition.EQUAL,state);
qs.appendWhere(sc,new int[] {classIndex});
qs.appendAnd();
QuerySpec subQs= querylatestDocumentSubQuery();
SubSelectExpression subselect= new SubSelectExpression(subQs);
String docIDA2A2=WTDocument.PERSIST_INFO+"."+ PersistInfo.OBJECT_IDENTIFIER+"."+ObjectIdentifier.ID;
ClassAttribute docIda3a3Attribute = new ClassAttribute(Document.class,docIDA2A2);
sc=new SearchCondition(docIda3a3Attribute,SearchCondition.IN,subselect);
qs.appendWhere(sc,new int[]{classIndex});
QueryResult qr=PersistenceHelper.manager.find(qs);
MethodContext.getContext().sendFeedback(new StatusFeedback("<><><><>:"+ qs));
if (qr.hasMoreElements()) {
Object[] objects = (Object[]) qr.nextElement();
WTDocument wtDocument= (WTDocument) objects[0];
MethodContext.getContext().sendFeedback(new StatusFeedback("<><><><qr><><><>:"+ wtDocument.getNumber()));
WTDocument doc= reassignLifecyeleBuDocName(wtDocument,"LY_Part_STD_LC");
changeStateByDocumentName(doc,"P");
}
return qr;
}
/**
* 根据WTDocumentMaster的idaa分组,然后取每组中的的WTdocument的ida2a2最大的一条记录,以此作为Master的最新版本
*
*/
public static QuerySpec querylatestDocumentSubQuery() throws WTException {
QuerySpec qs=new QuerySpec();
qs.setAdvancedQueryEnabled(true);
int classIndex = qs.appendClassList(WTDocument.class,false);
String docida2a2 = WTDocument.PERSIST_INFO + "." + PersistInfo.OBJECT_IDENTIFIER + "." + ObjectIdentifier.ID;
ClassAttribute docida2a2Attribute = new ClassAttribute(WTDocument.class,docida2a2);
SQLFunction maxida2a2= SQLFunction.newSQLFunction(SQLFunction.MAXIMUM,docida2a2Attribute);
qs.appendSelect(maxida2a2,new int[] {classIndex},false);
String docMasterreferenceid = WTDocument.MASTER_REFERENCE+"."+ObjectReference.KEY+"."+ObjectIdentifier.ID;
ClassAttribute masterrferenceAttribute = new ClassAttribute(WTDocument.class,docMasterreferenceid);
qs.appendGroupBy(masterrferenceAttribute,new int[] {classIndex},false);
return qs;
}
更新文档
WTDocumentMaster docmaster = (WTDocumentMaster) doc.getMaster();
WTDocumentMasterIdentity docmasteridentity = (WTDocumentMasterIdentity) docmaster
.getIdentificationObject();
docmasteridentity.setName(newDocName);
docmasteridentity.setNumber();
docmaster = (WTDocumentMaster) IdentityHelper.service.changeIdentity(docmaster, docmasteridentity);
文档的生命周期
/**
* 重新制定文档生命周期
*
*/
public static WTDocument reassignLifecyeleBuDocName(WTDocument doc,String lifecycleName){
try{
LifeCycleTemplateReference lifeCycleTemplateReference = LifeCycleHelper.service
.getLifeCycleTemplateReference(lifecycleName);
doc = (WTDocument) LifeCycleHelper.service.reassign(doc,lifeCycleTemplateReference);
if(doc!=null){
MethodContext.getContext().sendFeedback(new StatusFeedback("重置成功"));
}
}catch (WTException WTE){
WTE.printStackTrace();
}
return doc;
}
/**
* 重新设置文档状态
*
*/
public static void changeStateByDocumentName(WTDocument doc,String statename){
State state = State.toState(statename);
try{
LifeCycleManaged obj = (LifeCycleManaged) doc;
obj = LifeCycleHelper.service.setLifeCycleState(obj,state);
String stateDisplayName = obj.getLifeCycleState().getDisplay();
if(stateDisplayName.equals(statename)){
MethodContext.getContext().sendFeedback(new StatusFeedback("重新设置状态成功"));
}
}catch (WTException WTE){
WTE.printStackTrace();
}
}
得到对象的大小版本
其中****wt.enterprise.RevisionControlled 是WTDoucment父类
查询对象的笔记本
创建笔记本
部件操作
查询部件
更改部件编号
/**
* 更改部件编号
* @param wtPart
* @param newNumber
* @return
* @throws WTException
* @throws WTPropertyVetoException
*/
public static WTPart reNumberWTPart(WTPart wtPart,String newNumber) throws WTException, WTPropertyVetoException{
WTPart part=(wt.part.WTPart)PersistenceHelper.manager.refresh(wtPart);
WTPartMaster wtPartMaster=(WTPartMaster)part.getMaster();
WTPartMasterIdentity wtpartmasterIdentity = (WTPartMasterIdentity) wtPartMaster
.getIdentificationObject();
if(!wtpartmasterIdentity.getNumber().equals(newNumber.trim())){
wtpartmasterIdentity.setNumber(newNumber.trim());
IdentityHelper.service.changeIdentity(wtPartMaster,wtpartmasterIdentity);
part = (wt.part.WTPart)PersistenceHelper.manager.refresh(part);
}
return part;
}
创建部件
部件生命周期
- 查询生命周期
- part.getState
重新指定部件的生命周期状态
得到部件的子阶
查询部件的替代料
常见BOM属性
位号:
QueryResult queryresult = OccurrenceHelper.service.getUsesOccurrences(usageLink);
子阶料号:
usageLink.getQuantity().getAmount()
单位:
usageLink.getQuantity().getUnit()
查询对象的笔记本
创建笔记本
部件参考文档
查询参考文档
创建部件的参考文档
查询部件的说明文档
QueryResult docs = wt.part.WTPartHelper.service.getDescribedByWTDocuments(part)
创建部件的说明文档
WTPartDescribeLink link = WTPartDescribeLink.newWTPartDescribeLink(part,document);
PersistenceServerHelper.manager.insert(link);
查询部件的CAD文档
容器文件夹、工作流
-
容器
-
wt.inf.container.WTContainer接口:
-
wt.inf.container.OrgContainer, wt.pdmlink.PDMLinkProduct, wt.projmgmt.admin.Project2, wt.inf.library.WTLibrary实现这个接口
-
文件夹
-
wt.folder.Folder****接口
wt.folder.SubFolder:实现wt.folder.Folder接口
得到文件夹
创建文件夹
更新流程实例对象
变更
-
变更相关对象
-
**wt.change2.WTChangeActivity2:**变更任务
**wt.change2.WTChangeOrder2:**变更通知
**wt.change2.WTChangeRequest2:**变更请求
ECN中相关对象
升级
- 升级对象 wt.maturity.PromotionNotice
- 升级流程 升级流程PBO对象为wt.maturity.PromotionNotice
升级流程收集升级对象
权限操作
l**wt.team.Team****,团队
l**wt.project.Role****,角色
l**wt.org.WTPrincipal****,抽象类,子类:WTUser,WTGroup
l**wt.org.WTUser****,用户
l**wt.org.WTGroup****,组
lwt.session.SessionHelper
获取到工作流团队
获取到组成员
从团队中获得角色
切换权限Session
项目
生命周期
生命周期相关对象
wt.lifecycle.LifeCycleManaged接口:所有具有生命周期的对象都实现这个接口;包括:WTPart,WTDocument
wt.lifecycle.State 生命周期状态
LifeCycleService接口:定义一些方法,对生命周期管理的对象进行操作
wt.lifecycle.StandardLifeCycleService****实现LifeCycleService接口
LifeCycleHelper:有一个LifeCycleService属性:service
高级查询
查询示例
l高级查询一般用于有多种约束条件的数据查询.用高级查询主要用来减少数据查询的次数,提高查询的效率.
需求**:
**该方法用来查询生命周期状态为‘****RELEASED’****或‘****INWORK’**的最新的二维图
查询设计**:
**1.**搜索条件
1)最后修改时间(输入从开始时间到结束时间)
2)状态为’RELEASED’或’INWORK‘
3)同一图纸只返回一个版本(通过EPMDocumentMaster返回一个)
**4)后缀名称为.**drw
sql查询逻辑
询的次数,提高查询的效率.**
需求**:
**该方法用来查询生命周期状态为‘****RELEASED’****或‘****INWORK’**的最新的二维图
查询设计**:
**1.**搜索条件
1)最后修改时间(输入从开始时间到结束时间)
2)状态为’RELEASED’或’INWORK‘
3)同一图纸只返回一个版本(通过EPMDocumentMaster返回一个)
**4)后缀名称为.**drw
sql查询逻辑