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

DXL脚本遍历DOORS模块视图时参数错误求助

问题

使用DXL脚本处理DOORS基础模块视图时出错,脚本目标是遍历数据库模块所有视图,检查是否属于skiplist中的通用视图:

  • 若是通用视图,移除除"12_Admin"组外所有组的全部访问权限
  • 为"12_Admin"组授予RMCDA权限
  • 保存模块修改

原脚本:

pragma runLim, 0

Skip includedViews = create()

/************************************
addIncludedView
Ajouter une vue à la skiplist des vues incluses.
************************************/
void addIncludedView(Skip includeList, string ViewName)
{
    Skip sk = includeList
   // sk insert ViewName
   put(sk, ViewName, ViewName)
   
}



/************************************
processFormal
Do something with the given formal module.
************************************/
void processFormal(string mName)
{
    Skip includeList = includedViews
    string IncludedView
    string sView
    View v
    noError
    Module m = read(mName, false)
    lastError

    // Parcourir toutes les vues du module "itm"
    for sView in views(m) do
    {
        // Initialiser isIncluded à false pour chaque vue
        v = view sView
        bool isIncluded = false
        print fullName(m) ";   "
        
        // Vérifier si la vue actuelle est incluse dans la liste des vues incluses
        for IncludedView in includeList do
        {
            if (IncludedView == name(v))
            {
                isIncluded = true
                break
            }
        }
        
        // Si la vue est incluse
        if (isIncluded)
        {
            Group group
            noError
            m = edit(mName, false)
            lastError
            
            for g in groupList do {
            string gName = group.name
                if (gName != "12_Admin"){
                unsetAll(v)
                }
            }
            
            set (v, read|modify|create|delete|control, "12_Admin")
            save(m)
            print name(v) "; Vue générique\n"
        }
        else
        {
            print name(v) "; Vue non générique\n"
        }
    }
}

void scanFolder(Folder f)
{
    Item itm;
    if (f == null)
    {
        print("NULL Folder parameter passed\n");
        return;
    }

    for itm in all f do
    {
        if (itm == null) continue;

        if (type(itm) == "Project" || type(itm) == "Folder")
        {
            scanFolder(folder(itm));
        }
        else if (type(itm) == "Formal")
        {
            processFormal(fullName(itm))
        }
    }
}

/************************************
MAIN
************************************/
// Ajoutez les vues que vous souhaitez inclure de la modification à la skiplist

addIncludedView(includedViews, "Allocation Matrix")




scanFolder(current Folder);

运行错误:

-E- DXL: <Line:59> Arguments incorrects pour (do)
问题分析与修复

错误原因

  1. Skip遍历语法错误:DOORS DXL中不能直接用for 变量 in Skip对象 do,必须使用keys(Skip对象)来遍历Skip的键集合,原脚本遍历includeList的方式不符合语法规范。
  2. Group循环变量不匹配:第59行的循环中,定义的Group变量是group,但循环变量用的是g,内部却调用group.name,导致变量引用错误;同时遍历groupList时需正确声明循环变量类型。
  3. 权限移除逻辑问题:原脚本中unsetAll(v)会移除所有组的权限(包括"12_Admin"),应针对每个非目标组单独移除权限,而非直接清空所有权限。

修复后的脚本

pragma runLim, 0

Skip includedViews = create()

/************************************
addIncludedView
Ajouter une vue à la skiplist des vues incluses.
************************************/
void addIncludedView(Skip includeList, string ViewName)
{
    put(includeList, ViewName, ViewName)
}

/************************************
processFormal
Do something with the given formal module.
************************************/
void processFormal(string mName)
{
    Skip includeList = includedViews
    string IncludedView
    string sView
    View v
    noError
    Module m = read(mName, false)
    lastError

    // 遍历模块所有视图
    for sView in views(m) do
    {
        v = view sView
        bool isIncluded = false
        print fullName(m) ";   "
        
        // 检查当前视图是否在目标列表中(修正Skip遍历方式)
        for IncludedView in keys(includeList) do
        {
            if (IncludedView == name(v))
            {
                isIncluded = true
                break
            }
        }
        
        if (isIncluded)
        {
            noError
            m = edit(mName, false)
            lastError
            
            // 遍历所有组,修正变量引用问题
            Group g
            for g in groupList do 
            {
                string gName = name(g)
                if (gName != "12_Admin")
                {
                    // 单独移除当前非目标组的所有权限
                    unset(v, read|modify|create|delete|control, gName)
                }
            }
            
            // 为目标组授予完整权限
            set(v, read|modify|create|delete|control, "12_Admin")
            save(m)
            print name(v) "; Vue générique\n"
        }
        else
        {
            print name(v) "; Vue non générique\n"
        }
    }
    // 关闭模块释放资源
    close(m)
}

void scanFolder(Folder f)
{
    Item itm;
    if (f == null)
    {
        print("NULL Folder parameter passed\n");
        return;
    }

    for itm in all f do
    {
        if (itm == null) continue;

        if (type(itm) == "Project" || type(itm) == "Folder")
        {
            scanFolder(folder(itm));
        }
        else if (type(itm) == "Formal")
        {
            processFormal(fullName(itm))
        }
    }
}

/************************************
MAIN
************************************/
// 添加需要处理的通用视图到skiplist
addIncludedView(includedViews, "Allocation Matrix")

scanFolder(current Folder);

额外优化点

  • 移除冗余的变量赋值Skip sk = includeList
  • 添加close(m)关闭模块,避免资源占用
  • 将unsetAll(v)改为针对单个组的unset操作,避免误删目标组权限
  • 统一Group变量的命名和引用,确保循环内变量正确匹配

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 23:43:12