Topic
3 replies Latest Post - ‏2013-03-20T15:45:08Z by SystemAdmin
TerryMoriarty
TerryMoriarty
126 Posts
ACCEPTED ANSWER

Pinned topic Rename Attributes in VBA

‏2013-03-18T18:30:18Z |
I want to rename attributes in VBA. I found a macro here and used it to rename entities. Worked just fine. But doesn't work for attributes because it opens the definition edit window and you can't open an attribute's edit window directly. So, I get the message about having to open it's entity and everything stops working. Just goes on to the next attribute to be renamed without doing anything.

The relevant code that I copied is:
For Each clsDDID In clnDDIDs
With clsDDID
strName = Replace(.Name, " ", "_")
Call imfSA.SAEditDefinition(.ddId, 0) ' 0 = Open as Read/Write
Call imfSA.SARenameDefinition(.ddId, strName) ' Update and Close
Call clsDDID.Save
End With
Next

I tried the following to replace the SAEditDefinition statement, but got a "method or data member not found" compile error on the Call CurDef.ReadAll statement.

Dim CurDef As SA2001.Definition

For Each clsDDID In clnDDIDs
With clsDDID
strName = Replace(.Name, " ", "_")

' want to avoid using this stmt Call imfSA.SAEditDefinition(.ddId, 0) ' 0 = Open as Read/Write

Set CurDef = appSA.Encyclopedia.GetDefinitionById(clsDDID.ddId)
Call CurDef.ReadAll
Call imfSA.SARenameDefinition(.ddId, strName) ' Update and Close
Call CurDef.Save
End With
Next

I'm hoping that I'm missing something very obvious, but right now, I can't see it.

Thanks,
Terry
Updated on 2013-03-20T15:45:08Z at 2013-03-20T15:45:08Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1061 Posts
    ACCEPTED ANSWER

    Re: Rename Attributes in VBA

    ‏2013-03-18T18:36:04Z  in response to TerryMoriarty
    Terry,

    Using the 'getdefinitionbyid' method, you already have the definition object set, so you don't need to do a 'readall'. This is not a method that is valid for the sa2001.definition class. This method is available for the 'saobject' class.
  • TerryMoriarty
    TerryMoriarty
    126 Posts
    ACCEPTED ANSWER

    Re: Rename Attributes in VBA

    ‏2013-03-18T23:04:35Z  in response to TerryMoriarty
    It appears that the renamedefinition method only works on when the definition's edit window is open. Works just fine for entities. But not for attributes. As I stated in my first message, it gives the error message about attributes needing to be editted through their entity and then opens the entity edit window. Then goes on to the next attribute. Never changes the name.

    Any ideas on how to get around this process is greatly appreciated.
    • SystemAdmin
      SystemAdmin
      1061 Posts
      ACCEPTED ANSWER

      Re: Rename Attributes in VBA

      ‏2013-03-20T15:45:08Z  in response to TerryMoriarty
      Hi Terry,

      Where you talking about a DoDaf(?) Entity (SAType 15)?
      With the script below I was able to rename the definition.

      Hope this helps,

      Remco

      
      Sub Test() Dim saimf As ISAImf Dim def As Definition Dim coll As OfCollection Dim ddid As Long, x Set saimf = Application.Interface(
      "ISAImf") Set def = Application.Encyclopedia.GetDefinitionById(2956) 
      ' Specific to my Encyclopedia Set coll = def.GetPropertyAsCollection(
      "Description") 
      ' Its a renamed property ddid = coll.Item(1).ddid 
      ' Clear the references and close the definition/attributes Set coll = Nothing Set def = Nothing x = saimf.SARemoteRenameDefinition(ddid, 
      "Testing")   Set saimf = Nothing End Sub