问题
I'm writing a DXL script to extract history information from all objects and write some of the history parameters into other attributes (columns) in the DOORS module. I started out with the example script in the DXL Reference Manual (rev 9.6, near page 333), which just prints the information into the DXL editor window. I tried to add some code to write to the attribute _Reviewer
-- see below. The code as written looks at the currently selected object rather than the one to which the current h
history belongs to. What's the safest variable to pass into the function print
so I can access the desired object and write to its _Reviewer
attribute?
// 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
回答1:
I imagine that you want to set the _Reviewer attribute not only for one object but rather for all objects of the module. So you will have a loop over all objects and for each object you will have a loop over each of its history entries.
So, the main loop would be like
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
and your function getHistoryContent
would be similar to your function void print (History h)
, only that you will return a string instead of printing the history entry. Something like
string getHistoryContent (History h) {
HistoryType ht = h.type
string sReturnValue = h.author "\t" h.date "\t" ht ""
return sReturnValue
}
One additional hint: you wrote "into other attributes (columns)". The above solution is for persistent attributes. Instead of this, you might want to show the information in a view as a DXL Layout column or or as a DXL attribute -- both possibilities have the advantage that the information is more or less always up to date, but with a persistent attribute the information will only be current after you run the script. Also note that this approach will only give you the changes since the last baseline. If you need more, the problem will be more complex. See the Rational DXL forum or google for more complex solutions of showing history entries
//Edit: removed typo in string concatenation, use Buffer insted
来源:https://stackoverflow.com/questions/41618168/how-to-keep-track-of-object-and-object-history-information-in-a-loop