copying the value of one attribute to another

Like copy attributes, but instead of doing it for the whole module, I need it to copy attribute values for only the objects in my current view. Anyone modify or come up with a script for that?
cliff.sadler - Fri Jan 14 09:33:53 EST 2011

Re: copying the value of one attribute to another
adevicq - Fri Jan 14 12:16:19 EST 2011

Hi,

Try this:
 

Object o
Module m = current
string fromAttr = "some attribute"
string toAttr = "some other attribute"
 
 
for o in m do {
o.toAttr = probeAttr_(o, fromAttr)
}

 


Regards,

Alain

 

Re: copying the value of one attribute to another
llandale - Fri Jan 14 13:15:35 EST 2011

The "for obj in mod" loop finds currently displayed objects and should work for this particular use. I seem to have a minority opinion about that loop in that I almost always use the "for obj in entire mod" loop, then explicitly reject objets I don't care about, typically "if (isDeleted(obj)) continue" and "if (table(obj) or row(obj) or cell(obj)) continue". I do not want my scripts routinely dependant on the current view, unless the script is specifically designed to be sensitive to that (such as your script).

There is also an undocumented assignment perm that is superior in every way to retrieving one attr value and assigning it to another:

string    set(Attr__ To,Attr__ From)
Use:
string ErrMess = set(oNew."NameAttr", oOld."NameOtherAttr")


Will accurately copy rich text along with OLE diagrams without wasting space staging the value in memory. Works for objects in different modules. Is basically equivalent to this:
oNew."NameAttr" = richText(richTextWithOle(oOld, "NameOtherAttr"))

OK, not "every way" because you get DXL errors if the attr reference doesn't exist. But this solves that problem:

 

noError()
Object o = null
set(o."New", o."Old")
string Err1 =lastError()
print "Err1: " Err1

 

 

 

  • Louie

 

 

 

  • Louie

 

Re: copying the value of one attribute to another
cliff.sadler - Fri Jan 14 13:54:06 EST 2011

Thanks for the quick followup
tightly controlled copy, so the first snippet worked great.

Re: copying the value of one attribute to another
llandale - Fri Jan 14 14:56:31 EST 2011

cliff.sadler - Fri Jan 14 13:54:06 EST 2011
Thanks for the quick followup
tightly controlled copy, so the first snippet worked great.

You know that "probeAttr_" retrieves raw text, "string probeRichAttr_(Object o, string attrName)" retrieves rich text but not OLE, and "string probeRichAttr_(Object o, string attrName, true)" retrieves rich text with OLE.

Re: copying the value of one attribute to another
bullbala - Tue Jan 18 08:06:15 EST 2011

llandale - Fri Jan 14 14:56:31 EST 2011
You know that "probeAttr_" retrieves raw text, "string probeRichAttr_(Object o, string attrName)" retrieves rich text but not OLE, and "string probeRichAttr_(Object o, string attrName, true)" retrieves rich text with OLE.

When we want to retrieve rich text without OLE, can these forms be considered as equivalents ?

string probeRichAttr_(Object o, string attrName)
string probeRichAttr_(Object o, string attrName, false)

Re: copying the value of one attribute to another
llandale - Tue Jan 18 10:29:38 EST 2011

bullbala - Tue Jan 18 08:06:15 EST 2011
When we want to retrieve rich text without OLE, can these forms be considered as equivalents ?

string probeRichAttr_(Object o, string attrName)
string probeRichAttr_(Object o, string attrName, false)

They are in fact the same, the first perm calls the 2nd one just as you suggest.
See ../lib/dxl/utils/attrutil.inc

  • Louie

Re: copying the value of one attribute to another
SystemAdmin - Fri Mar 22 14:34:41 EDT 2013

llandale - Tue Jan 18 10:29:38 EST 2011
They are in fact the same, the first perm calls the 2nd one just as you suggest.
See ../lib/dxl/utils/attrutil.inc

  • Louie

I'm trying to use the following to cut OLE objects (1 OLE per object) from the Object Text attribute into an attribute called "LD 2". The script seems like it's cutting the OLE's ok, but it is not populating the "LD 2" attribute. LD 2 is type text just like Object Text.

Any thoughts?
 

Object o
Module m = current
string fromAttr = "Object Text"
string toAttr = "LD 2"
 
 
for o in m do {
o.toAttr = set(o.fromAttr, o.toAttr)
}

 


thanks

 

Re: copying the value of one attribute to another
SystemAdmin - Fri Mar 22 14:45:32 EDT 2013

SystemAdmin - Fri Mar 22 14:34:41 EDT 2013

I'm trying to use the following to cut OLE objects (1 OLE per object) from the Object Text attribute into an attribute called "LD 2". The script seems like it's cutting the OLE's ok, but it is not populating the "LD 2" attribute. LD 2 is type text just like Object Text.

Any thoughts?
 

Object o
Module m = current
string fromAttr = "Object Text"
string toAttr = "LD 2"
 
 
for o in m do {
o.toAttr = set(o.fromAttr, o.toAttr)
}

 


thanks

 

o.toAttr = set(o.fromAttr, o.toAttr)

 


use just (probably you have also from/to wrong way round)

 

 

 

set(o.toAttr, o.fromAttr)

 

 

 

  • Pekka Mäkinen - http://www.softqa.eu/

 

Re: copying the value of one attribute to another
SystemAdmin - Fri Mar 22 15:48:32 EDT 2013

SystemAdmin - Fri Mar 22 14:45:32 EDT 2013

o.toAttr = set(o.fromAttr, o.toAttr)

 


use just (probably you have also from/to wrong way round)

 

 

 

set(o.toAttr, o.fromAttr)

 

 

 

  • Pekka Mäkinen - http://www.softqa.eu/

 

you're absolutely right about the flip flop and taking off the prefix. The following copied the OLE from object text to my other attribute just like I wanted.
 

//set(oTo."NameAttr", oFrom."NameOtherAttr")
 
Object o
Module m = current
string fromAttr = "Object Text"
string toAttr = "LD"
 
 
for o in m do {
set(o.toAttr, o.fromAttr)
}

 


Thanks so much

 

Re: copying the value of one attribute to another
SystemAdmin - Fri Mar 22 15:58:06 EDT 2013

SystemAdmin - Fri Mar 22 15:48:32 EDT 2013

you're absolutely right about the flip flop and taking off the prefix. The following copied the OLE from object text to my other attribute just like I wanted.
 

//set(oTo."NameAttr", oFrom."NameOtherAttr")
 
Object o
Module m = current
string fromAttr = "Object Text"
string toAttr = "LD"
 
 
for o in m do {
set(o.toAttr, o.fromAttr)
}

 


Thanks so much

 

and the following will delete the original OLE as well after the copy
 

//set(oTo."NameAttr", oFrom."NameOtherAttr")
 
Object o
Module m = current
string fromAttr = "Object Text"
string toAttr = "LD"
 
 
for o in m do {
set(o.toAttr, o.fromAttr)
oleDelete (o)
}

Re: copying the value of one attribute to another
llandale - Mon Mar 25 12:47:01 EDT 2013

SystemAdmin - Fri Mar 22 15:58:06 EDT 2013

and the following will delete the original OLE as well after the copy
 

//set(oTo."NameAttr", oFrom."NameOtherAttr")
 
Object o
Module m = current
string fromAttr = "Object Text"
string toAttr = "LD"
 
 
for o in m do {
set(o.toAttr, o.fromAttr)
oleDelete (o)
}

I am guessing that oleDelete(Object) only deletes the 1st OLE in Object Text. Test this with text with 3 OLEs:

int  Count = 0
bool More  = false
while(More) 
{  More = oleDelete(o)
   if (More) print "OLE Deleted\t#" Count++
}


-Louie