如何从 DXL 中获取 object 和更低层级的 object

How to get object and lower hierarchical objects from a DXL

我是 DXL 的新手,正在做一些可能非常简单的事情。 我想解析当前模块,并为每个具有给定 ID(在下面调用 IDNUM)不为空的 object 获取以下数据: IDNUM - Object 文本 - 所有具有较低层级的文本,所有 object 都喜欢这个文本。

结合代码可能会更容易理解。到目前为止,它看起来像这样:

Object o 
Object ol
Link l
Module m = current Module

For o in entire(m) do{
 if (o."IDNUM" != ""){
   print o."IDNUM" "" 
   print o."text" "" 
   //HERE I WOULD LIKE TO ALSO PRINT EVERY TEXT IN OBJECT "LOWER" THAN o
   for l in o --> "*" do{
    ol = target(l)
    print ol."text" "" 
    //HERE I WOULD LIKE TO ALSO PRINT EVERY TEXT IN OBJECT "LOWER" THAN ol
   }
  }
}

基本上,我有 object 和喜欢它的人的 ID 和标题,但没有下面的文字。换句话说,我的代码将 "mimic" 函数 right click>copy>copy with hierarchy 我怎样才能做到这一点?不幸的是,我没有发现任何有用的东西。

非常感谢,

这是您概述的草图代码:

Object o 
Object ol
Link l
Module m = current Module

For o in entire(m) do{
 if (o."IDNUM" != ""){
   print o."IDNUM" "" 
   print o."text" "" 
   //HERE I WOULD LIKE TO ALSO PRINT EVERY TEXT IN OBJECT "LOWER" THAN o
   for l in o --> "*" do{
    ol = target(l)
    print ol."text" "" 
    //HERE I WOULD LIKE TO ALSO PRINT EVERY TEXT IN OBJECT "LOWER" THAN ol
   }
  }
}

此处需要更改一些小语法,但最大的更改是您处理 linked 项目的方式。源模块中的链接 'live',但它们仅存储有限的信息,主要是作为 link 的源和目标的模块,以及它们接触的对象的绝对数量。因此,在尝试从中读取文本之前,您需要检查另一侧的模块是否打开。

并且由于您要遍历整个 link 结构,因此您需要一个递归元素。

我可能会得到这样的结果:

//turn off run limit timer- this might take a bit
pragma runLim , 0 

Object o 
Module m = current Module

// Recursive function- assumes each object has a text attribute- will error otherwise
void link_print(Object obj) {
    print obj."text" "\n"
    Link out_link
    Object next_obj = null
    for out_link in obj -> "*" do {
        // Set the next object in the chain
        next_obj = target ( out_link )
        // This might return null if the module is not loaded
        if ( null next_obj ) {
            // Load the module in read-only mode, displayed and in standard view
            read ( fullName ( ModName_ target ( out_link ) ) , true , true )
            // Try and resolve out 'target' again
            next_obj = target ( out_link )
            // If it doesn't work, print a message so we can figure it out
            if ( null next_obj ) {
                print "Error Accessing Object " ( targetAbsNo ( out_link ) )""
            } else {
                //Iterate down structure
                link_print ( next_obj )
            }
        } else {
            //Iterate down structure
            link_print ( next_obj )
        }
    }
}


for o in entire(m) do {
    // Note that I cast the result of o."IDNUM" to a string type by appending ""
    if (o."IDNUM" "" != ""){
        print o."IDNUM" "\n" 
        // Recurse
        link_print(o)
        print "\n"
    }
}

注意!根据你的 link 结构的大小,即你有多少层(以及是否有任何循环 link 模式),这可能是一个相当耗费资源的任务,使用一些东西会更好地解决除了 "print" 命令(比如将它附加到一个 word 文件,这样你就知道它在出错之前走了多远)

祝你好运!

编辑:

此脚本现在将进入单一级别,但应报告子对象,而不是递归地执行任务。

 //turn off run limit timer- this might take a bit
pragma runLim , 0 

Object o 
Module m = current Module

// Recursive function- assumes each object has a text attribute- will error otherwise
void link_print(Object obj) {
    print obj."text" "\n"
    Link out_link
    Object next_obj = null
    Object child_obj = null
    for out_link in obj -> "*" do {
        // Set the next object in the chain
        next_obj = target ( out_link )
        // This might return null if the module is not loaded
        if ( null next_obj ) {
            // Load the module in read-only mode, displayed and in standard view
            read ( fullName ( ModName_ target ( out_link ) ) , true , true )
            // Try and resolve out 'target' again
            next_obj = target ( out_link )
            // If it doesn't work, print a message so we can figure it out
            if ( null next_obj ) {
                print "Error Accessing Object " ( targetAbsNo ( out_link ) )""
            } else {
                // Loop and report on child objects
                for child_obj in next_obj do {
                    print child_obj."text" "\n"
                }
            }
        } else {
            // Loop and report on child objects
            for child_obj in next_obj do {
                print child_obj."text" "\n"
            }
        }
    }
}


for o in entire(m) do {
    // Note that I cast the result of o."IDNUM" to a string type by appending ""
    if (o."IDNUM" "" != ""){
        print o."IDNUM" "\n" 
        // Recurse
        link_print(o)
        print "\n"
    }
}

亲爱的罗素(和其他人)

我刚刚浏览了您提供给我的一段代码,它可以工作....但不是我要找的东西。看来我的解释不是很清楚。对不起(我不是母语人士)。 我不希望获得所有 link,而只是写在当前 link 指向的对象正下方的 Object text。 这是我的文件的样子

 object1 (with IDNUM) : "Title_doc_1"   --> (link) objectA "Title_doc_2"
    object2 : "some_text"                            objectB : "some_text"
    object3 : "some_text"                            objectC : "some_text"

object1 可以指向许多其他 objectA 但我已经处理过了。)

我上面提供的代码解析 "doc_1",并打印 "IDNUM" "Title_doc_1" "Title_doc_2"

我正在寻找的不仅是objectA,还有objectBobjectC,它们在objectA(和object2object3 也一样,但过程相同)。

希望我能让自己明白...