如何在循环中跟踪对象和对象历史信息

how to keep track of object and object history information in a loop

我正在编写一个 DXL 脚本来从所有对象中提取历史信息,并将一些历史参数写入 DOORS 模块中的其他属性(列)。我从 DXL 参考手册(修订版 9.6,第 333 页附近)中的示例脚本开始,它只是将信息打印到 DXL 编辑器中 window。我试图添加一些代码来写入属性 _Reviewer——见下文。编写的代码着眼于当前选定的对象,而不是当前 h 历史记录所属的对象。传递给函数 print 的最安全变量是什么,以便我可以访问所需的对象并写入其 _Reviewer 属性?

// history DXL Example
/*   from doors  manual  
Example history DXL program.
Generate a report of the current Module's
history.
*/
// print a brief report of the history record
// hs     is a variable of type HistorySession
// module      is a variable of type Module

void print(History h) {
HistoryType ht = h.type
print h.author "\t" h.date "\t" ht "\t"
//next 3 lines are the code I added to the manual's example 
Buffer authortmp = create;
authortmp =  h.author "\t" h.date "\t" ht "\t"
 (current Object)."_Reviewer" = authortmp; 

// other code from original deleted
}

// Main program
History h
print "All history\n\n"
for h in current Module do print h
print "\nHistory for current Object\n\n"
for h in current Object do print h
print "\nNon object history\n\n"
for h in top current Module do print h

我想您不仅要为一个对象而且要为模块的所有对象设置 _Reviewer 属性。因此,您将对所有对象进行循环,对于每个对象,您将对其每个历史条目进行循环。

所以,主循环就像

Module m = current
string sHistoryAttributeName = "_Reviewer"
if (null m) then {infoBox "Open this script from a module";halt)
// […]add more code to check whether the attribute "_Reviewer" already exists in the current module and whether the module is open in edit mode
Object o
for o in entire m do {
  if isDeleted(o) then continue // deleted objects are not of interest
  // perhaps there are more objects that are not of interest. add relevant code here
  if (!canModify o.sHistoryAttributeName) then {warn "cannot modify history entry for object " (identifier o) "\n"; continue}
  Buffer bContentOfReview = create
  History h
  for h in o do {
    bContentOfReview += getHistoryContent(h) "\n"
  }
  o.sHistoryAttributeName = sContentOfReview
  delete bContentOfReview
}
save m

并且您的函数 getHistoryContent 将类似于您的函数 void print (History h),只是您将 return 一个字符串而不是打印历史条目。像

string getHistoryContent (History h) {
  HistoryType ht = h.type
  string sReturnValue = h.author "\t" h.date "\t" ht ""
  return sReturnValue
}

一个附加提示:您写了 "into other attributes (columns)"。上述解决方案适用于持久属性。取而代之的是,您可能希望在视图中将信息显示为 DXL 布局列或 DXL 属性——这两种可能性的优点是信息或多或少始终是最新的,但具有持久属性只有在您 运行 脚本之后,信息才会是最新的。另请注意,此方法只会为您提供自上次基线以来的更改。如果你需要更多,问题会更复杂。请参阅 Rational DXL 论坛或 google 以获取更复杂的显示历史条目的解决方案

//编辑:删除字符串连接中的拼写错误,使用 Buffer insted