[CONNECT Update 15 C++] Display Rule API

When I create a Display Rule manually it works...

Display Rule

When I write the same rule using code...

DisplayRulePtr displayRule = mgr.MakeRule (L"ELEMENT.Area Feature.occupied=No");

Display Rule

The Display Rules dialog tells me Unrecognized criteria!  There is no further explanation.  How can I diagnose problems with Display Rules?

You can reproduce this using the delivered SDK example ..\View\DisplayRule.  If I use that example's command to add a rule, it also fails when the rule involves an Item Type; the code succeeds if it concerns a raw element property.

The failure seems to occur when setting a rule for an Item Type property value.  Is there something about Item Types that affects the way in which a rule should be specified?

Parents
  • Hi Jon,

    is it possible to share test case (DGN with Item Type Lib, even limited to queried property, and one element)?

    Regards,

      Jan

  • is it possible to share test case (DGN with Item Type Lib, even limited to queried property, and one element)?

    Here's a DGN file with AreaAnnotator and DoorKeeper Item Type defintions, and several DGN elements tagged with those Item Types.

    AreaAnnotator8.dgn

     
    Regards, Jon Summers
    LA Solutions

  • Wrote a listRuleCondition function to check your DGN file and got the below results:

    But when I checked your DisplayRule definition, its definition seems incorrect. Shown as below:

    [What we see the rule condition in the Display Rules dialog is just rule description not its definition. We can see its definition in Condition Editor dialog].

    Then I correct it as below:

    and re-get its content as below:

    So the format "element.ItemTypeLibraryName::ItemTypeName::PropertyName=Value" is almost right except:

    1. Prefix DgnCustomItemTypes_  at the actual ItemTypeLibraryName;
    2. Use __x0020__ to replace a blank character.



  • the format "element.ItemTypeLibraryName::ItemTypeName::PropertyName=Value" is almost right

    Thanks!  How do you show the complete expression in the Message Center?

    Almost Right

    When I set the rule programmatically, it remains incorrect whether I use the display name or the internal name of the schema...

    Display Name not correct

    Internal Name not correct

    Internal Names

    1. Prefix DgnCustomItemTypes_  at the actual ItemTypeLibraryName
    2. Use __x0020__ to replace a blank character

    We can get those by calling GetInternalName()...

    Bentley::WString  ItemTypes::GetInternalName (WStringCR	name)
    {
      WString  internalName;
      ECNameValidation::EncodeToValidName (internalName, name);
      return   internalName;
    }
    

    Some EC classes have a similar method already available.

     
    Regards, Jon Summers
    LA Solutions

  • How do you show the complete expression in the Message Center?

    This isn't MessageCenter, just a temporary message dialog. I use below function listDisplayRules to do this.

    void listDisplayRules(WCharCP ruleSetName)
    {
    	DgnFileP pDgnFile = ISessionMgr::GetActiveDgnFile();
    	DisplayRuleSetCP ruleSetCP = DisplayRulesManager::GetDisplayRuleSetByName(ruleSetName, *pDgnFile);
    	if (nullptr == ruleSetCP)
    	{
    		mdlDialog_dmsgsPrint(L"nullptr == ruleSetCP");
    		return;
    	}
    	DisplayRuleSetPtr ruleSet = ruleSetCP->Clone(*pDgnFile);
    	for (DisplayRulePtr rule : ruleSet->GetDisplayRules())
    	{
    		WStringCR  ruleCond = rule->GetCondition();
    		mdlDialog_dmsgsPrint(ruleCond.GetWCharCP());
    	}
    }

    When I set the rule programmatically, it remains incorrect whether I use the display name or the internal name of the schema...

    I firstly create a test rule set named FooRuleSet. Then I type below keyins which works fine.

    MDL LOAD DisplayRule
    displayrule create rule FooRuleSet element.DgnCustomItemTypes_AreaAnnotator_1_0::Area__x0020__Feature::occupied=True ElementDisplay

    We can get those by calling GetInternalName()...

    Yes. You are right. But without correcting DisplayRule example, we have to keyin raw rule condition.



  • without correcting DisplayRule example,

    Here's a modified DisplayRule example.

    DisplayRule.zip

    I've added a new command:

    displayrule create ruleItemType rule-set-name schema-name item-name property-name condition ElementDisplay 

    Example:

    displayrule create ruleItemType FooRuleSet AreaAnnotator_1_0 "Area Feature" Occupied =True ElementDisplay 

    That rule does nothing very exciting!  It assembles those arguments into a string and then creates the rule.  However, it doesn't work.  The best I can do is to create a schema name that looks correct to the human eye, but results in an invalid rule definition.

    I conclude that the DisplayRule class is looking for a schema name in a very particular format, but which is undocumented.

     
    Regards, Jon Summers
    LA Solutions

  • I continue to search for a solution to this problem: unable to set a Display Rule for an Item Type programmatically.  The modified DisplayRule example includes a new command to help analyze the problem.

    DisplayRule.zip

     
    Regards, Jon Summers
    LA Solutions

  • Have you followed my test steps strictly? It really can create our own rule.

    Maybe need us close and reopen the Display Rule dialog to check the result.



  • Have you followed my test steps strictly?

    I've finally solved my problem, after following your advice to be strict!

    Here's a display rule definition that is incorrect...

    Bad Display Rule

    And here's a correct definition...

    Good Display Rule

    Spot the difference!  I'll help you: in both rule definitions I include the Item Type library name, schema name and property name, separated by double-colons (the Area Feature looks odd because there's a space in its name)...

    DgnCustomItemTypes_AreaAnnotator_1_0::Area__x0020__Feature::occupied

    In the good definition, the Display Rules dialog displays the accepted expression as ELEMENT.Area Feature.occupied.

    In the bad definition, the Display Rules dialog displays the message 'Schema not found: DgnCustomItemTypes_AreaAnnotator_1_0'.  But, if you examine the definition, you can see that the schema name is exactly the same in both cases.  The cause of my trouble is my spelling of the property occupied.  When a capitalised name is used (Occupied)  then the Display Rules dialog tells me that the schema is incorrect, which I hope you'll agree is a misleading diagnostic message.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Jon Summers 

Reply
  • Have you followed my test steps strictly?

    I've finally solved my problem, after following your advice to be strict!

    Here's a display rule definition that is incorrect...

    Bad Display Rule

    And here's a correct definition...

    Good Display Rule

    Spot the difference!  I'll help you: in both rule definitions I include the Item Type library name, schema name and property name, separated by double-colons (the Area Feature looks odd because there's a space in its name)...

    DgnCustomItemTypes_AreaAnnotator_1_0::Area__x0020__Feature::occupied

    In the good definition, the Display Rules dialog displays the accepted expression as ELEMENT.Area Feature.occupied.

    In the bad definition, the Display Rules dialog displays the message 'Schema not found: DgnCustomItemTypes_AreaAnnotator_1_0'.  But, if you examine the definition, you can see that the schema name is exactly the same in both cases.  The cause of my trouble is my spelling of the property occupied.  When a capitalised name is used (Occupied)  then the Display Rules dialog tells me that the schema is incorrect, which I hope you'll agree is a misleading diagnostic message.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Jon Summers 

Children
No Data