• In SGML files graphics are declared. Once they are declared they can be referenced in elements such as <graphic> or whatever your DTD declares. Often during the development of the files, some graphic declarations are created but never used. It is a good practice to remove graphic declarations that are not required.

    I came across this ACL file from Karl Johan Kleist (original code by Rune Kallhovd) on Adepters website, listed below.

    I named that code below as removeUnusedGraphics.acl and placed it in <arbortext home>/custom/scripts folder. I tied it to a menu on init ACL file (<arbortext home>/custom/editinit) that runs when a document is opened. It has these items added in the menu. First, the file is sourced. second, call the function, clean_unused_gfxents() when the menu item is selected.

    Remove Unused Graphic Menu Pick

    Remove Unused Graphic Menu Pick

    Items to add to the Menu*

    source removeUnusedGraphics.acl
    menu_add ".TechData." "Remove all unused graphic entities" -cmd { clean_unused_gfxents() }

    Code File

    # Rune Kallhovd and Karl Johan Kleist
    # Posted 2006-06-18 to adepters.org

    function clean_unused_gfxents(doc,op) {

        local entArr[], gfxArr[];
        local entArrlen = 0;
        local gfxCnt = 1;

        if (op != 2) {
            return 0;
        }

    # Building an Array of declared entities:

        entArrlen = graphic_entity_names(entArr, doc);

    # Building an Array of used entities:

        for (o = oid_first(doc); oid_valid(o); o = oid_forward(o)) {

            # Do we have a Graphic tag?

            if (graphic_tag(oid_name(o))) {

                # Get the attribute name holding the ENTITY

                local gfxentnam = graphic_entity_attr_name(oid_name(o));

                if (gfxentnam != "") {
                    gfxArr[gfxCnt] = oid_attr(o, gfxentnam);
                    gfxCnt++;
                }
            }
        }

    # Iterate over declared entities, and delete unused ones:

        for (i = 1; i <= entArrlen; i++) {

            local found = 0;

            ent = entArr[i];

            for (gfx in gfxArr) {
                if (gfxArr[gfx] == ent) {
                    found = 1;
                }
            }

            if (!found) {
                undeclare_entity $ent;  # NOTE: dollar sign needed here / kjk
            }
        }
    }

    # Add the following to e.g. a init() function:
    doc_add_callback(0, ‘save’, ‘cor_utils::clean_unused_gfxents’, ‘PREPEND’);

    * Menu article coming soon…

    This entry was posted on Thursday, November 5th, 2009 at 4:35 pm and is filed under ACL, Structured Authoring. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 0 Comments

    Take a look at some of the responses we have had to this article.

  • Leave a Reply

    Let us know what you thought.

  • Name(required):

    Email(required):

    Website:

    Message: