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
salvatore montella said: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).
salvatore montella said:string MyRuleCondition = $@"REFERENCE.References.Logical Name = {fieldValue}";"
It's not clear what you're writing in that statement...
$@
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.
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(); }
Hi Salvatore,
salvatore montella said:Here is the whole procedure I wrote to create the display rule.
In my opinion your original code and the more completed code does something different.
In the first case, at runtime, the string is:
string MyRuleCondition = "REFERENCE.References.Logical Name = Attachment_1"
whereas in the second code, the string is:
string MyRuleCondition = @"REFERENCE.References.Logical Name = ""Attachment_1"""
I have not used Display Rules API often, but I remember it's quite sensitive about quotation marks and other characters, because (unfortunately) the conditions are interpreted as text in this case.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point