获取某一产品库下所有Part及工程图,模型图,欢迎高人审阅,如有错误请指正.谢谢! package ext.powerlink; import wt.query.*; import wt.fc.*; import wt.part.*; import wt.vc.config.*; import wt.vc.views.View; import wt.vc.views.ViewHelper; import wt.vc.views.ViewReference; import java.io.*; import wt.util.*; import java.util.*; import org.apache.poi.hssf.usermodel.*; import wt.epm.*; import ext.com.part.PartUtil; import ext.com.util.ObjectUtil; import wt.epm.structure.*; import wt.part.WTPartMaster; import wt.inf.container.*; public class GetAllPartAndView{ public static void main(String args[]) throws Exception { System.out.println("Begin ..."); System.out.println("####################################"); String oid = args[0]; //获取产品库编号 WTContainer container = (WTContainer)ObjectUtil.getObjectByKey(oid); //导出数据 GetData(container); System.out.println("End!"); } public static void GetData(WTContainer container) throws Exception { QueryResult allWTPart =GetAllLatestPartsOfContainer(container); while(allWTPart.hasMoreElements()) { //输出WTPart WTPart part = (WTPart)allWTPart.nextElement(); //获得IBA属性 ext.com.iba.IBAUtil ibaUtil= new ext.com.iba.IBAUtil(part); //输出part编号 System.out.print("part编号:"+part.getNumber()+"/t"); //输出part名称 System.out.print("part名称:"+part.getName()+"/t"); //输出Part IBA属性 型号规格 String SpecType= ibaUtil.getIBAValue("SpecType"); System.out.print("part型号规格:"+SpecType+"/t"); //输出Part IBA属性 备注 String Comment= ibaUtil.getIBAValue("Comment"); System.out.print("part备注:"+Comment+"/t"); //获得part相关的所有CAD Vector allEPM =new Vector(); try { allEPM = getActiveCADandReferenceDoc(part,true); if (allEPM==null || allEPM.size()==0) { //根据零件标号及视图查找最新版本part part =getWTPartByNumberAndView(part.getNumber(),"Design"); if (part !=null) allEPM = getActiveCADandReferenceDoc(part,true); } } catch (WTException wte) { System.out.println("Error ="+wte.toString()); continue; } for(int i=0 ; i<allEPM.size() ; i++ ) { EPMDocument epm = (EPMDocument)allEPM.elementAt(i); String epmType = epm.getDocType().getStringValue(); //处理三维 if(epmType.equalsIgnoreCase("wt.epm.EPMDocumentType.CADCOMPONENT")||epmType.equalsIgnoreCase("wt.epm.EPMDocumentType.CADASSEMBLY")) { //三维图IBA属性 ext.com.iba.IBAUtil ibaUtil1= new ext.com.iba.IBAUtil(epm); //获取part对应的三维图编号 System.out.print("EPM编号:"+epm.getNumber()+"/t"); //获取part对应的三维图名称 System.out.print("EPM名称"+part.getName()+"/t"); //输出Part对应三维图IBA属性 型号规格 String EPMSpecType= ibaUtil.getIBAValue("SpecType"); System.out.print("EPM型号"+SpecType+"/t"); //输出Part对应三维图IBA属性 备注 String EPMComment= ibaUtil.getIBAValue("Comment"); System.out.print("EPM备注"+Comment+"/t"); } //处理二维图 if(epmType.equalsIgnoreCase("wt.epm.EPMDocumentType.CADDRAWING")) { //二维图IBA属性 ext.com.iba.IBAUtil ibaUtil1= new ext.com.iba.IBAUtil(epm); //获取part对应的二维图编号 System.out.print("CAD编号:"+epm.getNumber()+"/t"); //获取part对应的二维图名称 System.out.print("CAD名称"+part.getName()+"/t"); //输出Part对应二维图IBA属性 型号规格 String EPMSpecType= ibaUtil.getIBAValue("SpecType"); System.out.print("CAD型号"+SpecType+"/t"); //输出Part对应二维图IBA属性 备注 String EPMComment= ibaUtil.getIBAValue("Comment"); System.out.print("CAD备注"+Comment+"/t"); } } //输出换行 System.out.println("/n"); } } public static QueryResult GetAllLatestPartsOfContainer(WTContainer container)throws WTException { Vector allparts = new Vector(); QuerySpec qs = new QuerySpec(WTPartMaster.class); QueryResult qr=null; WTContainerRef containerRef = WTContainerRef.newWTContainerRef(container); ObjectIdentifier objId = ObjectIdentifier.newObjectIdentifier(containerRef.getKey().toString()); SearchCondition sc = new SearchCondition(WTPartMaster.class, "containerReference.key", SearchCondition.EQUAL, objId); qs.appendSearchCondition(sc); qr= PersistenceHelper.manager.find(qs); LatestConfigSpec latestconfigspec = new LatestConfigSpec(); QueryResult allWTPart = ConfigHelper.service.filteredIterationsOf(qr,latestconfigspec); return allWTPart; } public static Vector getActiveCADandReferenceDoc(WTPart part, boolean isIncludeReferenceDoc) throws WTException { Vector cads = new Vector(); try { EPMDocument cad=ext.com.part.PartUtil.getBuiltEPMDocByPart(part); if(cad!=null) { if( !ext.com.util.ObjectUtil.isPersistableInobjVector(cads, cad)) cads.add(cad); if(isIncludeReferenceDoc) { QuerySpec qs= new QuerySpec(EPMReferenceLink.class); QueryResult qr1= EPMStructureHelper.service.navigateReferencedBy((EPMDocumentMaster)cad.getMaster(), qs, false); while(qr1!=null && qr1.hasMoreElements()) { EPMReferenceLink epmRefLink =(EPMReferenceLink)qr1.nextElement(); int dep_type =epmRefLink.getDepType(); if (dep_type==4) { EPMDocument referencedBy= (EPMDocument)epmRefLink.getReferencedBy(); if( !ext.com.util.ObjectUtil.isPersistableInobjVector(cads,referencedBy) && referencedBy.isLatestIteration()) cads.add(referencedBy); } } } } } catch (WTException wte) { System.out.println("part ="+part.getIdentity()); System.out.println("wte ="+wte.toString()); } return cads; } //根据编号和视图查找所需视图的最新小版本,若不存在此视图的部件,则返回空 public static WTPart getWTPartByNumberAndView(String number, String view) throws Exception { WTPartMaster master = PartUtil.getWTPartMasterByNumber(number); if(master == null) return null; else return getWTPartByMasterAndView(master,view); } //根据编号和视图查找所需视图的最新小版本,若不存在此视图的部件,则返回空 public static WTPart getWTPartByMasterAndView(WTPartMaster master, String view) throws WTException,WTPropertyVetoException { WTPart part=null; View viewObj= ViewHelper.service.getView(view); WTPartConfigSpec config = WTPartHelper.service.findWTPartConfigSpec(); WTPartStandardConfigSpec standardConfig= config.getStandard(); standardConfig.setView(viewObj); QueryResult qr1 = ConfigHelper.service.filteredIterationsOf(master, standardConfig); while(qr1.hasMoreElements()) { WTPart iter = (WTPart)qr1.nextElement(); ViewReference viewObj1 = iter.getView(); String viewStr = ""; if(viewObj1 != null) viewStr = viewObj1.getName(); if(viewStr.length()!=0&&viewStr.equals(view)) { if(iter.isLatestIteration()) { part= iter; } } } return part; } }