• Agile Engineering Collaboration CustomAction


    package com.agile.cax.custom;

    import com.agile.api.*;
    import com.agile.cax.datatypes.*;
    import com.agile.cax.*;
    /**
     * This class implements methods, which are called during
     * CAXConnector Load and Save Actions. Please add your customizing
     * in a class implementing this interface and set your class as
     * an actionhandler inside the CAXClient.xml
     */
    public class CustomAction extends CAXAction implements ICAXAction {
     
     public CustomAction() {
      super();
     }

     public void setChangeValues__UNUSED(IChange change, IAglFields data) {
      try {
       IItem item = (IItem) getTools().getObject(data);
       if (item != null) {
        /* define the correct field ids here */
        Integer ItemCompanyField = new Integer("1111");
        /* or
         *
         * Integer ItemCompanyField= ItemConstants.ATT_TITLE_BLOCK_...
         * */
        Integer ChangeCompanyField=new Integer("1223");
        /* or
         *
         * Integer ChangeCompanyField= ChangeConstants.ATT_COVER_PAGE_...
         * */
        String company = item.getValue(ItemCompanyField).toString();
        /* or you can get the value from the given fields
         * eg if they were transmitted from CAD properties...
         *
         * String company=data.getByName("COMPANY").toString();
         */
       
        change.setValue(ChangeCompanyField, company);
       }
      } catch (Exception e) {
       e.printStackTrace(System.out);
      }
     }
     /**
      * called before creation of an Object. Modify the data here to
      * modify occurrence in interactive dialog and to define defaults for fields
      * @param IAglFields fields : list of name-value pairs
      * @throws Exception
      */
     public void checkCreateEntry__UNUSED(IAglFields fields) throws Exception {
      // **************************************************
      // **       Code added by John Loechli for Metaldyne
      // **  restrict Agile Number prefix to SPN, PRT, STN
      // **  sufix to .PRT, .DWG, .ASM, .FRM
      // **  body to 6 digits excludeing "000000"
      // **  if not valid continue Interactive     
      // **************************************************  
      Validator validate = new Validator(getClient(), getTools());
      String newNumber = fields.getByName("NUMBER").get_ValueToString();
      if ( !validate.checkNumberformat(newNumber) ) {
       throw new Exception("Invalid Format: "+validate.getErrMsg());
      }
      
       // **************************************************
       // **       End of Code added by John Loechli for Metaldyne
       // **************************************************          
     }
     /**
      * called before Save is executed. Modify the data here to
      * modify occurrence in dialog and to define defaults for fields
      * @param IAglTable table : table of objects
      * @throws Exception
      */
     private static String CAX_FIL_NAME="CAX_FIL_NAME";
     private static String SYMBILC_PART_ID="CAX_PART";
     public void saveDialogOK(IAglTable table) throws Exception {
      try {
       if (!getClient().getXMLConfig().getClientConfig().get("IntermaticDataLoad").toString().equalsIgnoreCase("ON")) { return ; }
           }  catch (Exception e) { return ;}
      String exception = "";
      try {
       IAglFieldsArray fc = table.get_FieldsArray();
       // cycle over all selected items
       for (int i=0; i< fc.size(); i++) {
        try {
         // get the current line
         IAglFields line = fc.get(i);
         // check the selection
         if (line.getByName("SAVE_FLAG") != null && line.getByName("SAVE_FLAG").get_ValueToString().equals("1") && (line.getByName("SAVED")==null || line.getByName("SAVED").get_ValueToString().equals("0")) ) {
          // object is selected for save
          String msg="";
          // get the part id to be assigned
          String PartID = line.getByName(SYMBILC_PART_ID).get_ValueToString();
          String CadFil = line.getByName(CAX_FIL_NAME).get_ValueToString();
          if (CadFil.length()!=0) {
           // check if a part with this ID exists
           if (PartID.length()==0) {
            System.out.println("Warning: no PartID ("+SYMBILC_PART_ID+") for "+CadFil+" found in Database!");             
           } else {
            IAgileObject part = getTools().getObject(ItemConstants.CLASS_ITEM_BASE_CLASS, PartID, "");
            if (part!=null) {
             // Item is found, check the subclass
             if (!getTools().isPart(part)) {
              msg = "Warning: Found Item "+PartID+" for "+CadFil+" is not a Part subclass instance!";
             }
            } else {
             msg = "Error: Part "+PartID+" for "+CadFil+" doesn't exist in Database!";
            }
            if (msg.length()>0) {
             System.out.println(msg);
             if (exception.length()==0) { exception = msg; } else { exception=exception+"\n"+msg; }
            } else {
             System.out.println("OK: Part "+PartID+" for "+CadFil+" found in Database!");      
            }       
           }       
          }
         }
        } catch (Exception ee) {
         System.out.println(ee);
         ee.printStackTrace(System.out);
        }
       }
        
      } catch (Exception e) {
       // the object already exists in agile, therefore no cax_new_number is given
       e.printStackTrace(System.out);
      }
      if (exception.length()>0) throw new RuntimeException(exception);
     }
     


    }

  • 相关阅读:
    Angular常用VSCode插件
    asp.net MVC设计模式中使用iTextSharp实现html字符串生成PDF文件
    Docker Compose部署 EFK(Elasticsearch + Fluentd + Kibana)收集日志
    强烈推荐这本书《编码:隐匿在计算机软硬件背后的语言》
    frp 内网穿透访问内网Web服务
    代码玄学——镇代码的注释
    C#基础之多线程与异步
    C#基础之事件(1)
    WPF之Unity与ServiceLocator运用
    WPF之实现控件内容拖动
  • 原文地址:https://www.cnblogs.com/leojun/p/1869497.html
Copyright © 2020-2023  润新知