I'm using for for a year but now I have to modify small scripts and I'm a newbie with DXL
. I have searched in before questions but I don't know how I can do it.
I have to develope a script that analyzes all objects in the same formal module to extract from each "object text" different strings separated by tab, to be written in other different attributes of the same object.
The formal module contents has been imported from Word. In that way that normal text format is defined as "object text" and every Title style is associated to a given level heading. In that way each object is provided with object heading or object text (but not both at the same time). Objects with object heading doesn't require any further action. However for objects provided with object text, I have to extract from object text some atributes separated by tabs.
For example a typical object text could be:
NNNN TEXT/TABLE/OLE OBJECT/ANY OTHER STRING (XXXXXX) (YYYYYY)
After apply the script it should be converted as:
Attribute 1: NNNN
Object Text: TEXT/TABLE/OLE OBJECT/ANY OTHER STRING
Attribute 2: XXXXXX
Attribute 3: YYYYYY
I have small script as example but I have passed all the morning trying to modify it to get I need but I can't do it:
Object o = current
//bool get_text(Object o) {return o."Object Heading" "" != ""}
string get_text(Object o)
{
if (o."Object Heading" "" != "")
return "Object Heading"
else
return "Object Text"
}
Regexp r_id = regexp "(http://0-9a-z/.+) "
for o in current Module do
{
string texto = o.(get_text(o))
if (r_id text)
{
o."Attribute 1" = textmatch 1
string input = richTextWithOle(o.(get_text(o)))
string output = cutRichText(input, 0, length(textmatch 1))
o.(get_text(o)) = richText(output)
}
}
This was a complicated one, but I think I have it figured out. Thanks for posting this because I may find it useful in the future as well.
I tried this out and it seems to work:
Object o
string get_text(Object o)
{
if (o."Object Heading" "" != "")
return "Object Heading"
else
return "Object Text"
}
char cTab = '\t' //The tab character to find
Buffer b = create
string tmp = "" //Needed to concatenate buffer parts
int offset = 0
for o in current Module do
{
string attr = get_text(o)
b = o.attr //Put the contents in the buffer
offset = contains(b, cTab) //Find the first tab
o."Attribute 1" = b[0:offset-1] //Set the first Attribute
b = b[offset+1:] //Remove the first attribute from the text
offset = contains(b, cTab)
if(offset > -1)
{
if(attr == "Object Heading") o.attr = b[0:offset-1]
b = b[offset+1:]
offset = contains(b, cTab)
if(offset > -1)
{
o."Attribute 2" = b[1:offset-2] //Set the second Attribute without the ()
b = b[offset+1:]
o."Attribute 3" = b[1:length(b)-2] //Set the third Attribute without the ()
} else {
o."Attribute 2" = b[1:length(b)-2] //Set the second Attribute without the ()
}
} else {
if(attr == "Object Heading") o.attr = b[0:]
}
if(attr == "Object Text")
{
b = richTextWithOle(o.attr) "" //This section removes the attributes from the contents without losing the rich text formatting and OLEs that may be present.
string word = o."Attribute 1"
offset = contains(b, word, 0)
tmp = b[0:offset-1] "" b[(offset+length(word)+5):]
b = tmp
word = "(" o."Attribute 2" ")"
offset = contains(b, word, 0)
if(offset > -1)
{
tmp = b[0:offset-6] "" b[offset+length(word):]
b = tmp
}
word = "(" o."Attribute 3" ")"
offset = contains(b, word, 0)
if(offset > -1)
{
tmp = b[0:offset-6] "" b[offset+length(word):]
}
o.attr = richText(tmp) //Set the Object Text or Heading
}
}
delete b //Release the buffer resources
Let me know if this gives you any trouble or if you want more detailed explination of the code.
EDIT: I updated the above code to take care of the issues you mentioned. It should be all set now. Let me know if you have any more trouble with it.