how to filter attributes with different values

Hi,

I did a search without success.

I'd like to filter objects that has not the same value in 2 different attribute (this filter will be used inside a DXL for view's building).

something like: f = attribute "Object Type VAL" != attribute "Object Type"

Both attribute are enumerations.

Right now I'm doing it listening all possible cases but I'm looking for something smarter than this.

f = (((attribute "Object Type VAL" != "Heading") && (attribute "Object Type" == "Heading")) || ((attribute "Object Type VAL" != "Test Requirement") && (attribute "Object Type" == "Test Requirement")) || ((attribute "Object Type VAL" != "Support Information") && (attribute "Object Type" == "Support Information")) || ((attribute "Object Type VAL" != "Requirement") && (attribute "Object Type" == "Requirement")) || ((attribute "Object Type VAL" != "") && (attribute "Object Type" == "")) || ((attribute "Object Type VAL" == "") && (attribute "Object Type" != "")))

 

Thanks a lot in advance.

 

Regards,

Daniele


dacapri - Wed Sep 25 04:46:03 EDT 2013

Re: how to filter attributes with different values
GregM_dxler - Wed Sep 25 09:54:25 EDT 2013

Hello,

It looks like attributes are enumerations, but can only contain a single value.  I made a filter a while ago that may work, just does the opposite, filters for only when the two attributes match.  It can be easily changed by swapping the reject/accept commands.

 

Hope this helps,

Greg

// Filters a module for 2 attributes that are not identical

/* This routine filters out all of the objects in a module
that have two different attributes that match  */

Object o
int iCnt = 0
string sAttr1 = "Object Type VAL" //First attribute
string sAttr2 = "Object Type"
string s
string t

 

void search(){
   filtering off
   ancestors (false)
   for o in (current Module) do {
      s = o.sAttr1
      t = o.sAttr2
      if (s == t) {
         reject o
      } else {
         accept o
         iCnt++
      }
   }
   filtering on
   refresh current Module
}

/*** Main Program ***/

search()
print "Found " iCnt "\n"

Re: how to filter attributes with different values
llandale - Wed Sep 25 12:48:26 EDT 2013

If you do NOT need to save the filter in a view, Greg's accept/reject method looks good.

If you DO need to save the Filter in a view, I think your way is the only way using just "Filters".

However, you could add an Attr-DXL to do the work, then Filter on whether this single attr is "SAME" or "DIFFERENT"

  • if (probeAttr_(obj, "Object Type VAL") == probeAttr_(obj, "Object Type")) //
  • then obj.attrDXLName = "SAME"
  • else obj.attrDXLName = "DIFFERENT"

-Louie

Re: how to filter attributes with different values
dacapri - Mon Sep 30 03:13:32 EDT 2013

llandale - Wed Sep 25 12:48:26 EDT 2013

If you do NOT need to save the filter in a view, Greg's accept/reject method looks good.

If you DO need to save the Filter in a view, I think your way is the only way using just "Filters".

However, you could add an Attr-DXL to do the work, then Filter on whether this single attr is "SAME" or "DIFFERENT"

  • if (probeAttr_(obj, "Object Type VAL") == probeAttr_(obj, "Object Type")) //
  • then obj.attrDXLName = "SAME"
  • else obj.attrDXLName = "DIFFERENT"

-Louie

Hello Louie,

I'd need to save the filter in a view (using triggers).

So, looks like there isn't a direct way to compare them. I'll try with a probe attribute.

Many thanks.

 

Daniele

Re: how to filter attributes with different values
dacapri - Thu Jan 30 02:53:42 EST 2014

llandale - Wed Sep 25 12:48:26 EDT 2013

If you do NOT need to save the filter in a view, Greg's accept/reject method looks good.

If you DO need to save the Filter in a view, I think your way is the only way using just "Filters".

However, you could add an Attr-DXL to do the work, then Filter on whether this single attr is "SAME" or "DIFFERENT"

  • if (probeAttr_(obj, "Object Type VAL") == probeAttr_(obj, "Object Type")) //
  • then obj.attrDXLName = "SAME"
  • else obj.attrDXLName = "DIFFERENT"

-Louie

Thank you Louie.

At the end I've used your solution with a Layout-DXL instead of Attr-DXL :

if (probeAttr_(obj, "Object Type VAL") == probeAttr_(obj, "Object Type")) then
display("SAME")
else
display("DIFFERENT")