1.1.根据零件名称/编码得到该零件2.wt.clients.prodmgmt.WTPartHelper.findPartByName(name);3.wt.clients.prodmgmt.WTPartHelper.findPartByNumber(number);4.2.根据WTpart得到WTparMaster5.WtPartwtpart;6.WTPartMasterwtmaster=(WTPartMster)part.getMaster();7.3.获取codebase下配置文件wt.properties属性信息8.WTPropertieswtproperties=WTProperties.getLocalProperties();9.Stringwthome=wtproperties.getProperty(wt.home,);//codebase的文件夹路径10.4.获取part被借用的所有父部件11.QueryResultqr=wt.part.WTPartHelper.service.getUsedByWTParts(WTPartMsterwtMaster);12.注:此方法得到的结果为该part被使用情况的全部父部件,包括了Design视图及Manufacturing视图更包括了父部件使用part的所有修订版本,打印出来可以看到会有相同的部件编号,不同的修订版本.13.5.根据OID获取Wtpart14.wt.fc.WTReferencepartRef=newwt.fc.ReferenceFactory().getReference(oid);15.WTPartwtpart=(WTPart)partRef;16.6.得到零件最新版本17.WTPartwtpart=(WTPart)VersionControlHelper.getLatestIteration(part);18.7.通过过滤得到零件最新版本19.QuerySpecquerysearch=newQuerySpec(WTPartMaster.class);20.//查询所有的WTPartMaster21.QueryResultqueryresult=PersistenceHelper.manager.find(querysearch);22.LatestConfigSpeclatestconfigspec=newLatestConfigSpec();23.//根据WTPartMaster查询所有最新版本的零部件24.QueryResultallWTPart=ConfigHelper.service.filteredIterationsOf(queryresult,latestconfigspec)25.8.查询某用户某段时间范围内创建的零件26.QuerySpecqs=newQuerySpec(WTPart.class);27.qs.appendSearchCondition(newSearchCondition(WTPart.class,WTPart.CREATE_TIMESTAMP,true,newAttributeRange(begintime,endtime)));//删选条件时间范围内28.qs.appendAnd();//一定要加上不然下一个条件不能删选29.qs.appendSearchCondition(newSearchCondition(WTPart.class,30.iterationInfo.creator.key,SearchCondition.EQUAL,PersistenceHelper.getObjectIdentifier(name)));//删选条件用户31.QueryResultqr=PersistenceHelper.manager.find(qs);32.//今后持续更新1.根据零件名称/编码得到该零件wt.clients.prodmgmt.WTPartHelper.findPartByNamewt.clients.prodmgmt.WTPartHelper.findPartByNumb2.根据WTpart得到WTparMasterWtPartwtpart;WTPartMasterwtmaster=(WTPartMster)part.getMaste3.获取codebase下配置文件wt.properties属性信息WTPropertieswtproperties=WTProperties.getLocaStringwthome=wtproperties.getProperty(wt.ho4.获取part被借用的所有父部件QueryResultqr=wt.part.WTPartHelper.service.ge注:此方法得到的结果为该part被使用情况的全部父部件,5.根据OID获取Wtpartwt.fc.WTReferencepartRef=newwt.fc.ReferenceFaWTPartwtpart=(WTPart)partRef;6.得到零件最新版本WTPartwtpart=(WTPart)VersionControlHelper.get7.通过过滤得到零件最新版本/***根据用户名得到用户*@paramname用户名*@throwsWTException*returnWTUser*/publicstaticWTUsergetUserFromName(Stringname)throwsWTException{EnumerationenumUser=OrganizationServicesHelper.manager.findUser(WTUser.NAME,name);WTUseruser=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){thrownewWTException(系统中不存在用户名为'+name+'的用户!);}returnuser;}}10.windchill中查询,高级查询,基本查询QuerySpecqs=newQuerySpec();//构造Intindex=qs.appendClassList(WTPart.class,true);//添加查询类型,获取类型索引,第2个参数表示“要查询的类型、表”WhereExpressionwhere=newSearchCondition(WTPart.class,WTPart.xx,“=”,xx);//泛型在WCAPI中的使用//获取查询条件数目If(qs.getConditionCount()0&&qs.getWhere().endsWith(“)){qs.appendAnd();}//添加查询条件qs.appendWhere(where,newint[]{index});//**以下是联合查询的API范例。LINK关系//ROLEA、ROLEB的INDEX被使用到。intlinkIndex=qs.appendClassList(XXLink.class,false);qs.appendJoin(linkIndex,xxLink.RoleA,index_A);qs.appendJoin(linkIndex,xxLink.RoleB,index_B);//添加“生命周期”查询条件LifeCycleConfigSpeclcsp=newLifeCycleConfigSpec();lcsp.setLifeCycleState(State.toState(state));qs=lcsp.appendSearchCriteria(qs);//执行查询QueryResultqr=PersistenceHelper.manager.find(qs);//过滤出最新小版本LatestConfigSpeclcs=newLatestConfigSpec();qr=lcs.process(qr);/***根据WTPartMaster对象获得最新的WTPart*@parampartmasterWTPartMaster对象*@return最新的WTPart*@throwsWTException*/publicstaticWTPartgetLastPart(WTPartMasterpartmaster)throwsWTException{WTPartpart=null;if(partmaster==null){returnpart;}ConfigSpecconfigSpec=ConfigHelper.service.getDefaultConfigSpecFor(WTPart.class);QueryResultqr=ConfigHelper.service.filteredIterationsOf(partmaster,configSpec);if(qr!=null){while(qr.hasMoreElements()){part=(WTPart)qr.nextElement();}}returnpart;}