You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用DXL向DOORS的#Fruits文本属性追加值?

DOORS属性追加值失败问题解决

问题情况

要将缓冲区的值添加到DOORS的#Fruits(文本类型)属性中,当前执行流程:

  • for循环更新缓冲区:正常工作
  • 缓冲区内容插入#Fruits属性:正常工作
  • 刷新缓冲区获取新值:正常工作
  • 向#Fruits属性追加新值且不覆盖原有内容:失败

预期结果

选中对象的#Fruits属性内容应为:

Apple
Banana
Pear
Strawberry

实际结果

属性内容被覆盖,仅保留最后一个值:

Strawberry 

原代码

Module m = current
Object o = current
Column col
int nCol = 0
string str = ""

//Check whether #Fruits already exists, if yes, then delete the old one
void DeleteDOORSAttribute(string AttributeName){
    AttrDef ad
    ad = find(m,AttributeName)
    if (null ad){
        print "Creating new attribute #Fruits...\n"
    }
    else{
        delete(m, ad)
        print "Attribute #Fruits already exists\n"
    }
}
DeleteDOORSAttribute("#Fruits")

// Create a new attribute named as #Fruits
for col in m do{
    nCol++
}
create object type "Text" attribute "#Fruits"
attribute(column nCol, "#Fruits")


//Create an array with fruit names
Array ListOfFruits = create(3,1)
put(ListOfFruits, "Apple", 0, 1)
put(ListOfFruits, "Banana", 1, 1)
put(ListOfFruits, "Pear", 2, 1)
put(ListOfFruits, "Strawberry", 3, 1)

for (x = 0; x < 4; x++){
    str = (string get(ListOfFruits,x,1))
    Buffer buf = create()
    buf += str
    print "buffer content: " buf "\n"
    // Go on the currently selected object and append the fruit names in it
    o."#Fruits" = buf ""    
}

问题原因

  1. 循环内每次新建Buffer,导致缓冲区仅保留当前循环的单个水果名,无法累积之前的内容
  2. 使用o."#Fruits" = buf ""是直接赋值覆盖属性原有值,而非追加内容
  3. 数组创建时create(3,1)指定3行1列,索引范围为0-2,存入索引3属于越界操作(DOORS可能自动扩容,但属于不规范写法)

解决方案

方案1:一次性拼接所有内容(高效推荐)

先把所有水果名拼接成带换行的字符串,再一次性赋值给属性:

Module m = current
Object o = current
Column col
int nCol = 0
string str = ""

//Check whether #Fruits already exists, if yes, then delete the old one
void DeleteDOORSAttribute(string AttributeName){
    AttrDef ad
    ad = find(m,AttributeName)
    if (null ad){
        print "Creating new attribute #Fruits...\n"
    }
    else{
        delete(m, ad)
        print "Attribute #Fruits already exists\n"
    }
}
DeleteDOORSAttribute("#Fruits")

// Create a new attribute named as #Fruits
for col in m do{
    nCol++
}
create object type "Text" attribute "#Fruits"
attribute(column nCol, "#Fruits")


//Create an array with fruit names(修正数组容量为4行)
Array ListOfFruits = create(4,1)
put(ListOfFruits, "Apple", 0, 1)
put(ListOfFruits, "Banana", 1, 1)
put(ListOfFruits, "Pear", 2, 1)
put(ListOfFruits, "Strawberry", 3, 1)

// 拼接所有水果名,每行一个
Buffer buf = create()
for (x = 0; x < 4; x++){
    str = (string get(ListOfFruits,x,1))
    buf += str "\n"
    print "buffer content: " buf "\n"
}

// 一次性赋值给属性
o."#Fruits" = buf ""    

方案2:循环追加(适合需要逐步更新的场景)

每次循环先获取属性当前值,再追加新内容:

Module m = current
Object o = current
Column col
int nCol = 0
string str = ""

//Check whether #Fruits already exists, if yes, then delete the old one
void DeleteDOORSAttribute(string AttributeName){
    AttrDef ad
    ad = find(m,AttributeName)
    if (null ad){
        print "Creating new attribute #Fruits...\n"
    }
    else{
        delete(m, ad)
        print "Attribute #Fruits already exists\n"
    }
}
DeleteDOORSAttribute("#Fruits")

// Create a new attribute named as #Fruits
for col in m do{
    nCol++
}
create object type "Text" attribute "#Fruits"
attribute(column nCol, "#Fruits")


//Create an array with fruit names(修正数组容量为4行)
Array ListOfFruits = create(4,1)
put(ListOfFruits, "Apple", 0, 1)
put(ListOfFruits, "Banana", 1, 1)
put(ListOfFruits, "Pear", 2, 1)
put(ListOfFruits, "Strawberry", 3, 1)

for (x = 0; x < 4; x++){
    str = (string get(ListOfFruits,x,1))
    // 获取属性当前内容
    Buffer currentBuf = create()
    currentBuf = o."#Fruits"
    
    // 追加新内容(加换行)
    currentBuf += str "\n"
    print "buffer content: " currentBuf "\n"
    
    // 重新赋值给属性
    o."#Fruits" = currentBuf ""    
}

内容的提问来源于stack exchange,提问作者NickHalden

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 16:43:11