This utility allows you to export attribute definitions from the current Module to a CSV file. The export include all the attribute definition properties and access rights.
// Export Attributes /* Tony Goodman Initial Version */ pragma runLim, 0 DB dbMain = null DBE dbeFileName = null Module m = null string outputFile = "" Buffer buf = create Buffer buf2 = create /********************** replaceQuotes *********************/ string replaceQuotes(string s) { int i = 0 setempty(buf2) for (i=0;i<length(s);i++) { if (s[i] == '"') { buf2 += "'" } else { buf2 += s[i:i] } } return(stringOf(buf2)) } /***************** printAccess *********************/ string getAccess(AccessRec ar) { string r = ((read ar) ? "R" : "") string m = ((modify ar) ? "M" : "") string c = ((create ar) ? "C" : "") string d = ((delete ar) ? "D" : "") string a = ((control ar) ? "A" : "") string accessStr = r m c d a "" if (null accessStr) { accessStr = "None" } return(accessStr) } /****************************** getAccessVal ******************************/ string getAccessVal(AttrDef ad) { AccessRec ar = null bool isInherited = false string defaultPerms = "" setempty(buf) isAccessInheritedVal(m, ad, isInherited) if (isInherited) { buf += "[Inherited]\n" } for ar in all values ad do { if (null username(ar)) { // store the string, not the access record, for processing later. // access records cannot be stored in variables and then used outside // of the loop - not sure why. just doesn't work defaultPerms = "Everyone Else (" getAccess(ar) ")\n" } else { buf += username(ar) " (" getAccess(ar) ")\n" } } buf += defaultPerms return(stringOf(buf)) } /****************************** getAccessDef ******************************/ string getAccessDef(AttrDef ad) { AccessRec ar = null bool isInherited = false string defaultPerms = "" setempty(buf) isAccessInheritedDef(m, ad, isInherited) if (isInherited) { buf += "[Inherited]\n" } for ar in all ad do { if (null username(ar)) { // store the string, not the access record, for processing later. // access records cannot be stored in variables and then used outside // of the loop - not sure why. just doesn't work defaultPerms = "Everyone Else (" getAccess(ar) ")\n" } else { buf += username(ar) " (" getAccess(ar) ")\n" } } buf += defaultPerms return(stringOf(buf)) } /********************** doExport *********************/ void doExport(DB db) { AttrDef ad = null AttrType at = null string existsForObject = "" string existsForModule = "" string inheritValue = "" string defVal = "" AttrBaseType abt = null string isDxl = "" string hasHistory = "" string hasBars = "" string hasDates = "" string minVal = "" string maxVal = "" string isMulti = "" string accessDef = "" string accessVal = "" string desc = "" Stream st = null Buffer enumerations = create int enumSize = 0 int i = 0 bool isHidden = false bool isSystem = false outputFile = get(dbeFileName) st = write(outputFile) if (null st) { infoBox("failed to open file for writing: " outputFile) return } st << "Name," st << "Description," st << "Type," st << "Exists For Object," st << "Exists For Module," st << "Generates History," st << "Affects Change Bars," st << "Affects Change Dates," st << "DXL Attribute," st << "Inherits Value," st << "Default Value," st << "Base Type," st << "Enumerations," st << "Multi Valued," st << "Min Value," st << "Max Value," st << "Access Definition," st << "Access Value\n" for ad in m do { setempty(enumerations) isSystem = ad.system if (ad.system) continue isHidden = ad.hidden if (ad.hidden) continue if (ad.module) { existsForModule = "Y" } else { existsForModule = "" } if (ad.object) { existsForObject = "Y" } else { existsForObject = "" } if (ad.inherit) { inheritValue = "Y" } else { inheritValue = "" } defVal = "" if (ad.defval) { defVal = plainText(ad.defval) } at = ad.type abt = at.type isMulti = "" if (abt == attrEnumeration) { if (ad.multi) { isMulti = "Y" } enumSize = at.size for (i = 0; i < enumSize; i++) { enumerations += at.strings[i] "\n" } } if (ad.dxl) { isDxl = "Y" } else { isDxl = "" } if (!ad.nohistory) { hasHistory = "Y" } else { hasHistory = "" } if (!ad.nochanges) { hasDates = "Y" } else { hasDates = "" } if (!ad.nobars) { hasBars = "Y" } else { hasBars = "" } minVal = "" maxVal = "" if (abt == attrInteger) { if (at.minValue) { minVal = (int at.minValue) "" } if (at.maxValue) { maxVal = (int at.maxValue) "" } } else if (abt == attrDate) { if (at.minValue) { minVal = (Date at.minValue) "" } if (at.maxValue) { maxVal = (Date at.maxValue) "" } } else if (abt == attrReal) { if (at.minValue) { minVal = (real at.minValue) "" } if (at.maxValue) { maxVal = (real at.maxValue) "" } } accessDef = getAccessDef(ad) accessVal = getAccessVal(ad) st << "\"" ad.name "\"," st << "\"" (replaceQuotes(ad.description)) "\"," st << "\"" ad.typeName "\"," st << "\"" existsForObject "\"," st << "\"" existsForModule "\"," st << "\"" hasHistory "\"," st << "\"" hasBars "\"," st << "\"" hasDates "\"," st << "\"" isDxl "\"," st << "\"" inheritValue "\"," st << "\"" defVal "\"," st << "\"" abt "\"," st << "\"" stringOf(enumerations) "\"," st << "\"" isMulti "\"," st << "\"" minVal "\"," st << "\"" maxVal "\"," st << "\"" accessDef "\"," st << "\"" accessVal "\"\n" } st << "Exported from DOORS module " fullName(m) " on " stringOf(dateOf(intOf(today)), "dd MMMM yyyy") "\n" close(st) infoBox("Export complete!") release(dbMain) } /********************** buildDialog *********************/ void buildDialog() { dbMain = create(m, "Export Attributes to CSV", styleCentered) label(dbMain, "This utility exports attribute details to a CSV file.\n\n") dbeFileName = fileName(dbMain, "Export to:", "U:\\" name(m) ".csv", "*.csv", "CSV Files", false) apply(dbMain, "Export", doExport) realize(dbMain) block(dbMain) destroy(dbMain) dbMain = null } /********************* exportAttributes **********************/ void exportAttributes() { m = current Module buildDialog() } exportAttributes()