关于属性分类Category中设置的优先级未生效的问题

FindInstancesScope scope = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.File, false));
IECSchema eCSchema = DgnECManager.Manager.LocateSchemaInScope(scope, "OpenPlant_3D", 1, 8, SchemaMatchType.Exact);
IECClass eCClass = eCSchema.GetClass("HAND_WHEEL");

这个文件中,我给ACCESSSTRING为 NAME、COMPONENT_NAME、ALIAS、DRY_WEIGHT的4个属性分别设置了测试类别1和测试类别2两个Category,同时为测试类别1设置了 500000的优先级。设置成功后,在属性面板中实际看到这两个测试类别排在属性面板的最后,如图

设置成功后再次通过代码可以获得“常规”分类的优先级为400000,而“测试类别1”的优先级为500000。为什么“测试类别1”没有跑到“常规”类别的前边呢?

我设置属性类别的代码如下:

IECProperty prop = eCClass.FindProperty(CommandData.PropNamesofCategoryToBeSeted[i]);
 string[] categoryNameAndPriority = CommandData.CategoryToSet[i].Split(new string[] { @"\%" }, StringSplitOptions.RemoveEmptyEntries);
 string categoryName = categoryNameAndPriority[0];
 string categoryPriority = categoryNameAndPriority.Length > 1 ? categoryNameAndPriority[1] : "0";
 IECInstance newCategory;
 bool b = int.TryParse(categoryPriority, out int priority);
newCategory = ECPropertyPane.CreateCategory(categoryName, categoryName, categoryName, b ? priority : 0);

//设置Category
if (newCategory is not null)
{
    if (!prop.IsContainerSupplemented())
    {
        ECPropertyPane.SetCategory(prop, newCategory);
    }//如果不是在Supplemented的Schema中定义的
    else
    {
        prop.SetSupplementedCustomAttribute(newCategory);
    }
}

//更新Schema
DgnECManager.Manager.UpdateSchema(prop.ClassDefinition.Schema, GeneralUtils.ActiveDgnFile, new())

我还尝试在代码中不判断prop.IsContainerSupplemented(),直接同时设置SetSupplementedCustomAttribute和SetCustomAttribute,也依然无法使优先级生效。

关了MS再开也不生效。中文版的MS环境,英文版也试了,优先级也不生效。

Parents
  • 如下所示是我以前测试这个特性用过的测试代码,您试试:

    var ecClass≡ecSchema.GetClass("myClass");
                FindInstancesScope scopeTemp = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), new FindInstancesScopeOption());
                int verMaj = 1, verMin = 3;
                IECSchema schemaCustomAtt = DgnECManager.Manager.LocateSchemaInScope(scopeTemp, "EditorCustomAttributes", verMaj, verMin,
                          SchemaMatchType.LatestCompatible);
                if (schemaCustomAtt != null)
                {
                    IECClass ecClassCate = schemaCustomAtt.GetClass("Category");
                    IECInstance ecInsCate = ecClassCate.CreateInstance();
                    ecInsCate.SetString("Name", "NameGhq");
                    ecInsCate.SetString("DisplayLabel", "NameGhq");
                    ecInsCate.SetInteger("Priority", 500000);
                    ecClass.SetCustomAttribute(ecInsCate);
                }
                DgnECManager.Manager.UpdateSchema(ecSchema, Session.Instance.GetActiveDgnFile(), opt);

Reply
  • 如下所示是我以前测试这个特性用过的测试代码,您试试:

    var ecClass≡ecSchema.GetClass("myClass");
                FindInstancesScope scopeTemp = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), new FindInstancesScopeOption());
                int verMaj = 1, verMin = 3;
                IECSchema schemaCustomAtt = DgnECManager.Manager.LocateSchemaInScope(scopeTemp, "EditorCustomAttributes", verMaj, verMin,
                          SchemaMatchType.LatestCompatible);
                if (schemaCustomAtt != null)
                {
                    IECClass ecClassCate = schemaCustomAtt.GetClass("Category");
                    IECInstance ecInsCate = ecClassCate.CreateInstance();
                    ecInsCate.SetString("Name", "NameGhq");
                    ecInsCate.SetString("DisplayLabel", "NameGhq");
                    ecInsCate.SetInteger("Priority", 500000);
                    ecClass.SetCustomAttribute(ecInsCate);
                }
                DgnECManager.Manager.UpdateSchema(ecSchema, Session.Instance.GetActiveDgnFile(), opt);

Children
  • 我看了您的代码是给ECClass设置的Category啊,我是给其中的一条属性设置的Category,他的优先级不能生效。

    但我尝试将您代码中的ecClass替换为一个ecProperty,居然可以令设置的属性优先级生效……就很奇怪呢?问题出在哪呢?是原生的创建Category的API有问题吗?

  • 可能基于我上面的代码试着一步一步改造成您的修改方式,然后改一点测试一下看看,如果不行了,那就是最近改的这一部分内容造成的。

  • foreach (IDgnECInstance item in DgnECManager.Manager.GetElementProperties(ele, ECQueryProcessFlags.SearchAllClasses))
    {
        if (item.ClassDefinition.Name == "HAND_WHEEL")
        {
            string[] propAccessStrings = { "NUMBER", "SIZE", "NAME", "ALIAS", "COMPONENT_NAME", "DRY_WEIGHT", "PLANT_AREA" };
    
            for (int i = 0; i < propAccessStrings.Length; i++)
            {
                string propAccessString = propAccessStrings[i];
                IECProperty property = item.ClassDefinition.FindProperty(propAccessString);
                if (property is not null)
                {
                    Bentley.DgnPlatformNET.DgnEC.FindInstancesScope scopeTemp = Bentley.DgnPlatformNET.DgnEC.FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), new Bentley.DgnPlatformNET.DgnEC.FindInstancesScopeOption());
                    int verMaj = 1, verMin = 3;
                    IECSchema schemaCustomAtt = DgnECManager.Manager.LocateSchemaInScope(scopeTemp, "EditorCustomAttributes", verMaj, verMin,
                              SchemaMatchType.LatestCompatible);
                    if (schemaCustomAtt != null)
                    {
                        IECClass ecClassCate = schemaCustomAtt.GetClass("Category");
                        Bentley.ECObjects.Instance.IECInstance ecInsCate = ecClassCate.CreateInstance();
                        string c = "测试分类" + (i + 77);
                        ecInsCate.SetString("Name", c);
                        ecInsCate.SetString("DisplayLabel", c);
                        ecInsCate.SetString("Description", c);
                        ecInsCate.SetInteger("Priority", 500000 + i);
                        property.SetCustomAttribute(ecInsCate);
                        DgnECManager.Manager.UpdateSchema(property.ClassDefinition.Schema, GeneralUtils.ActiveDgnFile, new());
                    }
                }
            }
        }
    }

    您的代码我又不好使了……我把类别名设置成了变量,然后给多个属性同时更改不同的类别名称,生成的结果如下图

    上边的代码执行完以后,我再通过代码查看这些属性分类的优先级,都是500000+的。但就是显示不靠前。关闭了软件重开也这样。

    之前成功了是特殊的固定的名称

    如果方便恳请您用我的文件和我的代码测试一下在您那里的执行结果。如果您那里执行成功,我怀疑是我的MS版本的bug。记得用中文环境测试代码,谢谢。

  • 我用您的测试代码测试都正常,我的Mstn版本是10.17.02.61

    Answer Verified By: 霄男 宿 

  • 我就怀疑可能是我的客户端太老了有bug,明天我还是装个最新的2023吧。老版本bug太多了。