Topic
11 replies Latest Post - ‏2013-10-25T06:49:39Z by oaklodge
Zooby
Zooby
7 Posts
ACCEPTED ANSWER

Pinned topic Attribute Compare DXL

‏2012-08-22T17:40:34Z |
So I have a simple, not very long at all, DXL layout script that compares two attributes within a module and shows the differences in a column. My only problem, however, is that for some reason it is showing the differences 30 times in a row (not just once). I was wondering if someone could take a quick look and be able to see why this is happening. My script is as follows:

//compareAttributes
Module mnew = current
//Attributes to be compared
string attribut1 = "TPRC_1";
string attribut2 = "TPRC_2";

//Check whether attributes exist
AttrDef ad
string Text=""
if(exists(attribute attribut1)&&exists(attribute attribut2))
{
//Compare Attributes
if(obj.attribut1"" == obj.attribut2"")
display "true"
else

for ad in mnew do
{

Buffer bufCur = create()
bufCur=obj.attribut1""
Buffer bufOld = create()

bufOld=obj.attribut2""
if (bufCur!=bufOld)
{
Buffer bufDiff = create()
diff(bufDiff, bufOld, bufCur, "\\b\\cf1\\strike ", "\\b\\cf3\\ul ")
Text = Text stringOf(bufDiff) " \n"
delete(bufDiff)
}

delete(bufOld)
delete(bufCur)

}
displayRichWithColor(Text)
}
else if(!exists(attribute attribut1))
display "Attribut1 does not exist";
else if(!exists(attribute attribut2))
display "Attribut2 does not exist";
Updated on 2012-08-23T13:31:28Z at 2012-08-23T13:31:28Z by llandale
  • llandale
    llandale
    2939 Posts
    ACCEPTED ANSWER

    Re: Attribute Compare DXL

    ‏2012-08-22T18:08:34Z  in response to Zooby
    Get rid of this loop:
    • for ad in mnew do
    • {

    This statement is always false ..err.. true; it compares the variables but you want to compare the contents:
    • if (bufCur!=bufOld)
    But you don't need that anyway, you compared contents further up.

    This "else" clause needs braces {}:
    • display "true"
    • else

    -Louie
    • Zooby
      Zooby
      7 Posts
      ACCEPTED ANSWER

      Re: Attribute Compare DXL

      ‏2012-08-22T18:54:55Z  in response to llandale
      Thank you! That worked perfectly. Now, however, I just wanted to add a bit where for the first buffer it would use Object Heading for the first attribute in the compare if the main column is an object heading, and it would use Object Text for the same first attribute (in the compare) if the main column is object text for each individual object. I don't know if this is possible (I don't know if the obj.attribut1 can have attribut1 change for individual objects). As an example I tried putting this in near the beginning of the script:

      string attribut2 = "TPRC_2";
      string one = "Object Heading";
      string two = "Object Text";
      if (obj.one"" != "") then
      {
      string attribut1 = "Object Heading"
      }
      if (obj.two"" != "") then
      {
      string attribut1 = "Object Text"
      }
      • llandale
        llandale
        2939 Posts
        ACCEPTED ANSWER

        Re: Attribute Compare DXL

        ‏2012-08-23T13:31:28Z  in response to Zooby
        You need to declare it, THEN conditionally set the value. In your case variable "attribut1" ceases to exist (is "undefined")after the "then" and "else" clauses (end brace "}")
        • int i = 0
        • if (true) then {int i = 4, j = 3} // two new variables; confusing when i is same name as i defined above
        • print i "\n" // prints 0, not 4
        • print j "\n" // j undefined

        In your case:
        • string attribut1
        • if (!null obj."Object Heading" "") //
        • then attribut1 = "Object Text"
        • else attribut1 = "Object Heading"

        However, I'd be tempted also to do just a single retrieval:
        • Buffer bufFrom = create()
        • bufFrom = obj."Object Heading"
        • if (length(bufFrom) == 0) then bufFrom = obj."Object Text"

        -Louie
    • Mathias Mamsch
      Mathias Mamsch
      1911 Posts
      ACCEPTED ANSWER

      Re: Attribute Compare DXL

      ‏2013-10-23T18:46:26Z  in response to llandale

      Just one remark @Louie - there is indeed a content comparison in DXL for Buffers. Run this code: 

      Buffer b1 = create(); b1 = "DEF";
      Buffer b2 = create(); b2 = "DEF";

      bool bNotEqual = b1 != b2; // if what you say is true, this should be true
      bool bEqual    = b1 == b2; // if what you say is true, this should be false

      print "bNotEqual (if false, then comparison was performed): " bNotEqual "\n"
      print "bEqual (if true then comparison was performed): " bEqual "\n"

      Regards, Mathias

      • llandale
        llandale
        2939 Posts
        ACCEPTED ANSWER

        Re: Attribute Compare DXL

        ‏2013-10-24T14:27:23Z  in response to Mathias Mamsch

        I sit corrected.  Browsing the doors.exe I see these "==" functions:

        • Filter   ::==(Fattr_,string)
        • Permission ::==(Permission,Permission) 
        • bool     ::==(_xx,_xx)
        •  
        • bool     ::==(ModuleVersion,ModuleVersion)
        • bool     ::==(Buffer,Buffer) 
        • bool     ::==(real,real)
        • bool     ::==(Date,Date)
        • bool     ::==(string,string)
        • bool     ::==(char,char)
        • bool     ::==(int,int)

        Ignoring the 1st three, it appears the others indicate "==" means "are contents the same?".  I wonder are there other data types that actually HAVE contents, or are all the others comparing only Addresses?  What does the 3rd one mean?

        - Louie

        PS.  "Browsing the doors.exe" is the only VooDoo I DooDoo.

        • Mathias Mamsch
          Mathias Mamsch
          1911 Posts
          ACCEPTED ANSWER

          Re: Attribute Compare DXL

          ‏2013-10-24T15:47:15Z  in response to llandale

          The third one is actually the one that compares anything else (as long as the datatype is the same on the left side). In DXL if you use those underscore types the order in which you define functions actually matters. The ones that you declare last take precedence over the ones you declare first. You can use this to create functions that work on any type, but have special implementations for certain types.

          Note that the underscore types stand for any type, but if you use the same underscore type in a function

          /*
          bool compare (_x A, _y B) {
             print "You can compare variables with different types:"

             return (A int  == B int )}
          */

          bool compare (_xx A, _xx B) {
             print "You can only compare variables of the same type:"
             return (A int  == B int )
          }

          bool compare (int A, int B) {
             print "Special integer comparison (Note: nothing equals 7):"
             return (A == B) && A != 7
          }

          Folder fldA = folder "/"; Folder fldB = null; Folder fldC = folder "/";
          Project p = project "/";

          print compare(fldA, fldB) "\n"
          print compare(fldA, fldC) "\n"
          // print compare(fldA, p) "\n"   // does not work with Same Type comparison

          int intA = 10, intB = 10;
          print compare(intA, intB) "\n"
          print compare(7, 7) "\n"

          So what we implemented above pretty much does, that the ::==(_xx, _xx) function does. A simple content comparison (pretty much treat the variable it like an integer).  Hope this clarifies things, sorry for going off topic. Regards, Mathias

          • llandale
            llandale
            2939 Posts
            ACCEPTED ANSWER

            Re: Attribute Compare DXL

            ‏2013-10-24T18:26:43Z  in response to Mathias Mamsch

            You seem to be having some success draging me, kicking and screaming, into your underworld.

            So, "yes"? the generic "::==" perm compares the address whereas the specific ones usually compare the contents?

            -Louie

  • Praveenrc
    Praveenrc
    2 Posts
    ACCEPTED ANSWER

    Re: Attribute Compare DXL

    ‏2013-10-23T17:33:34Z  in response to Zooby

    Instead of strings in attributes, if the attributes contains ole objects ....how to find that attributes contain ole objects??

    and I want the script to print the result as 

    " is "

    ole object in attribute1

    "was"

    ole object in attribute

     

    your help is appreciated , thanks 

    Updated on 2013-10-23T17:38:06Z at 2013-10-23T17:38:06Z by Praveenrc
    • Zooby
      Zooby
      7 Posts
      ACCEPTED ANSWER

      Re: Attribute Compare DXL

      ‏2013-10-23T18:03:45Z  in response to Praveenrc

      My experience has not gone so far as to deal with OLE objects much.  If it is comparing them that you want to do, then I don't think it's possible to compare OLE objects.  I could be wrong, however.

      • llandale
        llandale
        2939 Posts
        ACCEPTED ANSWER

        Re: Attribute Compare DXL

        ‏2013-10-24T14:31:50Z  in response to Zooby

        These perms work:

        • bool     containsOle(Attr__)
        • int      oleCount(Attr__)

        e.g.

        • if (containsOle(o."MyTextAttr")) then get the OLE

        -Louie

        The "bool oleIsObject(Object)" perm considers only "Object Text".