Hello Everyone,
I found the existing code here in the DXL Forum.Thanks a ton for this existing code which gets me going forward.
I have edited and enhanced the code(added few functions) to suit my requirement. I got stuck up when you select the RTF File to import back to DOORS.
I am getting the following error here in this function:
importRTF(strFileforImport, dbeModuleList, true, true) // Imports into the selected module
-E- DXL: <Line:392> incorrect arguments for function (importRTF)
-I- DXL: All done. Errors reported: 1. Warnings reported: 0.
Code:
// sets the time-out interval : The time-out is suppressed if zero.
pragma runLim,0
string promptOpts[] = { "Yes", "Yes to all", "No", "Cancel" }
string modeOpts[] = { "Edit" }
string modTypeOptions[] = {"Formal"}
string dummyList[] = {}
Project currProj = null
Module currMod = null
bool yesToAll = false
int selectedModType = 0
DB dbRunAll = null
DBE dbeModuleList = null
DBE dbeIncludeFile = null
DBE dbeDxlScript = null
DBE dbeModeOptions = null
DBE dbeRun = null
DBE dbeSelectAll = null
DBE dbeClear = null
DBE selectedMods = null
DBE dbeModTypes = null
/******************************************************************************
fillModsList
******************************************************************************/
int fillModsList(DBE dbeList)
{
int i = 0
int len = 0
string modName = ""
Item it
empty(dbeList)
for it in current Project do
{
modName = fullName(it)
if (null module modName)
{
continue
}
if ((type module modName) != modTypeOptions[selectedModType])
{
continue
}
insert(dbeList, i, modName)
i++
}
return noElems dbeList
}
/******************************************************************************
runScript
******************************************************************************/
bool runScript(string dxlScript, Module m)
{
if (null m)
{
return true
}
if (!yesToAll)
{
int ans = query("Run script on module '" fullName(m) "'?", promptOpts)
if ( promptOpts[ans] == "Cancel" )
{
return false
}
if ( promptOpts[ans] == "No" )
{
return true
}
if ( promptOpts[ans] == "Yes to all" )
{
yesToAll = true
}
}
Module oldCurr = current
(current ModuleRef__) = m
eval_(dxlScript)
if (!null oldCurr)
{
(current ModuleRef__) = oldCurr
}
return true
}
/******************************************************************************
doSelect
******************************************************************************/
void doSelect(DBE dbe)
{
int nm = 0
string s = ""
for s in dbeModuleList do
{
nm++
}
if ( nm == 0 )
{
inactive dbeRun
}
else
{
active dbeRun
}
set(selectedMods, nm "/" noElems(dbeModuleList) "")
}
/******************************************************************************
doRunScript
******************************************************************************/
void doRunScript(DB db)
{
string incFile = ""
string dxlText = ""
string dxlScript = ""
string res = ""
Module thisMod = null
bool runOK = true
string mn = ""
bool opened = false
int n = 0
incFile = get(dbeIncludeFile)
dxlText = get(dbeDxlScript)
if (incFile == doorsHome "\\lib\\dxl")
{
incFile = ""
}
if (incFile != "")
{
Stat st = create(incFile)
if ( null st )
{
warningBox "No such file '" incFile "'."
return
}
if ( !regular(st) )
{
warningBox "The name '" incFile "' is not a file."
return
}
}
if (incFile != "")
{
dxlScript = "#include <" incFile ">\n"
}
dxlScript = dxlScript dxlText
res = checkDXL(dxlScript)
if (res != "")
{
warningBox("Errors in DXL:\n" res)
return
}
// get module mode
int mode = get(dbeModeOptions)
// count items
int numMods = 0
for mn in dbeModuleList do numMods++
progressStart(dbRunAll, "Running script on selected modules", "Initialising...", numMods)
yesToAll = false
for mn in dbeModuleList do
{
if (!runOK) break
opened = false
// open module
progressMessage("Opening module '" mn "' ...")
if (!open(module mn))
{
opened = true
}
if (modeOpts[mode] == "Edit")
{
thisMod = edit(mn, false)
}
else
{
warningBox "To import you need to open the module in Exclusive Edit"
}
if (null thisMod)
{
infoBox("Failed to open module " mn)
return
}
progressMessage("Running script on module '" mn "' ...")
runOK = runScript(dxlScript, thisMod)
progressStep(n++)
// save and close module
progressMessage("Closing module '" mn "' ...")
if (isEdit(thisMod))
{
if(confirm"Imported! Do you want to save the module?")
{
save(thisMod)
}
}
if (opened)
{
close(thisMod)
}
}
progressStop()
}
/******************************************************************************
doSelectModTypes
******************************************************************************/
/*void doSelectModTypes(DBE dbe)
{
selectedModType = get(dbeModTypes)
fillModsList(dbeModuleList)
}*/
/******************************************************************************
Browse RTF file from the directory
******************************************************************************/
//DB dbMain
DBE dbeFile
void doOk(DB db)
{
string sFile = get(dbeFile)
infoBox(dbRunAll, "You selected the file " sFile )
}
/******************************************************************************
doSelectIncPartners
******************************************************************************/
void doSelectIncPartners(DBE dbe)
{
fillModsList(dbeModuleList)
}
/******************************************************************************
doSelectAllMods
******************************************************************************/
void doSelectAllMods(DBE dbe)
{
int i
for i in 0:noElems(dbeModuleList)-1 do
{
set(dbeModuleList, i, true)
}
doSelect(dbeModuleList)
}
/******************************************************************************
doClearMods
******************************************************************************/
void doClearMods(DBE dbe)
{
int i
for i in 0:noElems(dbeModuleList)-1 do
{
set(dbeModuleList, i, false)
}
doSelect(dbeModuleList)
}
/******************************************************************************
contextOK
******************************************************************************/
bool contextOk()
{
currProj = current Project
if (null currProj)
{
infoBox("Please run this script from within a project")
return false
}
return true
}
/******************************************************************************
MAIN
******************************************************************************/
if (!contextOk)
{
halt
}
dbRunAll = create("Import of RTF document, EXCEL to DOORS modules")
label(dbRunAll, "#include:")
dbeIncludeFile = fileName(dbRunAll, doorsHome "\\lib\\dxl", "*.dxl;*.inc", "DXL files")
dbeDxlScript = text(dbRunAll, "DXL script:", "", 300, 100, false)
//To select the modules with the desired options
dbeModeOptions = radioBox(dbRunAll, "Open modules in mode:", modeOpts, 0)
//dbeModTypes = radioBox(dbRunAll, "Module Type: " , modTypeOptions, 0)
dbeModuleList = multiList(dbRunAll, "Formal modules:", 300, 10, dummyList)
dbeSelectAll = button(dbRunAll, "Select all", doSelectAllMods)
beside(dbRunAll)
dbeClear = button(dbRunAll, "Clear", doClearMods)
selectedMods = field(dbRunAll, "# selected:", "", 4, true)
left(dbRunAll)
dbeRun = apply(dbRunAll, "Run", doRunScript)
realize dbRunAll
inactive(dbeRun)
//Calling the BROWSE button function to select the required file to be imported
dbeFile = fileName(dbRunAll, "Select the file to import back to DOORS", "")
ok(dbRunAll, doOk)
//Checking whether the slected DB has RTF file selected or not
if (get(dbeFile) != null)
{
string strFileforImport = get dbeFile
importRTF(strFileforImport, dbeModuleList, true, true) // Imports into the selected module
print "Success!!\n"
infoBox "Success!! Importing successful"
}
set(dbeModuleList, doSelect, doSelect)
//set(dbeModTypes)
if (fillModsList(dbeModuleList) == 0)
{
inactive dbeRun
insert(dbeModuleList, 0, "(No modules)")
}
block(dbRunAll)
I would like to enhance the tool for Importing to EXCEL too after rectifying the error.
Anyone please help me out with your suggestion.
KBSri - Mon Mar 17 01:56:55 EDT 2014 |