【问题标题】:(DOORS/DXL) Script for Split Object text in some atributtes using Tab(DOORS/DXL) 使用 Tab 在某些属性中拆分对象文本的脚本
【发布时间】:2012-11-06 07:52:50
【问题描述】:

我使用了一年,但现在我必须修改小脚本,我是 DXL 的新手。我已经搜索过之前的问题,但我不知道我该怎么做。

我必须开发一个脚本来分析同一正式模块中的所有对象,以从每个“对象文本”中提取由制表符分隔的不同字符串,以写入同一对象的其他不同属性。

正式模块内容已从 Word 导入。这样,普通文本格式被定义为“对象文本”,并且每个标题样式都与给定的级别标题相关联。以这种方式,每个对象都提供有对象标题或对象文本(但不能同时提供两者)。具有对象标题的对象不需要任何进一步的操作。但是对于带有对象文本的对象,我必须从对象文本中提取一些由制表符分隔的属性。

例如,典型的对象文本可能是:

NNNN       TEXT/TABLE/OLE OBJECT/ANY OTHER STRING      (XXXXXX)     (YYYYYY)

应用脚本后应转换为:

Attribute 1: NNNN
Object Text: TEXT/TABLE/OLE OBJECT/ANY OTHER STRING
Attribute 2: XXXXXX
Attribute 3: YYYYYY

我有一个小脚本作为示例,但我整个上午都试图修改它以获得我需要但我做不到:

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) 
    }

}

【问题讨论】:

  • 下次请按缩进。
  • @Abhishek Bhatia 感谢您纠正我的信息。对不起。请原谅我,我也是这个网站的新手。

标签: ibm-doors


【解决方案1】:

这是一个复杂的问题,但我想我已经弄清楚了。感谢您发布此内容,因为我将来可能会发现它也很有用。

我试过了,它似乎有效:

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

如果这给您带来任何麻烦,或者您想要更详细地解释代码,请告诉我。

编辑:我更新了上面的代码来处理你提到的问题。现在应该全部设置好了。如果您还有其他问题,请告诉我。

【讨论】:

  • 感谢您的回答!这对我来说非常有用。起初它给了我运行时错误。为了尝试它,我不得不修改行以设置对象文本或标题。我已将“richtext(tmp)”更改为“richTextWithOle(tmp)”。我认为这个脚本对很多人来说可能非常有用。您可以维护层次结构(作为 rtf 导入)和一些属性信息(作为电子表格导入)。
  • 它工作正常,但我仍然需要更正两件事才能使用它。我希望你能帮我解决这个问题: 1.- 我需要带有对象文本的对象,应该完全按照你的编程来分割。但是,没有对象文本的对象(仅提供对象标题)应仅按属性 1 和对象标题分割。 2.- 所有带有对象文本的对象都至少有 1 个选项卡(属性 1+对象文本),但其他选项卡(属性 2 和 3)可能会丢失。在这种情况下,它们应该被忽略。现在,如果其中任何一个丢失,则会显示运行时错误。谢谢你的帮助!!
  • 谢谢。它非常适合对象标题,但对于对象文本,虽然它在对象文本及其属性中很好地分割,但新属性不会从原始对象文本中删除。很抱歉再次打扰您。试过修改但不知道DXL,有时修改代码也没有成功。
  • 嗨,你能看看我之前的评论吗??
  • 我刚刚又测试了一次,它似乎工作正常。我在 3 个文本对象和 3 个标题对象上运行它,它们都正确复制到属性中,然后从标题或文本中删除属性文本。我不知道为什么它对您不起作用,或者我将如何解决它,因为据我所知它可以正常工作。你能发布一些不工作的示例对象吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多