[Solved] Enumerate enumeration names

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
pitonyak
Volunteer
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

[Solved] Enumerate enumeration names

Post by pitonyak »

Given the name of an enumeration (or constant group, or similar), how can I enumerate the names? Consider the following (horrible) code:

Code: Select all

Sub TestEnumerations_001
  Dim oTDM
  Dim oTDME
  Dim oTD
  Dim typeArray

  Set oTDM = GetDefaultContext().getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager") 
  
  typeArray = Array(com.sun.star.uno.TypeClass.ENUM, _
     com.sun.star.uno.TypeClass.SEQUENCE, _
     com.sun.star.uno.TypeClass.CONSTANT, _
     com.sun.star.uno.TypeClass.CONSTANTS)
  
  Dim sFullName$
  Dim sBaseName$
  sFullName = "com.sun.star.presentation.AnimationEffect"
  sBaseName = "com.sun.star.presentation"
  
  oTDME = oTDM.createTypeDescriptionEnumeration(sBaseName, typeArray, com.sun.star.reflection.TypeDescriptionSearchDepth.ONE)
  
  While oTDME.hasMoreElements()
    oTD = oTDME.nextTypeDescription()
    If oTD.Name = sFullName Then
      MsgBox Join( oTD.getEnumNames(), CHR$(10))
    End If
  wend
End Sub
Sure, it works, but really, do I need to enumerate all of the values to find AnimationEffect.... Oh, you know what, just bothering to ask the question made the solution obvious to me...

Code: Select all

If oTDM.hasByHierarchicalName(sFullName) Then 
    oTDM.getByHierarchicalName(sFullName) 
  End If 
Guess if I wondered, someone else may wonder as well, so post the solution.
Last edited by MrProgrammer on Mon Apr 10, 2023 6:00 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
Post Reply