Copy attributes from a module to another

Hi,

I try to copy some attributes from a module to another.
I want to import by DXL some attributes frome one module to another.

I do it by selecting Edit / Attributes... / Import but I want to have it automatically.

Can someone help me ?
Estebell - Fri Jun 15 03:51:05 EDT 2012

Re: Copy attributes from a module to another
xEntwicklung - Fri Jun 15 07:56:54 EDT 2012

You can use this function:
void copyAttributeDefinition(Module m_source, Module m_target, AttrDef ad_source, string s_newName)
{

AttrType at_target = null
AttrType at_source = null
string s_typeName = ""

if(!null m_source && !null m_target && !null ad_source && s_newName != "")
{
// find type of source attrdef
s_typeName = ad_source.typeName ""
at_target = find(m_target, s_typeName)

if (null at_target) // if the type of the attrdef does not exist in the target module, create it
{
at_source = find(m_source, s_typeName) // type of attribute does not exist in target module, copy from source module
copyAttrType_(at_source, m_source, m_target)
}

bool ismulti = ad_source.multi
AttrDef__ a = date false history false changeBars false inherit false multi ismulti attribute s_newName
a = type s_typeName a

if (ad_source.object) a = object a
if (ad_source.module) a = module a
create a
}
}

Re: Copy attributes from a module to another
mcnairk - Fri Jun 15 08:00:04 EDT 2012

Not sure what you mean "automatically". if you mean that when you update the attributes in one module, distribute the changes to multiple other modules then the attached DXLs may be of use. They both work, but slightly differently. Note the warnings that it's easy to wipe out attribute settings, especially for enumerated values.

Ken.
Attachments

attachment_14838884_CopyAttrsPlus.dxl

Re: Copy attributes from a module to another
mcnairk - Fri Jun 15 08:01:54 EDT 2012

mcnairk - Fri Jun 15 08:00:04 EDT 2012
Not sure what you mean "automatically". if you mean that when you update the attributes in one module, distribute the changes to multiple other modules then the attached DXLs may be of use. They both work, but slightly differently. Note the warnings that it's easy to wipe out attribute settings, especially for enumerated values.

Ken.

Second version.

Ken.
Attachments

attachment_14838885_CopyAtts-v13.dxl

Re: Copy attributes from a module to another
Estebell - Mon Jun 18 02:55:55 EDT 2012

mcnairk - Fri Jun 15 08:01:54 EDT 2012
Second version.

Ken.

Hi I will try these codes and see what works good for me.
Thanks !

Re: Copy attributes from a module to another
Estebell - Mon Jun 18 03:35:07 EDT 2012

Estebell - Mon Jun 18 02:55:55 EDT 2012
Hi I will try these codes and see what works good for me.
Thanks !

Hi,

The last code given by mcnairk works good. But I have some attributes that use enumerated types for example.
can I also copy types and update existing types ?

BR

Re: Copy attributes from a module to another
mcnairk - Mon Jun 18 08:38:44 EDT 2012

Estebell - Mon Jun 18 03:35:07 EDT 2012
Hi,

The last code given by mcnairk works good. But I have some attributes that use enumerated types for example.
can I also copy types and update existing types ?

BR

CopyAttrsPlus has a check-box for this, but read the warnings very carefully to avoid loss of data. If in doubt, baseline and/or archive the module first...

ken.

Re: Copy attributes from a module to another
Barmen - Mon Oct 22 08:36:08 EDT 2012

What I need to add to current script to apply a next functionality: when I update the attributes in one module, distribute the changes to multiple other modules then the attached DXLs may be of use?
And second question : why I can get list of all "Formal" modules ( from all Projects?

Re: Copy attributes from a module to another
Skotagiri - Thu Oct 25 04:36:23 EDT 2018

mcnairk - Fri Jun 15 08:01:54 EDT 2012
Second version.

Ken.

Hallo When I'm trying this script I'm getting a error to bring the colors from the source module to Target module. Could you please help me.

Invalid color specification (42)

Re: Copy attributes from a module to another
Skotagiri - Thu Oct 25 04:37:17 EDT 2018

mcnairk - Fri Jun 15 08:01:54 EDT 2012
Second version.

Ken.

Hallo When I'm trying this script I'm getting a error to bring the colors from the source module to Target module. Could you please help me.

-R-E- DXL: <Line:147> Invalid color specification (42)