Topic
  • 5 replies
  • Latest Post - ‏2014-03-17T14:54:03Z by adevicq
KBSri
KBSri
104 Posts

Pinned topic Import of RTF Files and EXCEL back to DOORS Tool

‏2014-03-17T05:56:55Z |

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.

 

  • adevicq
    adevicq
    154 Posts

    Re: Import of RTF Files and EXCEL back to DOORS Tool

    ‏2014-03-17T08:31:18Z  

    Hi,

    The function requires a module and not a DBE for the param #2.

    Regards,

    Alain

     

  • KBSri
    KBSri
    104 Posts

    Re: Import of RTF Files and EXCEL back to DOORS Tool

    ‏2014-03-17T09:15:42Z  
    • adevicq
    • ‏2014-03-17T08:31:18Z

    Hi,

    The function requires a module and not a DBE for the param #2.

    Regards,

    Alain

     

    Yes I know but is there any alternative way to access the selected module by the user?

    The problem is that GUI allows the user to select the number of modules...!! Thats is why i need some suggestion on this.

    Updated on 2014-03-17T12:47:12Z at 2014-03-17T12:47:12Z by KBSri
  • adevicq
    adevicq
    154 Posts

    Re: Import of RTF Files and EXCEL back to DOORS Tool

    ‏2014-03-17T12:07:19Z  
    • KBSri
    • ‏2014-03-17T09:15:42Z

    Yes I know but is there any alternative way to access the selected module by the user?

    The problem is that GUI allows the user to select the number of modules...!! Thats is why i need some suggestion on this.

    Hi,

    You should loop through all the selected elements, retrieve the module name and edit the module to retrieve a handle to the module:

    string sName
    Module m
    sName = get(dbeModuleList, n) // n is the element index
    m = edit(sName)
    // then you can call importRTF
    

    Alain

    Updated on 2014-03-17T12:07:46Z at 2014-03-17T12:07:46Z by adevicq
  • KBSri
    KBSri
    104 Posts

    Re: Import of RTF Files and EXCEL back to DOORS Tool

    ‏2014-03-17T13:21:52Z  
    • adevicq
    • ‏2014-03-17T12:07:19Z

    Hi,

    You should loop through all the selected elements, retrieve the module name and edit the module to retrieve a handle to the module:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">string sName Module m sName = get(dbeModuleList, n) // n is the element index m = edit(sName) // then you can call importRTF </pre>

    Alain

    -E- DXL: <Line:399> incorrect arguments for function (importRTF)
    -I- DXL: All done. Errors reported: 1. Warnings reported: 0.


    //Checking whether the slected DB has RTF file selected or not

    if (get(dbeFile) != null)
    {
        string strFileforImport = get dbeFile

        string sName = ""

        Module mod

        int n

        sName = get(dbeModuleList, n) // n is the element index
        mod = edit(sName)

        importRTF(strFileforImport, sName, true, true) // Imports into the current module
    }

        print "Success!!\n"
        infoBox "Success!! Importing successful"

    Still I am getting the same error in this function.

    Updated on 2014-03-17T13:25:48Z at 2014-03-17T13:25:48Z by KBSri
  • adevicq
    adevicq
    154 Posts

    Re: Import of RTF Files and EXCEL back to DOORS Tool

    ‏2014-03-17T14:54:03Z  
    • KBSri
    • ‏2014-03-17T13:21:52Z

    -E- DXL: <Line:399> incorrect arguments for function (importRTF)
    -I- DXL: All done. Errors reported: 1. Warnings reported: 0.


    //Checking whether the slected DB has RTF file selected or not

    if (get(dbeFile) != null)
    {
        string strFileforImport = get dbeFile

        string sName = ""

        Module mod

        int n

        sName = get(dbeModuleList, n) // n is the element index
        mod = edit(sName)

        importRTF(strFileforImport, sName, true, true) // Imports into the current module
    }

        print "Success!!\n"
        infoBox "Success!! Importing successful"

    Still I am getting the same error in this function.

    OK.

    With more details:

        int i
        for i in 0:noElems(dbeModuleList)-1 do {
            if (!selected(dbeModuleList, i))
                continue
            string sName = get(dbeModuleList, i)
            Module m = edit(sName, true)
            if (m == null)
                continue
            importRTF(strFileforImport, m, true, true) // Imports into the selected module
        }
    
        print "Success!!\n"
        infoBox "Success!! Importing successful"
    

    regards