Topic
  • 5 replies
  • Latest Post - ‏2013-06-06T04:31:00Z by Pekka_Makinen
Skaifey05
Skaifey05
2 Posts

Pinned topic Setting Attribute Default Value

‏2013-06-05T06:06:50Z |

Hi,

I am planning to copy an existing populated module to another folder (in the same database) to use it as a template for a new module, because I want all the same attributes, as well as the object layout etc.

When I copy the module, I want to go thru and reset all the attributes to their Default Values, as the value will be different for the new module.

Does anyone have a simple DXL script that I can run that will got thru each attribute and reset it to the default value, or is there another way of doing this?

Thanks

Mark

Updated on 2013-06-05T06:08:38Z at 2013-06-05T06:08:38Z by Skaifey05
  • Johnny_P
    Johnny_P
    25 Posts

    Re: Setting Attribute Default Value

    ‏2013-06-05T08:33:20Z  

    Hi,

    that depends on how many attributes you want to reset. If there are just a few attributes, the quickest way would be via the object properties window. In the Attributes tab you can select an attribute, assign a value and apply to "Objects in current view" or "Selected objects".

     

    Some time ago I wrote a little script to reset attribute values for selected attributes.

    1. Make sure, that you have no filter applied if you want to reset the attribute for ALL objects (The script asks you if you want to apply the default values only for values in the current view if you have a filter applied)
    2. Select the attributes you want to reset
    3. Click "Reset values" and "Continue" if you are sure, that you have selected the correct attributes.

    So if you have a lot of attributes you can try it:

    Module m = current
    AttrDef ad = null
    string sDummy[] = {}
    DB dbAttr = null
    DBE dbeListViewAttributes = null
    DBE dbeButtonSelectAll = null
    DBE dbeButtonDeselectAll = null
    int iIndex = 0

    // select all checkboxes
    void selectAll(DBE dbe)
    {
        int i = null
        int iNoElems = noElems(dbeListViewAttributes)
        
        for (i=0; i<iNoElems; i++)
        {
            setCheck(dbeListViewAttributes, i, true)
        }
    }

    // deselect all checkboxes
    void deselectAll(DBE dbe)
    {
        int i = null
        int iNoElems = noElems(dbeListViewAttributes)
        
        for (i=0; i<iNoElems; i++)
        {
            setCheck(dbeListViewAttributes, i, false)
        }
    }

    // reset selected attribute values
    void resetValues(DB db)
    {
        int i = null
        int iNoElems = noElems(dbeListViewAttributes)
        int iAttrCounter = 0
        Object o = null
        string sCurAttribute = null
        Skip skpAttributesToReset = createString()
        bool bCancel = false
        
        for (i=0; i<iNoElems; i++)
        {
            if (getCheck(dbeListViewAttributes, i))
            {
                sCurAttribute = getColumnValue(dbeListViewAttributes, i, 0)
                put(skpAttributesToReset, sCurAttribute, sCurAttribute)
                iAttrCounter++
            }
        }

        string sChoices[] = { "Continue", "Cancel" }
        int iContinue = query("You are about to reset the values for all selected attributes (" iAttrCounter "):\n\nDo you want to continue?", sChoices)
        
        // continue
        if (iContinue == 0)
        {
            // check if a filter is applied
            if (filtering(m))
            {    
                string sChoicesFilter[] = { "Continue with applied filter", "Disable filter and continue", "Cancel" }
                int iMode = query("There is a filter applied.\nDo you want to continue and reset only attribute values for objects in the current view or do you want to disable the filter?", sChoicesFilter)
                
                if (iMode == 0) {} // continue
                elseif (iMode == 1)
                {
                    filtering off
                }
                elseif (iMode == 2)
                {
                    bCancel = true
                }
            }
            
            if (!bCancel)
            {
                // loop through all objects in the view and reset all selected attribute values
                for o in m do
                {
                    for sCurAttribute in skpAttributesToReset do
                    {
                        o.sCurAttribute = ""
                    }
                }
            }
        }
        elseif (iContinue == 1)
        {
            bCancel = true
        }
        
        
        refresh m
        delete skpAttributesToReset
        
        if (!bCancel)
        {
            destroy db
            infoBox "done"
        }
    }

    dbAttr = create("Reset attribute values", styleCentered)
    dbeListViewAttributes = listView(dbAttr, listViewOptionCheckboxes, 300, 10, sDummy)
    dbeButtonSelectAll = button(dbAttr, "Select all", selectAll)
    beside dbAttr
    dbeButtonDeselectAll = button(dbAttr, "Deselect all", deselectAll)
    apply(dbAttr, "Reset values", resetValues)

    realize dbAttr
    insertColumn(dbeListViewAttributes, 0, "Attributes", 250, iconNone)
    setExtraHeightShare(dbeListViewAttributes, 1.0)

    // list all available attributes in the listview
    for ad in m do
    {
        if (!ad.object || ad.system) { continue } // skip module only attributes and systems attributes
        insert(dbeListViewAttributes, iIndex++, ad.name)
    }

    show dbAttr

    Regards Johnny

     

  • Mike.Scharnow
    Mike.Scharnow
    199 Posts

    Re: Setting Attribute Default Value

    ‏2013-06-05T14:00:20Z  
    • Johnny_P
    • ‏2013-06-05T08:33:20Z

    Hi,

    that depends on how many attributes you want to reset. If there are just a few attributes, the quickest way would be via the object properties window. In the Attributes tab you can select an attribute, assign a value and apply to "Objects in current view" or "Selected objects".

     

    Some time ago I wrote a little script to reset attribute values for selected attributes.

    1. Make sure, that you have no filter applied if you want to reset the attribute for ALL objects (The script asks you if you want to apply the default values only for values in the current view if you have a filter applied)
    2. Select the attributes you want to reset
    3. Click "Reset values" and "Continue" if you are sure, that you have selected the correct attributes.

    So if you have a lot of attributes you can try it:

    Module m = current
    AttrDef ad = null
    string sDummy[] = {}
    DB dbAttr = null
    DBE dbeListViewAttributes = null
    DBE dbeButtonSelectAll = null
    DBE dbeButtonDeselectAll = null
    int iIndex = 0

    // select all checkboxes
    void selectAll(DBE dbe)
    {
        int i = null
        int iNoElems = noElems(dbeListViewAttributes)
        
        for (i=0; i<iNoElems; i++)
        {
            setCheck(dbeListViewAttributes, i, true)
        }
    }

    // deselect all checkboxes
    void deselectAll(DBE dbe)
    {
        int i = null
        int iNoElems = noElems(dbeListViewAttributes)
        
        for (i=0; i<iNoElems; i++)
        {
            setCheck(dbeListViewAttributes, i, false)
        }
    }

    // reset selected attribute values
    void resetValues(DB db)
    {
        int i = null
        int iNoElems = noElems(dbeListViewAttributes)
        int iAttrCounter = 0
        Object o = null
        string sCurAttribute = null
        Skip skpAttributesToReset = createString()
        bool bCancel = false
        
        for (i=0; i<iNoElems; i++)
        {
            if (getCheck(dbeListViewAttributes, i))
            {
                sCurAttribute = getColumnValue(dbeListViewAttributes, i, 0)
                put(skpAttributesToReset, sCurAttribute, sCurAttribute)
                iAttrCounter++
            }
        }

        string sChoices[] = { "Continue", "Cancel" }
        int iContinue = query("You are about to reset the values for all selected attributes (" iAttrCounter "):\n\nDo you want to continue?", sChoices)
        
        // continue
        if (iContinue == 0)
        {
            // check if a filter is applied
            if (filtering(m))
            {    
                string sChoicesFilter[] = { "Continue with applied filter", "Disable filter and continue", "Cancel" }
                int iMode = query("There is a filter applied.\nDo you want to continue and reset only attribute values for objects in the current view or do you want to disable the filter?", sChoicesFilter)
                
                if (iMode == 0) {} // continue
                elseif (iMode == 1)
                {
                    filtering off
                }
                elseif (iMode == 2)
                {
                    bCancel = true
                }
            }
            
            if (!bCancel)
            {
                // loop through all objects in the view and reset all selected attribute values
                for o in m do
                {
                    for sCurAttribute in skpAttributesToReset do
                    {
                        o.sCurAttribute = ""
                    }
                }
            }
        }
        elseif (iContinue == 1)
        {
            bCancel = true
        }
        
        
        refresh m
        delete skpAttributesToReset
        
        if (!bCancel)
        {
            destroy db
            infoBox "done"
        }
    }

    dbAttr = create("Reset attribute values", styleCentered)
    dbeListViewAttributes = listView(dbAttr, listViewOptionCheckboxes, 300, 10, sDummy)
    dbeButtonSelectAll = button(dbAttr, "Select all", selectAll)
    beside dbAttr
    dbeButtonDeselectAll = button(dbAttr, "Deselect all", deselectAll)
    apply(dbAttr, "Reset values", resetValues)

    realize dbAttr
    insertColumn(dbeListViewAttributes, 0, "Attributes", 250, iconNone)
    setExtraHeightShare(dbeListViewAttributes, 1.0)

    // list all available attributes in the listview
    for ad in m do
    {
        if (!ad.object || ad.system) { continue } // skip module only attributes and systems attributes
        insert(dbeListViewAttributes, iIndex++, ad.name)
    }

    show dbAttr

    Regards Johnny

     

    Hello Johnny,

    on an unrelated side note: how did you manage to write this code block?

    Is there a tag like the old "{ code }"?

     

    BR
    Mike

    Updated on 2013-06-05T14:00:33Z at 2013-06-05T14:00:33Z by Mike.Scharnow
  • llandale
    llandale
    3035 Posts

    Re: Setting Attribute Default Value

    ‏2013-06-05T17:14:15Z  

    If you set an obj-attr-value to null it will appear to have the default value.

    • for o in entire m do {o."MyCustomAttr" = ""}

    -Louie

  • Skaifey05
    Skaifey05
    2 Posts

    Re: Setting Attribute Default Value

    ‏2013-06-05T22:06:13Z  

    Hi Johnny an Louie,

    Thanks for the responses, both are very helpful. Once I actually get started I will see which option works the best. It may be that I end up using the option that works best on the particular module.

    Cheers

    Mark

  • Pekka_Makinen
    Pekka_Makinen
    26 Posts

    Re: Setting Attribute Default Value

    ‏2013-06-06T04:31:00Z  

    Hello Johnny,

    on an unrelated side note: how did you manage to write this code block?

    Is there a tag like the old "{ code }"?

     

    BR
    Mike

    The grey area is a blockquote - you can select it from the editor window by using the button with large "-character.

    Seems to do the work for displaying DXL code examples.