CE C# Build Display Rules programmatically

Hi everyone,

I'm developing an AddIn in C # for Microstation Connect Version 12 and I should create, by code, a rule to insert in a display rules.


If I create the following rule (REFERENCE.References.Logical Name = Attachment_1), in the Microstation environment, everything works correctly (DisplayRules1.JPG) .


If I try to create the same rule from c # Microstation I get the message "Unrecognized Criteria" (DisplayRules2.JPG)

Code Example :

"string fieldValue = "Attachment_1";

string RuleStenName = "RulSet_1";

string MyRuleCondition = $@"REFERENCE.References.Logical Name = {fieldValue}";"

 


Could anyone tell me what is the exact way to build this rule condition from code?

Thanks for your help,

Salvio

Parents
  • Could anyone tell me what is the exact way to build a rule condition from code?

    More generally, I think we need advice on writing Expressions programmatically.  It's easy to get an Expression wrong, but hard to get diagnostic information (as you have found).

    string MyRuleCondition = $@"REFERENCE.References.Logical Name = {fieldValue}";"

    It's not clear what you're writing in that statement...

    • A literal string is prefixed with two special .NET modifiers $@
    • The string is terminated with an additional quote after the semi-colon
    • How do you assign that statement to an Expression?

    Please write your actual code here so we can better understand what you have:  Use the Insert|Code button.

     
    Regards, Jon Summers
    LA Solutions


  • Hi Jon, thanks for replying.
    Here is the whole procedure I wrote to create the display rule.

    Thanks for your help,

    Salvio

     private void DiplayRulesSampleNew()
            {
                BIM.CadInputQueue keyInCommand = ustnApp.CadInputQueue;
    
                DgnFile dgnFile = BM.Session.Instance.GetActiveDgnFile();
                DgnModel dgnModel = BM.Session.Instance.GetActiveDgnModel();
                DgnModelRef dgnModelRef = BM.Session.Instance.GetActiveDgnModelRef();
    
                string RuleStenName = "RulSet_1";
                string MyRuleCondition = @"REFERENCE.References.Logical Name = ""Attachment_1""";
    
                
                DisplayRuleSet displayRuleSet = new DisplayRuleSet(RuleStenName, dgnFile);
                
                DisplayRulesManager.WriteDisplayRuleSetToFile(displayRuleSet, dgnFile, true);
                DisplayRule displayRuleElement = new DisplayRule(MyRuleCondition, true, dgnFile);
    
                IDisplayRuleAction ruleAction = new ColorOverrideAction(5, dgnFile);
                displayRuleElement.AddAction(ruleAction);
                displayRuleSet.AddDisplayRule(displayRuleElement);
                DisplayRulesManager.WriteDisplayRuleSetToFile(displayRuleSet, dgnFile, true);
    
                keyInCommand.SendKeyin("MDL KEYIN CUSTOMDISPMODE DIALOG DISPLAYSTYLES");
                keyInCommand.SendKeyin(@"DISPLAYSTYLE CREATE ""DISPLAY_STYLE_BY_KEYIN""");
                keyInCommand.SendKeyin(@"MDL KEYIN VIEWCTRL CHANGE VIEW CUSTOM ""DISPLAY_STYLE_BY_KEYIN"" 1");
                keyInCommand.SendKeyin(@"DISPLAYSTYLE SETPARAM DISPLAYRULESET ""DISPLAY_STYLE_BY_KEYIN"" ""RulSet_1""");
    
                ustnApp.CommandState.StartDefaultCommand();
    
    
            }

Reply

  • Hi Jon, thanks for replying.
    Here is the whole procedure I wrote to create the display rule.

    Thanks for your help,

    Salvio

     private void DiplayRulesSampleNew()
            {
                BIM.CadInputQueue keyInCommand = ustnApp.CadInputQueue;
    
                DgnFile dgnFile = BM.Session.Instance.GetActiveDgnFile();
                DgnModel dgnModel = BM.Session.Instance.GetActiveDgnModel();
                DgnModelRef dgnModelRef = BM.Session.Instance.GetActiveDgnModelRef();
    
                string RuleStenName = "RulSet_1";
                string MyRuleCondition = @"REFERENCE.References.Logical Name = ""Attachment_1""";
    
                
                DisplayRuleSet displayRuleSet = new DisplayRuleSet(RuleStenName, dgnFile);
                
                DisplayRulesManager.WriteDisplayRuleSetToFile(displayRuleSet, dgnFile, true);
                DisplayRule displayRuleElement = new DisplayRule(MyRuleCondition, true, dgnFile);
    
                IDisplayRuleAction ruleAction = new ColorOverrideAction(5, dgnFile);
                displayRuleElement.AddAction(ruleAction);
                displayRuleSet.AddDisplayRule(displayRuleElement);
                DisplayRulesManager.WriteDisplayRuleSetToFile(displayRuleSet, dgnFile, true);
    
                keyInCommand.SendKeyin("MDL KEYIN CUSTOMDISPMODE DIALOG DISPLAYSTYLES");
                keyInCommand.SendKeyin(@"DISPLAYSTYLE CREATE ""DISPLAY_STYLE_BY_KEYIN""");
                keyInCommand.SendKeyin(@"MDL KEYIN VIEWCTRL CHANGE VIEW CUSTOM ""DISPLAY_STYLE_BY_KEYIN"" 1");
                keyInCommand.SendKeyin(@"DISPLAYSTYLE SETPARAM DISPLAYRULESET ""DISPLAY_STYLE_BY_KEYIN"" ""RulSet_1""");
    
                ustnApp.CommandState.StartDefaultCommand();
    
    
            }

Children