Find a word usind DXL script in the microsoft word document attached as OLE

Hi,

we have very very huge requirement document which contains 60% of OLE requirements. All the OLEs are microsoft word object. If i want to find some keyword in the entire document it shows up only for non OLE IDs, means It will not find in inside the OLE microsoft word object. I want to write a DXL script that can find a word in microsoft OLE word object. Anyone pls help me out with some example. Thank you very much

Regards,
Elam
Elamkumaran - Mon Apr 25 11:06:29 EDT 2011

Re: Find a word usind DXL script in the microsoft word document attached as OLE
mcnairk - Tue Apr 26 10:47:50 EDT 2011

Elam,

I have the exact same need as you, and previous posted here in the following thread.

http://www.ibm.com/developerworks/forums/thread.jspa?threadID=313869&tstart=0

If the above link doesn't work, email me and I will send you a summary. I got some really useful replies, but didn't follow up due to lack of resources to work on it.

I am not sure what the output of this search tool would be: would it output the Word paragraph that the string it was found in (ideally with the string highlighted), or just the module and object ID (and maybe number of hits).

Let me know if you make any progress on this.

Ken.

Re: Find a word usind DXL script in the microsoft word document attached as OLE
Elamkumaran - Tue Apr 26 11:45:25 EDT 2011

mcnairk - Tue Apr 26 10:47:50 EDT 2011
Elam,

I have the exact same need as you, and previous posted here in the following thread.

http://www.ibm.com/developerworks/forums/thread.jspa?threadID=313869&tstart=0

If the above link doesn't work, email me and I will send you a summary. I got some really useful replies, but didn't follow up due to lack of resources to work on it.

I am not sure what the output of this search tool would be: would it output the Word paragraph that the string it was found in (ideally with the string highlighted), or just the module and object ID (and maybe number of hits).

Let me know if you make any progress on this.

Ken.

Hai,
Thanks for your reply. I couldn't able to find any search tool which you mentioned in your reply. I am new to DXL. Please let me know step by step procedure to find a string in Word OLE object. Thanks You

Re: Find a word usind DXL script in the microsoft word document attached as OLE
Mathias Mamsch - Wed Apr 27 08:42:10 EDT 2011

Elamkumaran - Tue Apr 26 11:45:25 EDT 2011
Hai,
Thanks for your reply. I couldn't able to find any search tool which you mentioned in your reply. I am new to DXL. Please let me know step by step procedure to find a string in Word OLE object. Thanks You

Elam, if you are new to DXL you will probably have a lot of difficulties to face with implementing such a solution. You need to know about OLE objects and how to handle them, how to recognize embedded Word OLE objects, how to activate them and then you need to know the automation interface of Word well enough to come up with a script that will do a "find" in the word document and extract the result. So this is pretty hard stuff for a DXL newbie, I guess unless somebody is willing to publish a function for that (and I am sure there are several people that already implemented such a function, unfortunately I am not one of them) you will need to start reading a lot of info. Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Find a word usind DXL script in the microsoft word document attached as OLE
SystemAdmin - Wed Apr 27 12:10:09 EDT 2011

Elamkumaran - Tue Apr 26 11:45:25 EDT 2011
Hai,
Thanks for your reply. I couldn't able to find any search tool which you mentioned in your reply. I am new to DXL. Please let me know step by step procedure to find a string in Word OLE object. Thanks You

As an alternative, consider a typical practice in document management systems.

In document management systems, lots of content is OCRed (imported with optical character recognition). For each record, the image itself (or proprietary document) is stored plus some search meta-data is stored.

If you add a text "Search Meta-Data" attribute to your DOORS module schema, you can store the "plain text" content of your OLE objects. This way search is fast and the user does not necessarily need Word to search. The user will need Word to open the OLE object to see inside.

For OLE Word.Document you can store the "plain text" of the Word document. I'm talking about content that you would get if (from Word) you did from the menu

File \ Save As

With Save As Type = Plain Text (*.txt)

For other OLE objects (e.g., pictures) you can store some useful search keywords so users can find a given picture. An example would be "ABC Company Organizational Chart".

The "Search Meta-Data" attribute gets populated at insert or update time so search is fast.

Re: Find a word usind DXL script in the microsoft word document attached as OLE
mcnairk - Wed Apr 27 12:49:46 EDT 2011

SystemAdmin - Wed Apr 27 12:10:09 EDT 2011
As an alternative, consider a typical practice in document management systems.

In document management systems, lots of content is OCRed (imported with optical character recognition). For each record, the image itself (or proprietary document) is stored plus some search meta-data is stored.

If you add a text "Search Meta-Data" attribute to your DOORS module schema, you can store the "plain text" content of your OLE objects. This way search is fast and the user does not necessarily need Word to search. The user will need Word to open the OLE object to see inside.

For OLE Word.Document you can store the "plain text" of the Word document. I'm talking about content that you would get if (from Word) you did from the menu

File \ Save As

With Save As Type = Plain Text (*.txt)

For other OLE objects (e.g., pictures) you can store some useful search keywords so users can find a given picture. An example would be "ABC Company Organizational Chart".

The "Search Meta-Data" attribute gets populated at insert or update time so search is fast.

This is a great idea! When you say "The "Search Meta-Data" attribute gets populated at insert or update time", how do you suggest this would be accomplished? Through a DOORS trigger or a Word macro which runs when you "Close and Return" from Word to DOORS?

Re: Find a word usind DXL script in the microsoft word document attached as OLE
llandale - Wed Apr 27 13:24:23 EDT 2011

SystemAdmin - Wed Apr 27 12:10:09 EDT 2011
As an alternative, consider a typical practice in document management systems.

In document management systems, lots of content is OCRed (imported with optical character recognition). For each record, the image itself (or proprietary document) is stored plus some search meta-data is stored.

If you add a text "Search Meta-Data" attribute to your DOORS module schema, you can store the "plain text" content of your OLE objects. This way search is fast and the user does not necessarily need Word to search. The user will need Word to open the OLE object to see inside.

For OLE Word.Document you can store the "plain text" of the Word document. I'm talking about content that you would get if (from Word) you did from the menu

File \ Save As

With Save As Type = Plain Text (*.txt)

For other OLE objects (e.g., pictures) you can store some useful search keywords so users can find a given picture. An example would be "ABC Company Organizational Chart".

The "Search Meta-Data" attribute gets populated at insert or update time so search is fast.

I was thinking along these lines as well, exporting the Word to a Text then searching the text. Storing that info in an attribute is even a better idea.

I cannot do it but surely someone here can export the embedded OLE to a temp text file, open the temp file and store in an attribute.

  • Louie

Re: Find a word usind DXL script in the microsoft word document attached as OLE
SystemAdmin - Wed Apr 27 14:36:06 EDT 2011

llandale - Wed Apr 27 13:24:23 EDT 2011
I was thinking along these lines as well, exporting the Word to a Text then searching the text. Storing that info in an attribute is even a better idea.

I cannot do it but surely someone here can export the embedded OLE to a temp text file, open the temp file and store in an attribute.

  • Louie

There are too many unknowns to suggest an optimum way to achieve this. Are these OLE Word.Document items of the linked or unlinked variety?

I'd make the policy:
If you insert an OLE Word.Document, you insert the plain text at that time.
If you change the Word doc, you fix the Search Metadata as well.

I suppose some exist already in DOORS. Just open them. Select All. Copy to clipboard. Save somewhere like a text editor (or notepad). Reselect and copy to clipboard. Paste into "Search Metadata" attribute.

For automation you could paste clipboard into the "Search Metadata" attribute and then run a DXL script to remove OLE Rich Text and undo Rich Text formatting.

You'll have to decide if the automation is worth it.

If the word documents exist externally, there are loads of options to start Winword via batch and specify a macro to run to save a copy as a text file. Search the web for "word command line run macro" and you'll get lots of help.

Re: Find a word usind DXL script in the microsoft word document attached as OLE
David_G_Bond - Wed Apr 27 15:12:50 EDT 2011

SystemAdmin - Wed Apr 27 14:36:06 EDT 2011
There are too many unknowns to suggest an optimum way to achieve this. Are these OLE Word.Document items of the linked or unlinked variety?

I'd make the policy:
If you insert an OLE Word.Document, you insert the plain text at that time.
If you change the Word doc, you fix the Search Metadata as well.

I suppose some exist already in DOORS. Just open them. Select All. Copy to clipboard. Save somewhere like a text editor (or notepad). Reselect and copy to clipboard. Paste into "Search Metadata" attribute.

For automation you could paste clipboard into the "Search Metadata" attribute and then run a DXL script to remove OLE Rich Text and undo Rich Text formatting.

You'll have to decide if the automation is worth it.

If the word documents exist externally, there are loads of options to start Winword via batch and specify a macro to run to save a copy as a text file. Search the web for "word command line run macro" and you'll get lots of help.

If you really do only have OLEs that are word documents, the following function should work. I hacked it down from a more complex version.
 

bool searchOleInObject(Object o, string sKeyword)
{
    OleAutoObj objDoc = null, objApp = null, objSelection = null, objFind = null
    bool bIsStatic
    bool bFoundKeyword = false
    bool bIsActivated = false
    string sErr, sName
    
    if (containsStaticOle(o."Object Text")) return(bFoundKeyword)
    if (containsUnregisteredOle(o."Object Text")) return(bFoundKeyword)
    if (oleCount(o."Object Text") < 1) return(bFoundKeyword)
    
    bIsActivated = oleActivate(o)
    if (!bIsActivated) return(bFoundKeyword)
    objDoc = oleGetAutoObject(o)
    if (null(objDoc))
    {
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objDoc, "Application", objApp)
    if (null(objApp))
    {
        if (!null(objDoc)) oleCloseAutoObject(objDoc)
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objApp, "Name", sName)
    if (!matches("Word", sName))
    {
        // not a word application, so close out and return
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objApp, "Selection", objSelection)
    oleGet(objSelection, "Find", objFind)
    oleMethod(objFind, "ClearFormatting")
    olePut(objFind, "Text", sKeyword)
    olePut(objFind, "MatchWholeWord", true)
    olePut(objFind, "Format", false)
    oleMethod(objFind, "Execute")
    oleGet(objFind, "Found", bFoundKeyword)
    oleDeactivate(o)
    
    if (!null(objDoc)) oleCloseAutoObject(objDoc)
    if (!null(objApp)) oleCloseAutoObject(objApp)
    if (!null(objSelection)) oleCloseAutoObject(objSelection)
    if (!null(objFind)) oleCloseAutoObject(objFind)
    return(bFoundKeyword)
}

 

 

  • David Bond

 

 

Re: Find a word usind DXL script in the microsoft word document attached as OLE
Elamkumaran - Sun May 01 11:54:06 EDT 2011

David_G_Bond - Wed Apr 27 15:12:50 EDT 2011

If you really do only have OLEs that are word documents, the following function should work. I hacked it down from a more complex version.
 

bool searchOleInObject(Object o, string sKeyword)
{
    OleAutoObj objDoc = null, objApp = null, objSelection = null, objFind = null
    bool bIsStatic
    bool bFoundKeyword = false
    bool bIsActivated = false
    string sErr, sName
    
    if (containsStaticOle(o."Object Text")) return(bFoundKeyword)
    if (containsUnregisteredOle(o."Object Text")) return(bFoundKeyword)
    if (oleCount(o."Object Text") < 1) return(bFoundKeyword)
    
    bIsActivated = oleActivate(o)
    if (!bIsActivated) return(bFoundKeyword)
    objDoc = oleGetAutoObject(o)
    if (null(objDoc))
    {
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objDoc, "Application", objApp)
    if (null(objApp))
    {
        if (!null(objDoc)) oleCloseAutoObject(objDoc)
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objApp, "Name", sName)
    if (!matches("Word", sName))
    {
        // not a word application, so close out and return
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objApp, "Selection", objSelection)
    oleGet(objSelection, "Find", objFind)
    oleMethod(objFind, "ClearFormatting")
    olePut(objFind, "Text", sKeyword)
    olePut(objFind, "MatchWholeWord", true)
    olePut(objFind, "Format", false)
    oleMethod(objFind, "Execute")
    oleGet(objFind, "Found", bFoundKeyword)
    oleDeactivate(o)
    
    if (!null(objDoc)) oleCloseAutoObject(objDoc)
    if (!null(objApp)) oleCloseAutoObject(objApp)
    if (!null(objSelection)) oleCloseAutoObject(objSelection)
    if (!null(objFind)) oleCloseAutoObject(objFind)
    return(bFoundKeyword)
}

 

 

  • David Bond

 

 

Thank you very much
David_G_Bond. it is working... :)

Re: Find a word usind DXL script in the microsoft word document attached as OLE
Elamkumaran - Mon May 02 11:20:55 EDT 2011

Elamkumaran - Sun May 01 11:54:06 EDT 2011
Thank you very much
David_G_Bond. it is working... :)

The previous example will search a word from all the OLE object. What if i want to search 'n' number of words from different OLE object, if the word is found then the same word should be pasted in text type attribute or any other attribute column.

Example:

DOORS_OBJ_ID: OLE word table --> contains following words --> "Find Word1", "Find Word2", "Find Word3" --> in attribute column{Find Word1
Find Word3
}

I want to search both Find Word1 and Find Word3 using one DXL script. If these words are found then both "Find Word1" and "Find Word3" should be pasted in attribute column. Please let me know what are the API calls i should use. Thanks

Regards,
Elam

Re: Find a word usind DXL script in the microsoft word document attached as OLE
Elamkumaran - Wed May 04 08:26:28 EDT 2011

New req.

Re: Find a word usind DXL script in the microsoft word document attached as OLE
David_G_Bond - Wed May 04 13:05:28 EDT 2011

Elamkumaran - Wed May 04 08:26:28 EDT 2011
New req.

If it were me I would modify the function to add as a parameter a skip list that has the words to search for and return a skip list of words found. The function can be modified to loop through the input list of words and add words to the return skip list as they are found.

  • David Bond

Re: Find a word usind DXL script in the microsoft word document attached as OLE
Elamkumaran - Wed May 04 13:49:33 EDT 2011

David_G_Bond - Wed May 04 13:05:28 EDT 2011
If it were me I would modify the function to add as a parameter a skip list that has the words to search for and return a skip list of words found. The function can be modified to loop through the input list of words and add words to the return skip list as they are found.

  • David Bond

Thanks Bond. Also can you pls tell me the method of writing a word into text type attribute column. example

ID || Object Text || Text type attribute

ID_1 Text.... Text1,
Text2

Re: Find a word usind DXL script in the microsoft word document attached as OLE
Elamkumaran - Wed May 04 13:53:40 EDT 2011

Elamkumaran - Wed May 04 13:49:33 EDT 2011
Thanks Bond. Also can you pls tell me the method of writing a word into text type attribute column. example

ID || Object Text || Text type attribute

ID_1 Text.... Text1,
Text2

Thanks Bond. Also can you pls tell me the method of writing a word into text type attribute column. example

ID || Object Text || Text type attribute

ID_1 || Text.... || Text1,

Text2

Text1 and Text2 in same object ID

Re: Find a word usind DXL script in the microsoft word document attached as OLE
David_G_Bond - Thu May 05 14:28:17 EDT 2011

Elamkumaran - Wed May 04 13:53:40 EDT 2011
Thanks Bond. Also can you pls tell me the method of writing a word into text type attribute column. example

ID || Object Text || Text type attribute


ID_1 || Text.... || Text1,

Text2

Text1 and Text2 in same object ID

I don't know your situation, so I don't know what approach is best for you. You indicate that this is a very large module with many OLEs. It may be best to use a scheduled task to run a script nightly to update the attribute in question. That way there is no slow-down for the user. You could use a layout dxl, but that might lead to slow response for that view. You might also consider a dxl attribute. Perhaps others can suggest what approach is best.

  • David Bond

Re: Find a word usind DXL script in the microsoft word document attached as OLE
llandale - Thu May 05 14:56:51 EDT 2011

David_G_Bond - Thu May 05 14:28:17 EDT 2011
I don't know your situation, so I don't know what approach is best for you. You indicate that this is a very large module with many OLEs. It may be best to use a scheduled task to run a script nightly to update the attribute in question. That way there is no slow-down for the user. You could use a layout dxl, but that might lead to slow response for that view. You might also consider a dxl attribute. Perhaps others can suggest what approach is best.

  • David Bond

Layout for this is out of the question, [1] you'd be exporting to word etc every time the DOORS module window changes, and it would change every time you export to word since the word window would cover the DOORS window. [2] you need to coordinate the column number with the DXL doing the searches. Attr-DXL would be tolerable, you'd spend time exporting to word only once per object per module, but only when that attr value is read (i.e. when you are running the Find DXL).

Batch run for update would be perhaps best, but I'd check the Last Modified Date of the object, and don't bother doing the Word update if the object hasn't changed since last update.

  • Louie

Re: Find a word usind DXL script in the microsoft word document attached as OLE
SystemAdmin - Thu May 12 12:39:42 EDT 2011

David_G_Bond - Wed Apr 27 15:12:50 EDT 2011

If you really do only have OLEs that are word documents, the following function should work. I hacked it down from a more complex version.
 

bool searchOleInObject(Object o, string sKeyword)
{
    OleAutoObj objDoc = null, objApp = null, objSelection = null, objFind = null
    bool bIsStatic
    bool bFoundKeyword = false
    bool bIsActivated = false
    string sErr, sName
    
    if (containsStaticOle(o."Object Text")) return(bFoundKeyword)
    if (containsUnregisteredOle(o."Object Text")) return(bFoundKeyword)
    if (oleCount(o."Object Text") < 1) return(bFoundKeyword)
    
    bIsActivated = oleActivate(o)
    if (!bIsActivated) return(bFoundKeyword)
    objDoc = oleGetAutoObject(o)
    if (null(objDoc))
    {
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objDoc, "Application", objApp)
    if (null(objApp))
    {
        if (!null(objDoc)) oleCloseAutoObject(objDoc)
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objApp, "Name", sName)
    if (!matches("Word", sName))
    {
        // not a word application, so close out and return
        oleDeactivate(o)
        return(bFoundKeyword)
    }
    oleGet(objApp, "Selection", objSelection)
    oleGet(objSelection, "Find", objFind)
    oleMethod(objFind, "ClearFormatting")
    olePut(objFind, "Text", sKeyword)
    olePut(objFind, "MatchWholeWord", true)
    olePut(objFind, "Format", false)
    oleMethod(objFind, "Execute")
    oleGet(objFind, "Found", bFoundKeyword)
    oleDeactivate(o)
    
    if (!null(objDoc)) oleCloseAutoObject(objDoc)
    if (!null(objApp)) oleCloseAutoObject(objApp)
    if (!null(objSelection)) oleCloseAutoObject(objSelection)
    if (!null(objFind)) oleCloseAutoObject(objFind)
    return(bFoundKeyword)
}

 

 

  • David Bond

 

 

I tried to run this in DOORS 9.3....How do I invoke this....within a Module, then cut and paste in DXL window then run?