Converting object heading to object text

Hi,

I'm trying to convert all of an imported module's object headings into object text with a script. I figured if an object has a nonempty Object Heading but an empty Object Text, it matches my criteria to do a conversion. So far I have the following:

Object o

for o in all current Module do {
        if (!null o."Object Heading" && null o."Object Text") {
                o."Object Text" = richText(o."Object Heading")
                o."Object Heading" = null
        }
}

When I click Run, there are no errors; however nothing happens to my module. I think even though the Object Text may appear empty, it is not null. Is there a way I can fix this?

Thank you!


DoanD - Wed Jul 19 14:21:22 EDT 2017

Re: Converting object heading to object text
HPM2BP - Thu Jul 20 03:06:01 EDT 2017

Hello!

 

First of all I'd suggest using another method gaining information. Similar, but a bit different. Also I'd use a string between gaining info, and writing info:

Object o
string strTemp = ""

for o in all current Module do {
        if ((o."Object Heading" "" != "") and (o."Object Text" "" == "")) {
                                strTemp = richText(o."Object Heading")
                o."Object Text" = richText(strTemp)
                o."Object Heading" = null
        }
}

Tell me, how it worked out!

Best Regards,
Peter

Re: Converting object heading to object text
Mathias Mamsch - Thu Jul 20 04:13:45 EDT 2017

HPM2BP - Thu Jul 20 03:06:01 EDT 2017

Hello!

 

First of all I'd suggest using another method gaining information. Similar, but a bit different. Also I'd use a string between gaining info, and writing info:

Object o
string strTemp = ""

for o in all current Module do {
        if ((o."Object Heading" "" != "") and (o."Object Text" "" == "")) {
                                strTemp = richText(o."Object Heading")
                o."Object Text" = richText(strTemp)
                o."Object Heading" = null
        }
}

Tell me, how it worked out!

Best Regards,
Peter

For explanation why your code does not work: 

obj."String" in DOORS does NOT return string. It returns an undocumented Attr__ type object ... Therefore when you compare this object to null like this: 

(! null obj."String")    --> will never be null --> always be true

or compare them like this: 

(obj."String" != obj2."String")  --> will never be equal --> never be executed

Then you are comparing the objects, not the content. That is why you need to get the content by "appending" quotes: 

(!null obj."String" "") 

You can see this behaviour from the perms Excel list (available on the forum). Regards, Mathias

Re: Converting object heading to object text
DoanD - Thu Jul 20 11:59:41 EDT 2017

Mathias Mamsch - Thu Jul 20 04:13:45 EDT 2017

For explanation why your code does not work: 

obj."String" in DOORS does NOT return string. It returns an undocumented Attr__ type object ... Therefore when you compare this object to null like this: 

(! null obj."String")    --> will never be null --> always be true

or compare them like this: 

(obj."String" != obj2."String")  --> will never be equal --> never be executed

Then you are comparing the objects, not the content. That is why you need to get the content by "appending" quotes: 

(!null obj."String" "") 

You can see this behaviour from the perms Excel list (available on the forum). Regards, Mathias

Thank you for your explanation! I was wondering why the null was false despite the text being empty - now it makes a lot of sense.

Re: Converting object heading to object text
DoanD - Thu Jul 20 12:02:07 EDT 2017

HPM2BP - Thu Jul 20 03:06:01 EDT 2017

Hello!

 

First of all I'd suggest using another method gaining information. Similar, but a bit different. Also I'd use a string between gaining info, and writing info:

Object o
string strTemp = ""

for o in all current Module do {
        if ((o."Object Heading" "" != "") and (o."Object Text" "" == "")) {
                                strTemp = richText(o."Object Heading")
                o."Object Text" = richText(strTemp)
                o."Object Heading" = null
        }
}

Tell me, how it worked out!

Best Regards,
Peter

This was really close -- it was just missing one = sign in the second if condition:

Object o
string strTemp = ""

for o in all current Module do {
        if ((o."Object Heading" "" != "") and (o."Object Text" "" == "")) {
                                strTemp = richText(o."Object Heading")
                o."Object Text" = richText(strTemp)
                o."Object Heading" = null
        }
}

Thank you!

Re: Converting object heading to object text
HPM2BP - Fri Jul 21 03:14:14 EDT 2017

DoanD - Thu Jul 20 12:02:07 EDT 2017

This was really close -- it was just missing one = sign in the second if condition:

Object o
string strTemp = ""

for o in all current Module do {
        if ((o."Object Heading" "" != "") and (o."Object Text" "" == "")) {
                                strTemp = richText(o."Object Heading")
                o."Object Text" = richText(strTemp)
                o."Object Heading" = null
        }
}

Thank you!

No problem, glad it worked out :)

Also I corrected the missing "=" in the original comment, now the answer marked will be correct too.