KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method: Get Highest 4D Command ID
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: May 18, 2012

The Command name command will provide the name of any 4D command, given its ID. However the ID's are not easily obtainable. This method aides in the task of getting a list of all 4D command names by providing the highest-used ID.

The idea behind the method is to use the XLIFF file containing all 4D command ID's to find the highest ID.

Note: it is recommended to copy and paste this code into 4D as there are several long statements. Also this method only works with the US version of 4D.

// Get the highest 4D command ID.
C_LONGINT($0;$lastCommandID_l)

C_TIME($syntaxXLIFFFile_h)
C_TEXT($syntaxXLIFFFile_t)
C_TEXT($elementName_t;$elementPrefix_t;$commandID_t)
C_LONGINT($SAXEvent_l;$pos_l)

ARRAY TEXT($attributeNames_at;0)
ARRAY TEXT($attributeVals_at;0)

// There is an assumption here that this XLIFF file contains all 4D commands.
$syntaxXLIFFFile_t:=UTIL_PATH_LongNameToPath (Application file)\
  +"Resources"+Folder separator+"en.lproj"+Folder separator+"4DSyntaxEN.xlf"

$syntaxXLIFFFile_h:=Open document($syntaxXLIFFFile_t;Read Mode)

If (OK=1)

   Repeat
      $SAXEvent_l:=SAX Get XML node($syntaxXLIFFFile_h)

      Case of

         : ($SAXEvent_l=XML Start Element)
         SAX GET XML ELEMENT($syntaxXLIFFFile_h;$elementName_t;$elementPrefix_t;\
           $attributeNames_at;$attributeVals_at)

         Case of
            : ($elementName_t="trans-unit")
            $pos_l:=Find in array($attributeNames_at;"id")
            If ($pos_l>0)
               $commandID_t:=$attributeVals_at{$pos_l}
               If ($lastCommandID_l<Num($commandID_t))
                  $lastCommandID_l:=Num($commandID_t)
               End if
            End if
         End case
      End case

   Until ($SAXEvent_l=XML End Document)

   CLOSE DOCUMENT($syntaxXLIFFFile_h)
End if

$0:=$lastCommandID_l


The above method relies on this code (UTIL_PATH_LongNameToPath) to obtain the path to the XLIFF file:

// From: https://doc.4d.com/4Dv13/help/Title/en/page737.html
//
// Updated to use constant for path separator.
//
// Long name to path name ( String ) -> String
// Long name to path name ( Long file name ) -> Path name
C_STRING(255;$1;$0)
C_STRING(1;$vsDirSymbol)
C_INTEGER($viLen;$viPos;$viChar;$viDirSymbol)

$viDirSymbol:=Character code(Folder separator)
$viLen:=Length($1)
$viPos:=0
For ($viChar;$viLen;1;-1)
   If (Character code($1[[$viChar]])=$viDirSymbol)
      $viPos:=$viChar
      $viChar:=0
   End if
End for
If ($viPos>0)
   $0:=Substring($1;1;$viPos)
Else
   $0:=$1
End if