客户端开发中一些常用方法总结

蓝图分享网 2022-10-26 21:53:39 411阅读 0评论

客户端开发中一些常用方法总结 第1张

作者:殷启帆   审校:朱松

适用版本:Teamcenter10以上;JDK1.7

在Teamcenter二次开发中,有些操作的功能是固定的,所以,很多常用功能的代码就可以通用,可以将这些操作写成通用代码,供以后重用。

本文总结了Teamcenter二次开发中,客户端开发所用到的一些常用方法,提高开发效率。

首先是获取版本对象的BOMLINE结构,传递参数是对象版本。

/**

       * 传递一个ITEM REVISION进去,得到这个ITEM的BOMLINE

*/

      public static TCComponentBOMLine getNewBOMLine(TCSession session ,TCComponentItemRevision itemR,TCComponentBOMViewRevision tcBomView) {

              TCComponentBOMWindowType bomWinType;

              try {

                     bomWinType = (TCComponentBOMWindowType) session

                            .getTypeComponent(“BOMWindow”);

                     TCComponentBOMWindow win = bomWinType.create(null);

                     win.lock();

                     win.setWindowTopLine(itemR.getItem(), itemR, null, tcBomView);

                     TCComponentBOMLine componentbomline = win.getTopBOMLine();

                     return componentbomline;

              } catch (TCException e) {

                     e.printStackTrace();

                     return null;

              }

       }

通过系统UID获取对象,若对象存在,返回值是True,否则,该对象已被删除。

// 根据UID构造异常来判断对应的对象是否存在,返回值如果为TRUE,则表示已删除

       public static boolean isNotDeleted(TCSession session, String uid) {

              boolean flag = false;

              try {

                            TCComponent comp = session.stringToComponent(uid);

                            System.out.println(“comp:”+comp);

                            System.out.println(“comp:”+comp.isValid());

                            System.out.println(“comp:”+comp.isValidUid());

                     }

              } catch (TCException e) {

                     flag = true;

              }

              return flag;

       }

通过数据集名称查找数据集对象。

// 在系统中查找数据集,返回查找结果

       public static TCComponentDataset findDataSet(TCSession session, String dataSetName) {

              TCComponentDataset dataSet = null;

              try {

                     TCComponentDatasetType dsType = (TCComponentDatasetType) session

                                   .getTypeComponent(“Dataset”);

                     dataSet = dsType.find(dataSetName);

                     if (dataSet == null) {

                            MessageBox.post(“在系统中没有找到” + dataSetName + ” 数据集”, “INFO”, 1);

                     }

                     return dataSet;

              } catch (TCException e) {

                     MessageBox.post(“在系统中没有找到” + dataSetName + ” 数据集”, “INFO”, 1);

                     e.printStackTrace();

                     return null;

              }

       }

在系统中创建数据集。

// 创建数据集

       public static TCComponentDataset createDataset(TCSession session, TCComponent com,

                     String name, String url, String strType, String type) {

              try {

                     String as1[] = { url };

                     String as2[] = { strType };

                     TCComponentDatasetType tccomponentDatasetType = (TCComponentDatasetType) session

                                   .getTypeComponent(type);

                     TCComponentDataset tccomponentDataset = tccomponentDatasetType

                                   .create(name, “”, type);

                     if (tccomponentDataset != null)

tccomponentDataset.setFiles(as1, as2);

                            com.add(“IMAN_specification”, tccomponentDataset);

                     System.out.println(“=====================已重新创建数据集。。。”);

              } catch (TCException e) {

                     e.printStackTrace();

              }

       return  tccomponentDataset;

       }

创建零组件版本和分类节点之间关系,即给零组件版本分类。

       // tcobj —-零组件对象

       // ics_id—-分类节点ID

       public static void createCmpAndIcs(TCSession session, TCComponent tcobj,

                     String ics_id) throws TCException {

              String str = tcobj.getStringProperty(“ics_classified”);

              if (str != null && str.compareTo(“YES”) == 0)

                     return;

              TCClassificationService ics = session.getClassificationService();

              ICSApplicationObject icsap = ics.newICSApplicationObject(“ICM”);

              String wso_ics_id = ics.getTCComponentId(tcobj);

              String wso_uid = tcobj.getUid();

 

              icsap.create(wso_ics_id, wso_uid);

              icsap.setView(“Base”, ics_id);

 

              ICSPropertyDescription[] ppDesc = icsap.getView()

                            .getPropertyDescriptions();

              if (ppDesc != null) {

                     ICSProperty icss[] = new ICSProperty;

                     for (int i = 0; i

                            icss = new ICSProperty(ppDesc.getId(), “”);

                     }

                     icsap.setProperties(icss);

                     icsap.save();

              }

       }

逐行读取文本文档的内容,返回每行内容的集合。

public static Vector readFileTxt(String fileName) {

              File file = new File(fileName);

              Vector vec = new Vector();

              try {

                     BufferedReader reader = new BufferedReader(new FileReader(file));

                     String tempString = null;

                     int line = 1;

                     // 一次读一行,直到读取为null

                     while ((tempString = reader.readLine()) != null) {

                            vec.add(tempString);

                     }

              } catch (FileNotFoundException e) {

                     e.printStackTrace();

              } catch (IOException e) {

                     e.printStackTrace();

              }

              return vec;

       }

将集合里的数据逐行写入文本文档。

public static void writeFileTxt(String toFileName, Vector vec) {

try {

PrintWriter writer = new PrintWriter(new FileWriter(toFileName,

true), true);

if (vec.size() > 0) {

for (int i = 0; i

  writer.println(vec.get(i));

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

免责声明:

1、本站所有资源文章出自互联网收集整理,本站不参与制作,如果侵犯了您的合法权益,请联系本站我们会及时删除。

2、本站发布资源来源于互联网,可能存在水印或者引流等信息,请用户擦亮眼睛自行鉴别,做一个有主见和判断力的用户。

3、本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。

4、侵权违法和不良信息举报 举报邮箱:cnddit@qq.com

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
验证码
评论列表 (暂无评论,411人围观)

还没有评论,来说两句吧...