<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communities.bentley.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/197326/ce-c-build-display-rules-programmatically</link><description>Hi everyone, 
 I&amp;#39;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</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/588937?ContentTypeID=1</link><pubDate>Tue, 26 May 2020 09:17:54 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:89b3cdc8-9288-4872-9427-e038b61d9bc9</guid><dc:creator>Mangesh.Shelar</dc:creator><description>&lt;p&gt;No,&lt;/p&gt;
&lt;p&gt;ECQuery is object graph.&lt;/p&gt;
&lt;p&gt;For that where criteria LHS part shows with characters that are standard TSQL in text format.&amp;nbsp;For e.g., look at *Advance Search* dialog of Explorer:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/343173/pastedimage1590484661733v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;But when code for&amp;nbsp;where criteria for your ECQuery, you need to use something like:&lt;/p&gt;
&lt;p&gt;query.WhereClause.Add (new PropertyExpression (RelationalOperator.LIKE, purposeProp, &amp;quot;Ba*&amp;quot;));&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/588803?ContentTypeID=1</link><pubDate>Mon, 25 May 2020 13:02:52 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:97e41f41-cf40-4e62-aae6-caf43c714bcf</guid><dc:creator>Jon Summers</dc:creator><description>[quote userid="9574" url="~/products/programming/microstation_programming/f/microstation-programming---forum/197326/ce-c-build-display-rules-programmatically/588800"]It&amp;#39;s creating &amp;quot;where criteria&amp;quot; for EC. It follows TSQL format[/quote]
&lt;p&gt;Great tip: thanks!&lt;/p&gt;
&lt;p&gt;Is it universally true for an EC query that we should, in effect, write a valid &lt;a title="Wikipedia: Transact-SQL" href="https://en.wikipedia.org/wiki/Transact-SQL" rel="noopener noreferrer" target="_blank"&gt;TSQL&lt;/a&gt; statement?&amp;nbsp; &lt;a title="Wikipedia: Transact-SQL" href="https://en.wikipedia.org/wiki/Transact-SQL" rel="noopener noreferrer" target="_blank"&gt;TSQL&lt;/a&gt; is not mentioned in the documentation for any API.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/588800?ContentTypeID=1</link><pubDate>Mon, 25 May 2020 12:55:22 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:1e03afd5-c369-4155-95a4-4bdde91771e8</guid><dc:creator>Mangesh.Shelar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am not aware of Display Rule much, but that condition editor is surely EC. It&amp;#39;s creating &amp;quot;where criteria&amp;quot; for EC. It follows TSQL format. Please try to enclose your value in single quote.&lt;/p&gt;
&lt;p&gt;Like this:&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;string MyRuleCondition = &amp;quot;REFERENCE.References.Logical Name=&amp;#39;Attchment_1&amp;#39;&amp;quot;;&lt;br /&gt;&lt;br /&gt;Let me know if this works.&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/587243?ContentTypeID=1</link><pubDate>Sun, 17 May 2020 11:13:52 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:74f8283a-d791-47a0-8041-4397f09d1b34</guid><dc:creator>salvatore montella</dc:creator><description>&lt;p&gt;Hi Jon.&lt;br /&gt;Attachment_1, Attchment_1, Foo, TestName ... don&amp;#39;t make a difference, &lt;br /&gt;these are just the value of the logical name of the attachment.&lt;br /&gt;The problem is that Microstation does not create the rule&amp;nbsp; and&amp;nbsp;returns the error &amp;quot;Unrecognize Criteria&amp;quot;,&amp;nbsp; not that Micorstation creates the rule and then cannot resolve it.&lt;br /&gt;I also tried with the syntax you proposed and the result is always the same unfortunately&lt;/p&gt;
&lt;p&gt;greetings, Salvio&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/587242?ContentTypeID=1</link><pubDate>Sun, 17 May 2020 10:58:06 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:580a06da-2924-487e-abcf-487ef2ea937c</guid><dc:creator>Jon Summers</dc:creator><description>[quote userid="1009364" url="~/products/programming/microstation_programming/f/microstation-programming---forum/197326/ce-c-build-display-rules-programmatically/587236"]I tried in various ways[/quote]
&lt;ol&gt;
&lt;li&gt;In your first screenshot, where you create manually a rule, the expression target is spelled &lt;code&gt;Attchment_1&lt;/code&gt; not &lt;code&gt;Attachment_1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It&amp;#39;s possible that spaces around the &lt;code&gt;=&lt;/code&gt; are not required, or confuse the expression parser.&amp;nbsp; Try...&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;string MyRuleCondition = &amp;quot;REFERENCE.References.Logical Name=Attchment_1&amp;quot;;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/587241?ContentTypeID=1</link><pubDate>Sun, 17 May 2020 10:24:02 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:99705b0e-1bc7-47ff-b1e2-304ea5513d6c</guid><dc:creator>Jan Šlegr</dc:creator><description>[quote userid="1009364" url="~/products/programming/microstation_programming/f/microstation-programming---forum/197326/ce-c-build-display-rules-programmatically/587236"]I tried in various ways (as you can see in the attached code) but unfortunately nobody works (with or without $ or @)[/quote]
&lt;p&gt;Hmmm :-(&lt;/p&gt;
&lt;p&gt;I am not able to find my old code when I tried Display Rules, but I think it&amp;#39;s about to find out how exactly the condition is stored when created manually.&lt;/p&gt;
&lt;p&gt;BTW DisplayRule class is IDisposable, your code does not contain code respecting this fact.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/587236?ContentTypeID=1</link><pubDate>Sun, 17 May 2020 09:14:32 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:97d7ddb5-400d-4f16-8f1d-7247c7afcf6a</guid><dc:creator>salvatore montella</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi Jan, &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I tried in various ways (as you can see in the attached code) but unfortunately nobody works (with or without $ or @)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;//Attempt1
string MyRuleCondition = &amp;quot;REFERENCE.References.Logical Name = Attachment_1&amp;quot;;

//Attempt2
string value = &amp;quot;Attachment_1&amp;quot;;
string MyRuleCondition = &amp;quot;REFERENCE.References.Logical Name = &amp;quot;+ value;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/587235?ContentTypeID=1</link><pubDate>Sun, 17 May 2020 09:05:34 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:d5eedc3b-2ba6-45fb-b50c-33db57ab46d1</guid><dc:creator>Jan Šlegr</dc:creator><description>&lt;p&gt;Hi Salvatore,&lt;/p&gt;
[quote userid="1009364" url="~/products/programming/microstation_programming/f/microstation-programming---forum/197326/ce-c-build-display-rules-programmatically/587230"]Here is the whole procedure I wrote to create the display rule.[/quote]
&lt;p&gt;In my opinion your original code and the more completed code does something different.&lt;/p&gt;
&lt;p&gt;In the first case, at runtime, the string is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;string MyRuleCondition = &amp;quot;REFERENCE.References.Logical Name = Attachment_1&amp;quot;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;whereas in the second code, the string is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;string MyRuleCondition = @&amp;quot;REFERENCE.References.Logical Name = &amp;quot;&amp;quot;Attachment_1&amp;quot;&amp;quot;&amp;quot;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I have not used Display Rules API often, but I remember it&amp;#39;s quite sensitive about quotation marks and other characters, because (unfortunately) the conditions are interpreted as text in this case.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/587234?ContentTypeID=1</link><pubDate>Sun, 17 May 2020 08:58:13 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:27098e0e-7e92-4812-a14c-6d1453db9381</guid><dc:creator>Jan Šlegr</dc:creator><description>[quote userid="2269" url="~/products/programming/microstation_programming/f/microstation-programming---forum/197326/ce-c-build-display-rules-programmatically/587229"]It&amp;#39;s not clear what you&amp;#39;re writing in that statement...[/quote]
&lt;p&gt;It&amp;#39;s clear in my opinion, it&amp;#39;s standard C# syntax.&lt;/p&gt;
&lt;p&gt;In my opinion @ is unnecessary, because there is nothing that requires to interpret the string literally, but it does not cause any issue.&lt;/p&gt;
&lt;p&gt;With regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/587230?ContentTypeID=1</link><pubDate>Sun, 17 May 2020 07:56:32 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:837c239a-a636-45b9-88ee-89689bfc7af8</guid><dc:creator>salvatore montella</dc:creator><description>&lt;p&gt;&lt;br /&gt;Hi Jon, thanks for replying. &lt;br /&gt;Here is the whole procedure I wrote to create the display rule.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your help,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Salvio&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt; 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 = &amp;quot;RulSet_1&amp;quot;;
            string MyRuleCondition = @&amp;quot;REFERENCE.References.Logical Name = &amp;quot;&amp;quot;Attachment_1&amp;quot;&amp;quot;&amp;quot;;

            
            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(&amp;quot;MDL KEYIN CUSTOMDISPMODE DIALOG DISPLAYSTYLES&amp;quot;);
            keyInCommand.SendKeyin(@&amp;quot;DISPLAYSTYLE CREATE &amp;quot;&amp;quot;DISPLAY_STYLE_BY_KEYIN&amp;quot;&amp;quot;&amp;quot;);
            keyInCommand.SendKeyin(@&amp;quot;MDL KEYIN VIEWCTRL CHANGE VIEW CUSTOM &amp;quot;&amp;quot;DISPLAY_STYLE_BY_KEYIN&amp;quot;&amp;quot; 1&amp;quot;);
            keyInCommand.SendKeyin(@&amp;quot;DISPLAYSTYLE SETPARAM DISPLAYRULESET &amp;quot;&amp;quot;DISPLAY_STYLE_BY_KEYIN&amp;quot;&amp;quot; &amp;quot;&amp;quot;RulSet_1&amp;quot;&amp;quot;&amp;quot;);

            ustnApp.CommandState.StartDefaultCommand();


        }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CE C# Build Display Rules programmatically</title><link>https://communities.bentley.com/thread/587229?ContentTypeID=1</link><pubDate>Sun, 17 May 2020 07:43:07 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:c8812284-33c8-463e-ba87-7aa141199a3a</guid><dc:creator>Jon Summers</dc:creator><description>[quote userid="1009364" url="~/products/programming/microstation_programming/f/microstation-programming---forum/197326/ce-c-build-display-rules-programmatically"]Could anyone tell me what is the exact way to build a rule condition from code?[/quote]
&lt;p&gt;More generally, I think we need advice on writing &lt;em&gt;Expressions&lt;/em&gt; programmatically.&amp;nbsp; It&amp;#39;s easy to get an &lt;em&gt;Expression&lt;/em&gt; wrong, but hard to get diagnostic information (as you have found).&lt;/p&gt;
[quote userid="1009364" url="~/products/programming/microstation_programming/f/microstation-programming---forum/197326/ce-c-build-display-rules-programmatically"]&lt;em&gt;&lt;strong&gt;string MyRuleCondition = $@&amp;quot;REFERENCE.References.Logical Name = {fieldValue}&amp;quot;;&lt;/strong&gt;&lt;/em&gt;&amp;quot;[/quote]
&lt;p&gt;It&amp;#39;s not clear what you&amp;#39;re writing in that statement...&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A literal string is prefixed with two special .NET modifiers &lt;code&gt;$@&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The string is terminated with an additional quote after the semi-colon&lt;/li&gt;
&lt;li&gt;How do you assign that statement to an &lt;em&gt;Expression&lt;/em&gt;?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Please write your actual code here so we can better understand what you have:&amp;nbsp; Use the &lt;em&gt;Insert|Code&lt;/em&gt; button.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>