(实战)创建SelectedItems处理方法

1、in dir/msg/bbkmsg.met file, define as:
   define class message NewReport like SelectedItemSetMsg;
 
2、in dir/src/pdmitem.met file, define as:
   attach class message NewReport to PdmItem in server bbksvr;
3、in dir/src/pdmitemb.met file, define as:
   define option bbkNewReportOpt using message NewReport;
   display bbkNewReportOpt as "Write Report File";
   attach option bbkNewReportOpt to OmfPdoInfReportsOptL;
 
4、write the method code at dir/src/pdmitem.mth file:
注意 osExecuteAsync的参数如何组织!
 
class message PdmItem:NewReport(...)
{
   char *mod_name = "PdmItem:NewReport";
   status dstat = OKAY;
   char* a_home = NULL;
   char* a_hometemp = NULL;
   char* a_date = NULL;
   char* a_datetemp = NULL;
   char* outfile_name = NULL;
   char *a_type = NULL;
   char *a_dtype = NULL;
   FILE *file = NULL;
   MetaPtr dftMeta = NULL;
   ObjectPtr item = NULL;
   string itemClass = NULL;
   SetOfStrings itemAttrs = NULL;
   string attrName = NULL;
   string attrPrompt = NULL;
   string attrValue  = NULL;
   int size, i;
   int aSize, ia;
   string argv[3];
   *mfail = USC_OKAY;
 
// get name of directory from environment variable HOME
// make a local copy in memory
 
   a_hometemp = osGetenv(NULL, NULL, "HOME");
   if (a_hometemp == NULL) goto EXIT;
   a_home = nlsStrDup(a_hometemp);
   if (a_home == NULL) goto EXIT;
 
// get system date for creating report file
// make a local copy in memory
 
   a_datetemp = sysGetDate();
   if (a_datetemp == NULL) goto EXIT;
   a_date = nlsStrDup(a_datetemp);
   if (a_date == NULL) goto EXIT;
 
// create output file full path
 
// allocate string to contain complete path
   outfile_name = nlsStrAlloc(nlsStrLen(a_home) + 5 + nlsStrLen(a_date) + 5);
   outfile_name = nlsStrCpy(outfile_name, a_home);
   outfile_name = nlsStrCat(outfile_name, "
\\rep_");  // NT
//  outfile_name = nlsStrCat(outfile_name, "/rep_");  // UNIX
   outfile_name = nlsStrCat(outfile_name, a_date);
   outfile_name = nlsStrCat(outfile_name, ".txt");
 
// open the output file
   if ((file = sysFopen(outfile_name,"w")) == NULL)
   {
      goto EXIT;
   }
 
// get the meta data using oiMetaGetDefaultMeta
   if (dstat = oiMetaGetDefaultMeta(&dftMeta))
   {
      goto EXIT;
   }
 
// get the number of items selected using low_set_size
   size = low_set_size(SelectedItems);
 
// loop through each of the selected items
   for (i=0; i<size; i++)
   {
 
      /* get one of the items using low_set_get */
      item = (ObjectPtr)low_set_get(SelectedItems, i);
 
      /* get the class name of the item using objGetClass */
      if (dstat = objGetClass(item, &itemClass))
      {
          goto EXIT;
      }
 
      /* get all attributes for that class using metaGetAllClassAttributes */
      if (dstat = metaGetAllClassAttributes(dftMeta, itemClass, &itemAttrs))
      {
          goto EXIT;
      }
 
      /* count the number of attributes using low_set_size */
      aSize = low_set_size(itemAttrs);
 
      /* loop through each of the attributes */
      for (ia = 0; ia < aSize; ia++)
      {
  /* get one of the attributes using low_set_get */
         attrName = (string)low_set_get(itemAttrs, ia);
 
  /* get displayed name for the attribute using metaGetPromptFromTag */
         if (dstat = metaGetPromptFromTag(dftMeta, attrName, &attrPrompt))
         {
             goto EXIT;
         }
 
  /* get attribute type using metaGetAttributeTypes       */
  /* variables type a_type and a_dtype are declared above */
         if (dstat = metaGetAttributeTypes(dftMeta, attrName, &a_type, &a_dtype))
         {
             goto EXIT;
         }
 
  /* if I can handle this attribute type */
  if (nlsStrCmp(a_type, a_dtype))
  {
    /* get value for attribute */
           if(dstat = objGetAttribute(item, attrName, &attrValue))
           {
               goto EXIT;
           }
 
           /* print attribute name and value */
           if(attrValue != NULL) fprintf (file," Attribute:%s  ,Value:%s\n", attrPrompt, attrValue);
  }
      }  /* end for each attribute */
      fprintf (file,"\n===== End of Object =====\n");
   }    /* end for each select item */
 
   fprintf(file,"\n----------------\nEnd of Report\n---------------\n");
   fclose (file);
  
   /*********************************************/
   /*  Advanced Exercises                       */
   argv[0] = "notepad";
   argv[1] = outfile_name;
   argv[2] = NULL;
   osExecuteAsync(NULL, NULL, "notepad", argv);
   /*  End of Advanced Exercises                */
  
CLEANUP:
 
EXIT:
   if (dstat != OKAY)
      uiShowFatalError(dstat, WHERE);
   return (dstat);
}
原文地址:https://www.cnblogs.com/hcfalan/p/422510.html