CanDelete and attribute types

Hello,

I am trying to create a script that would allow me to create a skip list so that I may delete all old attributes that are nolonder needed and I would also like to removing all unused dataypes - (this where I am running into the issue how would I go about removing all unused datatype I keep getting a syntax error with the "canDelete" function what am I doing wrong? Thank you.

-Jim
 

Module m = current
mod = edit(fullName(m), false, true, true)    // Edit, invisible, silent, standard view
 
void  DeleteAttributes(Module mod, Skip skpAttrNames)
{
        string  NameAttr, NameMod = name(mod)
        
        for NameAttr in skpAttrNames do
        {  AttrDef ad = find(mod, NameAttr)
           print NameMod "\t" NameAttr "\t"
           if (null ad) { print "No such attr\n" }
           else
           {  
              ErrMess = delete(mod, ad)
              if (!null ErrMess) { "AttName Error Deleting: " ErrMess }
              else { print "Deleted OK\n" }
                  
                  AttrType CurrType = find(m, ad.typeName)
                  if canDelete(CurrType) 
                  { 
                        delete(CurrType, ErrMess) 
                        if (!null ErrMess) { "AttType Error Deleting: " ErrMess }
                        else { print "Deleted OK\n" } 
                  }
           }
        }    // end for attrs to delete
}    // end DeleteAttributes(mod)
 
// ========= MAIN =========
Skip skpAttrNames = createString   // KEY and DATA both 'string' Name of attr to delete
put(skpAttrNames, "Object Type", "Object Type")
 
DeleteAttributes(mod, skpAttrNames)
delete(skpAttrNames)

SystemAdmin - Tue Dec 13 12:45:42 EST 2011

Re: CanDelete and attribute types
OurGuest - Tue Dec 13 12:59:15 EST 2011

You might want to change: if canDelete(CurrType)

to: if (canDelete(CurrType) )

Re: CanDelete and attribute types
SystemAdmin - Tue Dec 13 13:18:27 EST 2011

OurGuest - Tue Dec 13 12:59:15 EST 2011
You might want to change: if canDelete(CurrType)

to: if (canDelete(CurrType) )

Hello,

I want to delete all unused datatypes how would you go about doing that? I thought the canDelete would protect against attempting to delete a dataype that is in use. But from what I can tell it doesn't. Any ideas?
 

if (canDelete(CurrType))
{ 
 delete(CurrType, ErrMess) 
 if (!null ErrMess) { "AttType Error Deleting: " ErrMess }
 else { print "Deleted OK\n" } 
}

Re: CanDelete and attribute types
llandale - Tue Dec 13 14:18:10 EST 2011

SystemAdmin - Tue Dec 13 13:18:27 EST 2011

Hello,

I want to delete all unused datatypes how would you go about doing that? I thought the canDelete would protect against attempting to delete a dataype that is in use. But from what I can tell it doesn't. Any ideas?
 

if (canDelete(CurrType))
{ 
 delete(CurrType, ErrMess) 
 if (!null ErrMess) { "AttType Error Deleting: " ErrMess }
 else { print "Deleted OK\n" } 
}

  • There is a "bool isUsed(AttrType)" function which seems to work.
  • In your original code I think you should get your CurrType handle before you delete the "ad" it needs.
  • Not sure, but I think you need a "flushDeletions()" command in there somewhere.
  • guess you fixed the "if" issue, but I wonder why it worked.

-Louie

Re: CanDelete and attribute types
SystemAdmin - Tue Dec 13 18:18:28 EST 2011

llandale - Tue Dec 13 14:18:10 EST 2011

  • There is a "bool isUsed(AttrType)" function which seems to work.
  • In your original code I think you should get your CurrType handle before you delete the "ad" it needs.
  • Not sure, but I think you need a "flushDeletions()" command in there somewhere.
  • guess you fixed the "if" issue, but I wonder why it worked.

-Louie

Hello,

Is there a way of checking to see if a datatype is define by the system before attempting to delete it; if not what would be the best why of error checking? Thank you.

-Jim
 

Module m = current
mod = edit(fullName(m), false, true, true)    // Edit, invisible, silent, standard view
 
void  DeleteAttributes(Module mod, Skip skpAttrNames)
{
        string  NameAttr, err
        print name(mod)
        for NameAttr in skpAttrNames do
        {  
           AttrDef ad = find(mod, NameAttr) //find Attribute from Skip list
           print "\nAttrDef: (" NameAttr ")"
           if (null ad) 
           { 
              print "\tNo such attr" 
           }
           else
           {  
              AttrType CurrType = find(m, ad.typeName)
                  string adType = ad.typeName
              err = delete(mod, ad) //find data type from valid attribute
                  if (err !="") { ack err; print "\t" err " [System Attr("ad.system")]"}
              else { print "\tDeleted OK" }
                  
                  if (!isUsed(CurrType))
                  { 
                    print "\nAttrType: (" adType
                        delete(CurrType, err) 
                        if (err !="") { ack err; ")\tError Deleting: " err ""; }
                        else { print ")\tDeleted OK" } 
                  }
           }
        }    // end for attrs to delete
        flushDeletions()
}    // end DeleteAttributes(mod)
 
// ========= MAIN =========
Skip skpAttrNames = createString   // KEY and DATA both 'string' Name of attr to delete
put(skpAttrNames, "Object Type", "Object Type")
put(skpAttrNames, "jim", "jim")
put(skpAttrNames, "Object", "Object")
put(skpAttrNames, "Object Text", "Object Text")
put(skpAttrNames, "kim", "kim")
put(skpAttrNames, "ll", "ll")
 
DeleteAttributes(mod, skpAttrNames)
delete(skpAttrNames)

Re: CanDelete and attribute types
llandale - Fri Dec 16 12:10:14 EST 2011

SystemAdmin - Tue Dec 13 18:18:28 EST 2011

Hello,

Is there a way of checking to see if a datatype is define by the system before attempting to delete it; if not what would be the best why of error checking? Thank you.

-Jim
 

Module m = current
mod = edit(fullName(m), false, true, true)    // Edit, invisible, silent, standard view
 
void  DeleteAttributes(Module mod, Skip skpAttrNames)
{
        string  NameAttr, err
        print name(mod)
        for NameAttr in skpAttrNames do
        {  
           AttrDef ad = find(mod, NameAttr) //find Attribute from Skip list
           print "\nAttrDef: (" NameAttr ")"
           if (null ad) 
           { 
              print "\tNo such attr" 
           }
           else
           {  
              AttrType CurrType = find(m, ad.typeName)
                  string adType = ad.typeName
              err = delete(mod, ad) //find data type from valid attribute
                  if (err !="") { ack err; print "\t" err " [System Attr("ad.system")]"}
              else { print "\tDeleted OK" }
                  
                  if (!isUsed(CurrType))
                  { 
                    print "\nAttrType: (" adType
                        delete(CurrType, err) 
                        if (err !="") { ack err; ")\tError Deleting: " err ""; }
                        else { print ")\tDeleted OK" } 
                  }
           }
        }    // end for attrs to delete
        flushDeletions()
}    // end DeleteAttributes(mod)
 
// ========= MAIN =========
Skip skpAttrNames = createString   // KEY and DATA both 'string' Name of attr to delete
put(skpAttrNames, "Object Type", "Object Type")
put(skpAttrNames, "jim", "jim")
put(skpAttrNames, "Object", "Object")
put(skpAttrNames, "Object Text", "Object Text")
put(skpAttrNames, "kim", "kim")
put(skpAttrNames, "ll", "ll")
 
DeleteAttributes(mod, skpAttrNames)
delete(skpAttrNames)

I see that system AttrType 'real' is not used by any system AttrDefs.

I see this in the manual:

  • canWrite -- Whether the user can delete the attribute type.

I'm pretty sure it means "Has permission to delete it", the "D" in RMCDA.

So maybe this answers your question:

if (CurrType.canWrite     and    // Allowed: I have permission -
    !(CurrType.system)    and    // Allowed: Its not a system type -
    !isUsed(CurrType)     and    // Allowed: No AttrDef is using it -
    canDelete(CurrType))         // Access right now: Module open Edit    -
then I can expect no "delete(CurrType)" errors.


I trust that "canDelete(CurrType)" covers AttrTypes in Partitions.

 

 

  • Louie