pythonscriptingmappingibm-doors

Importing text file in DXL script?


I am looking for a solution which helps to import a text file in the code, I am doing this to remove the hard coded values. Instead, I would want to call a text file and read values, which does the mapping. Making the code independent of projects. Any Idea how to do it ?

OleAutoObj createWrapperObj(Object obj) {
OleAutoArgs args = create
OleAutoObj wrapper = null
print oleMethod(d2e, "CreateObjectWrapper", args, wrapper)

olePut(wrapper, "ModuleName", name(m))
olePut(wrapper, "aObjectType", unicodeString(obj."aObjectType"))
olePut(wrapper, "TestDescription", unicodeString(obj."Object Short Text"))
olePut(wrapper, "TestPictureName", unicodeString(obj."ID"))
olePut(wrapper, "TestFocus", unicodeString(obj."Test_Focus"))

return wrapper }

Thank you


Solution

  • Create a file with each parameter you want to read on its own line. Here is an example of how to read the file.

    string filename="C:/parameters.txt" // can also use relative paths
    Stream input = read filename
    string param
    input >> param //this reads the first line into the string param
    
    //... continue to input into each variable
    //... and then when all done
    
    close input
    

    I think this is what you are asking for.