Hello!
I have a problem with the attached DXL script. This script is an advanced version of 'Link By Attribute' which has a few useful properties, It was written by member 'roybond' back in 2008.
I tried running this script on DOORS 9.5. In general it works, however it doesn't just link an object to the object number specified in the text field but also to objects that use digits within that. For example:
Let's say Object 1 in my source module should be linked to object 9876 in the target module. The text attribute contains '9876'. Now what the script does is linking Obj 1 to Obj 9876 in the target module. But it also links Obj 1 to Objects 9, 8, 7, 6, 98, 87, 76, 987 and 876, i.e. it seems to treat the individual digits as numbers.
My guess is that this is probably because the DOORS version I'm using is much newer and some functions may have changed since the DOORS version that was current back in 2008 when the script was written. Here's the code:
//
/*
*************************************************************************
*
* Name: Advanced Link By Attribute
*
* Description: This utility will allow the linking of objects based upon
* the matching of contents of any Object Atrributes or the
* matching of Attributes to data in a cross reference list.
*
* Notes : If not using Xref List, tool assumes only one
* entry in Target Attribute (eg. Object PID).
*
*
*
*************************************************************************
*
* Date Rev Author Change Descption
*
* 03/01/08 001 RDBond Initial Release
*
*
*************************************************************************
*/
// **********************************************************************************************
// Constant and Variable declarations
DB lnkByAttrDB
DBE browseButton1, browseButton2, listSprtr
DBE srcAttrDBE, tgtFmodDBE, tgtLmodDBE, tgtAttrDBE, xRefList
DBE toggleList
Module m = current
Module m2 = null
// **********************************************************************************************
// Functions and Procedures
// index: Returns the starting position of string t in string s
// or (-1) if string t is not found in string s.
int index(string t, string s) {
int ls = length s
int lt = length t
int i,j,k
for (i=0; i<(ls-lt+1) ; i++) {
j=i
for (k=0; k<lt && s[j]==t[k]; k++) {j++}
if (k==lt) return i
}
return -1
}
// ----------------------------------------------------------------------------------------------
// found: Returns TRUE if A is found in B, else returns FALSE
bool found(string a, string b) {
int lb = length b
int la = length a
int i,j,k
for (i=0; i<(lb-la+1) ; i++) {
j=i
for (k=0; k<la && b[j]==a[k]; k++) {j++}
if (k==la) return true
}
return false
}
// ----------------------------------------------------------------------------------------------
void doFmodBrowse (DBE x) {
Folder fldr = current
string title = "Browse to Formal Module"
string prompt = "Browse to required Formal Module"
string srcMod = fnMiniExplorer(fldr, MINI_EXP_FORMAL_MODS, title, prompt)
if (!null srcMod) {
if (!null m2) {close m2}
set(tgtFmodDBE, srcMod)
m2 = read(srcMod,true)
empty (tgtAttrDBE)
string objAttrName2
int attr_index2 = 0
for objAttrName2 in m2 do {
insert (tgtAttrDBE, attr_index2, objAttrName2)
attr_index2++
}
set (tgtAttrDBE,0)
active tgtAttrDBE
}
setFocus (browseButton1)
}
// ----------------------------------------------------------------------------------------------
void doLmodBrowse (DBE x) {
Folder fldr = current
string title = "Browse to Link Module"
string prompt = "Browse to required Link Module"
string srcMod = fnMiniExplorer(fldr, MINI_EXP_LINK_MODS, title, prompt)
set(tgtLmodDBE, srcMod)
setFocus (browseButton2)
}
// ----------------------------------------------------------------------------------------------
void doIt (DB x) {
string frmAttr = get srcAttrDBE
string toAttr = get tgtAttrDBE
string lmName = get tgtLmodDBE
int sprtrVal = get listSprtr
string sprtrStr = ""
if (sprtrVal == 0) {
sprtrStr = "\t"
} else {
sprtrStr = ","
}
if (!null(frmAttr) && !null(m2) && !null(toAttr)) {
bool byXrefList = get toggleList
if (byXrefList) {
Buffer nullBuffer = create
Buffer b = create
string refTxt = get xRefList
string tempPath = getenv("Temp")
string tempFile = tempPath "\\xRefList.txt"
Stream out = write tempFile
out << refTxt
close out
Stream xRefFile = read tempFile
while (!end xRefFile) {
xRefFile >= b
string xRefLine = stringOf(b)
if (xRefLine != "") {
int i = index (sprtrStr,xRefLine)
string frmText = xRefLine[0:i-1]
string toText = xRefLine [i+1:]
Object o1
for o1 in all m do {
string frmAttrTxt = o1.frmAttr
if (found(frmText,frmAttrTxt)) {
Object o2
for o2 in all m2 do {
string toAttrTxt = o2.toAttr
if (found(toText,toAttrTxt)) {
o1 -> lmName -> o2
}
}
}
}
}
}
} else {
Object o1
for o1 in all m do {
string frmAttrTxt = o1.frmAttr
Object o2
for o2 in all m2 do {
string toAttrTxt = o2.toAttr
if (found(toAttrTxt,frmAttrTxt)) {
o1 -> lmName -> o2
}
}
}
}
}
}
// ----------------------------------------------------------------------------------------------
void doToggle (DBE X) {
bool togVal = get toggleList
if (togVal) {
active (xRefList)
} else {
inactive (xRefList)
}
}
// **********************************************************************************************
// Main Body of DXL Script
string objAttrName
int attr_index = 0
for objAttrName in m do {
attr_index++
}
string attr_array[attr_index]
attr_index = 0
for objAttrName in m do {
attr_array[attr_index] = objAttrName
attr_index++
}
lnkByAttrDB = create "Advanced Link By Attribute"
srcAttrDBE = choice (lnkByAttrDB,"Select Source Attribute:",attr_array,0,50,false)
tgtFmodDBE = field (lnkByAttrDB,"Target Module:","Browse to Target Formal Module...",50)
browseButton1 = button(lnkByAttrDB,"Browse",doFmodBrowse)
browseButton1->"left"->"flush"->tgtFmodDBE
browseButton1->"top"->"aligned"->tgtFmodDBE
string nullArray[1]
nullArray[0] = "Null"
tgtAttrDBE = choice (lnkByAttrDB,"Select Target Attribute:",nullArray,0,50,false)
tgtLmodDBE = field (lnkByAttrDB,"Link Module:","Browse to Target Link Module...",50)
browseButton2 = button(lnkByAttrDB,"Browse",doLmodBrowse)
browseButton2->"left"->"flush"->tgtLmodDBE
browseButton2->"top"->"aligned"->tgtLmodDBE
inactive tgtAttrDBE
toggleList = toggle (lnkByAttrDB,"Link by Cross reference List",false)
xRefList = text(lnkByAttrDB, "Paste cross-reference list here...","",250,false)
string sprtrList[] = {"Tab", "Comma"}
listSprtr = radioBox (lnkByAttrDB, "List separator :", sprtrList, 0)
//realize lnkByAttrDB
//inactive tgtAttrDBE
apply(lnkByAttrDB,"Apply",doIt)
realize lnkByAttrDB
set (toggleList,doToggle)
show lnkByAttrDB
show lnkByAttrDB
It would be great if someone with better DXL knowledge than mine (which is very limited) please look at the script? Maybe there problem isn't big and easy to fix.
Thanks,
Ben Turnschuh - Thu Aug 31 10:38:23 EDT 2017 |