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
Hi Salvatore,
can you provide a DGN as an example, what would be expected result? I guess something like ItemType attached to an element plus display rule defined in some style...
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
DisplayRules.dgn
For this file I would like to create a condition that allows me to select the shape (the larger one to which an ItemType is attached) where the value of the L08_SHIP_ZONE property is = "FOO".Something like:string MyRuleCondition = @"element.DgnElementSchema::ShapeElement::IDES_ITEMTYPE.L08_SHIP_ZONE = ""FOO""";
salvatore montella said:For this file I would like to create a condition that allows me to select the shape (the larger one to which an ItemType is attached) where the value of the L08_SHIP_ZONE property is = "FOO".
Are you able to do it (configure the display rule) manually?
Yes
salvatore montella said:Yes
Thanks for the confirmation, I was able to modify your example accordingly (manually).
DisplayRules_ManualConfig.dgn
In this file there is the display rule configured manually
salvatore montella said:string MyRuleCondition = @"element.DgnElementSchema::ShapeElement::IDES_ITEMTYPE.L08_SHIP_ZONE = ""FOO""";
an idea, without writing any test code
Because as noted in documentation you linked, the format is
HostName.SchemaName::ClassName::Propertyname OPERATOR VALUE
I assume the definition cannot be based on DgnElementSchema, because it's not schema defining ItemType you attached.
Maybe something like
element.DgnCustomItemTypes_IDES_TYPELIBRARY::IDES_ITEMTYPE::L08_SHIP_ZONE = "FOO"
With regards,
Hi Jan, your suggestion resolved my issue.I was not able to figure how to determine the schema name of the ItemTypeLibary in the condition's expression.
Since there is no match between the condition expression shown in the user's interface and the expression required in code I don't know how to write the condition's expression.
E.G. "ELEMENT Is Shapes" in the UI became "element.IsOfClass ("ShapeElement","DgnElementSchema")" in the code.
Is there a reference guide describing the schemas and the expression syntax?
Best regards
Hi salvatore,
salvatore montella said:I was not able to figure how to determine the schema name of the ItemTypeLibary in the condition's expression.
it's "simple" (when you know it :-) ). When you need to know intrinsict (stored in DGN file) EC schemas, and ItemTypes EC schemas are alwayas intrinsict, use "ecx schema list" key-in, that lists the schemas to Message Center Details.
Graphical elements features like color etc. are defined in extrinsict EC schema DgnElementSchema.
salvatore montella said:Since there is no match between the condition expression shown in the user's interface and the expression required in code
There is no reason why there should be the match. It seems description is filled automatically by a summary, but it's not the condition syntax.
salvatore montella said: I don't know how to write the condition's expression.
Well ... as written in the documentation you linked: DisplayRule condition is based on ECExpression. I agree it tells nothing for a plain user, and also for developers it's not clear for 100% (because "is based on" expresses that it's only a subset of ECExpression). But at least, it's defines the basic syntax format.
salvatore montella said:Is there a reference guide describing the schemas and the expression syntax?
I think the description provided in DisplayRule API documentation is where you should start. Despite of it's short, I think it covers the most of needs and scenarios.
Two other sources are:
The problem is that without good knowledge of the whole "EC world" (which is very wide and complex topic), some concepts behind and terminology will remain unexplained.
the link
https://docs.bentley.com/LiveContent/web/MicroStation%20Help-v15/en/BetaExpressions.htmldoesn't exist? Just goes to Bentley docs.Can you give the proper link or is this another link only available to Bentley employees?Which Bentley Doc lists the Beta Expressions?
Display rules use ECExpressions?Does that mean you can use string.empty as an empty string value in Item display rules?Or IsNullOrEmpty?
tried to use the above, but didn't work for me, only the workaround did.CE update 14.Wouldn't ECExpression SymbolSet System.String need to be loaded to use string ECExpressions?communities.bentley.com/.../ecexpressions-explained-calculated-ecproperty
think there should be a simpler list of what expressions if any that you can use in Display Rules.
Karsten EVANS said: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
Hi Karsten,
Karsten EVANS said:doesn't exist?
Well, when you re-open nearly a year old discussion, links can be invalid. I think it is not surprise.
From the link it is visible it points to online documentation of some previous MicroStation version, which is not available now (I guess it was Update 14 or similar).
Karsten EVANS said:Can you give the proper link
I guess Jon answered this part already. To try to use Search in MicroStation documentation is where you should always start. It is really not difficult (15 seconds?) to find the same link in the current version: https://docs.bentley.com/LiveContent/web/MicroStation%20Help-v19/en/BetaExpressions.html
Karsten EVANS said:or is this another link only available to Bentley employees?
How can I know what links are available to Bentley employees?
Karsten EVANS said:Display rules use ECExpressions?
As documentation (DisplayRule Struct Reference) clearly tells: DisplayRule condition is based on ECExpressions.
So, every rule is string, evaluated as ECExpression. The result is always true / false.
Karsten EVANS said:Does that mean you can use string.empty as an empty string value in Item display rules?
In my opinion, not. And even when it would be possible, it is bad idea because of performance (do you know anything slower than string operations? ;-)
As mentioned in documentation: Conditions should specify only stored values
There is also written: Condition supports simple property value comparison as well as complicated conditions with AND and OR operators. No information about using Symbol Providers (libraries) to be able to extend standard comparisons.
Following this rule, I think proper solution (somebody can say it is workaround) is to add extra bool property, containing ECExpression, defining whether source string property is null/empty. The result can be easily evaluated in Display Rule condition.
Karsten EVANS said:think there should be a simpler list of what expressions if any that you can use in Display Rules.
I think it is well enough (even when not ideally) described in API documentation: When you are not sure about syntax, use GUI to define condition and check how it is persisted.