CE Display Rules C#

Hello, I'm trying to develop an add-in for creating Display Rules in c #. I have a problem creating the condition to pass as a parameter to the constructor of the DisplayRule class.
At this link "">www.bimsdks.com/.../structBentley_1_1DgnPlatform_1_1DisplayRule.html" I found some examples (see Condition format and types) but they are very few.

I implemented the following code that works:

string MyRuleCondition = @"element.IsOfClass (""ShapeElement"",""DgnElementSchema"")";

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"" ""Rule""");
ustnApp.CommandState.StartDefaultCommand();


I should implement a RuleCondition that evaluates the value of a property of an ItemType,
does anyone know a way, a tool, or examples (in c #) to create RuleConditions?

Thanks for the help, greetings

Parents Reply
  • CE update 14

    Expressions have advanced in recent versions of MicroStation CONNECT.  You'll find plenty by searching for Expressions in Update 16 help.

    If you're looking to create a display rule programmatically, then start with the C++ MicroStationAPI documentation.  For example...

    DisplayRuleSetPtr ruleSet = DisplayRuleSet::Create(L"RuleSetName", *dgnFile_);
    DisplayRulePtr MakeRule (WCharCP itemTypeName, WCharCP propName, WCharCP condition)
    {
      WString prop (propName);
      WString rule;
      rule.Sprintf (L"element.%s::%s::%s%s",
        ItemTypes::SchemaInternalName ().c_str (),
        ItemTypes::GetInternalName (itemTypeName).c_str (),
        propName,
        condition);
      return MakeRule(rule.c_str ());
    }
    DisplayRulePtr    MakeRule (WCharCP rule)
    {
      const bool    StopIfTrue    {true};
      DisplayRulePtr  displayRule   {DisplayRule::Create(rule, StopIfTrue , *dgnFile_)};
      const bool    valid      {displayRule.IsValid ()};
      if (valid)
      {
        // Created Display Rule:  rule
      }
      else
      {
        // Display rule instruction rule is invalid
      }
      return displayRule;
    }

     
    Regards, Jon Summers
    LA Solutions

Children
No Data