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
Jon Summers said:It's not clear what you're writing in that statement...
It's clear in my opinion, it's standard C# syntax.
In my opinion @ is unnecessary, because there is nothing that requires to interpret the string literally, but it does not cause any issue.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan,
I tried in various ways (as you can see in the attached code) but unfortunately nobody works (with or without $ or @)
//Attempt1 string MyRuleCondition = "REFERENCE.References.Logical Name = Attachment_1"; //Attempt2 string value = "Attachment_1"; string MyRuleCondition = "REFERENCE.References.Logical Name = "+ value;
salvatore montella said:I tried in various ways (as you can see in the attached code) but unfortunately nobody works (with or without $ or @)
Hmmm :-(
I am not able to find my old code when I tried Display Rules, but I think it's about to find out how exactly the condition is stored when created manually.
BTW DisplayRule class is IDisposable, your code does not contain code respecting this fact.
Regards,
salvatore montella said:I tried in various ways
Attchment_1
Attachment_1
=
string MyRuleCondition = "REFERENCE.References.Logical Name=Attchment_1";
Hi Jon.Attachment_1, Attchment_1, Foo, TestName ... don't make a difference, these are just the value of the logical name of the attachment.The problem is that Microstation does not create the rule and returns the error "Unrecognize Criteria", not that Micorstation creates the rule and then cannot resolve it.I also tried with the syntax you proposed and the result is always the same unfortunately
greetings, Salvio