Note: There is a newer version of the scripting documentation.
Go to the latest scripting documentation.

Appendix A: Scripting Felix

Most of the application's features can be scripted using Visual Basic (VB), Visual Basic for Applications (VBA), and other COM-aware languages (including C++). This makes Felix a flexible and powerful tool. You can build your own custom scripts to automatically perform various tasks, pre-process documents, and more.

In fact, the various interfaces for Microsoft Word, PowerPoint, and Excel that come with this application, as well as the Tag Assist translator's HTML editor, take advantage of this very feature to perform their magic. You can customize these scripts to your own purposes, or write new ones. You can also write VB or other applications that take advantage of these features.

Automation Function Specification

Properties

Name Type Read Write Description
Visible Boolean YES YES Show/hide the Memory window, and detect whether it is visible.
NumGlossMatches Integer YES NO Get the number of matches in the Main glossary.
NumMatches Long YES NO Get the number of matches in the memory.
Query String YES YES Get or set the current query. Setting the query causes the Memory window to search for matches in the current memory, and the Glossary windows to look for matches in their glossaries.
Score Double YES NO Get the score of the currently displayed match.
Trans String YES YES Get or set the translation for the current query. Setting the translation creates a new memory entry, with the query as the source and the translation as the translation.
App2 Object YES NO Retrieve the App2 interface, with several advanced features. See The App2 Interface for details.

Top | Contents

Methods

Method Name Parameters Return Value Action
AddGlossaryEntry String Source,
String Translation,
String Context
None Add an entry to the glossary. The source is the current query in the Memory window.
AddMemoryEntry String Source,
String Translation,
String Context
None Add an entry to the memory.
ClearGlossaries None None Clear the Main Glossary window memory.
ClearMemories None None Clear the Memory window memory.
Concordance String Query None Search the memory for concordances.
DeleteMemEntry None None Delete the currently displayed translation.
GlossMatch Integer Index String Get the glossary entry at position Index from the Main glossary.
NextTrans None None Show the next translation match.
PrevTrans None None Show the previous translation match.
Quit None None Quit Felix.
Save None None Save the memory and Main glossary.
TransConcordance String Query None Get translation concordance for Query.

Top | Contents

The App2 Interface

The App2 object provides advanced features.

CurrentMatch
The CurrentMatch property retrieves the current match for the lookup term. See the Match Objects specification for details.
CurrentMatches
A collection of Match objects representing the current matches in Felix.
CurrentGlossMatches
A collection of Match objects representing the current glossary matches in Felix.
ReflectChanges(ULONG Id, String Source, String Trans)
Correct the source and translation of the record with id Id
ReviewTranslation(ULONG Id, String Source, String Trans)
Review the translation unit (TU) with id Id, correcting the source and translation as supplied if necessary.

Top | Contents

Match Object

This represents a TM or glossary match in Felix. It has the following members.

Record
The TM/glossary record for this match. See the Record Objects specification for details.
Score
The match score (0.0 to 1.0).
MemoryName
The name of the memory/glossary that this match's record belongs to.

Top | Contents

Record Objects

This represents a Felix TM or glossary record. It has the following members.

Source
The source segment.
Trans
The translation segment.
Context
The record context string.
PlainSource
The source segment without any HTML markup.
PlainTrans
The translation segment without any HTML markup.
CreatedBy
The name of the user who created this record.
ModifiedBy
The name of the last user to modify this record.
DateCreated
The date this record was created.
LastModified
The date this record was last modified.
RefCount
The number of times this record has been retrieved as a match.
Id
The ID value of this record.

Top | Contents

Sample Code

VBA/Visual Basic

Add some memory and glossary entries

' Create the Felix object
Dim felix As Object
Set felix = CreateObject("Felix.App")

' Make it visible
felix.Visible = True

' source, translation, context
felix.AddMemoryEntry "white", "blanco", "from VBA"
felix.AddMemoryEntry "black", "negro", "from VBA"

felix.AddGlossaryEntry "uno", "one", "VBA gloss entry"
felix.AddGlossaryEntry "dos", "two", "VBA gloss entry"
felix.AddGlossaryEntry "tres", "three", "VBA gloss entry"

Clear the glossary and memory

' You could also add the type library to the
' references and declare:
' Dim felix As New FelixLib.App
Dim felix As Object
Set felix = CreateObject("Felix.App")
felix.Visible = True
felix.ClearGlossaries
felix.ClearMemories

Set a translation entry

Dim felix As Object
Set felix = CreateObject("Felix.App")
felix.Visible = True
felix.Query = "Can I automate my TM tool?"
felix.Trans = "Yes, if it's Felix!"

Replace all glossary matches in a Word document with their translations

Sub SubstituteGlossMatches()
' Replace all the Felix glossary matches in the document
' with their translations

    ' Create the Felix object
    Set felix = CreateObject("Felix.App")

    ' Get the find object...
    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Wrap = wdFindStop

        ' Go through each paragraph
        For Each para In ActiveDocument.Paragraphs

            ' Look up its text
            para.Range.Select
            felix.Query = para.Range.Text

            ' Loop through each of the glossary matches
            For Each match In felix.app2.CurrentGlossMatches

                ' Set the source and replacement text
                ' Use the "Plain" variants to get the text without HTML tags
                .Text = match.record.PlainSource
                .Replacement.Text = match.record.PlainTrans

                ' Do the replacement
                .Execute Replace:=wdReplaceAll
            Next match
        Next para

    End With

End Sub

C++

Set the query and translation

#include <string> // for wstring

// put this in your path or use the absolute path
#import "Felix.tlb" no_auto_exclude

// Note: obviously, these functions could live in a C++ object,
// which would eliminate the need to call
// CoCreateInstance every time.
// This is the approach that TagAssist uses. However, the sample
// has been condensed into two functions for brevity.

// set the current query
inline void set_query(  const std::wstring &query )
{
	CComPtr< FelixLib::IApp > felix ;
	// error handling omitted for brevity
	felix.CoCreateInstance( L"Felix.App",
		NULL,
		CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER ) ;

	// make it visible
	felix->Visible = VARIANT_TRUE ;

	// put the query
	// Felix will respond by showing a
	// list of any matches
	CComBSTR bQuery( query.c_str() );
	felix->Query = bQuery ;
}

// set the translation for the current query
inline void set_trans( const std::wstring  &trans )
{
	CComPtr<  FelixLib::IApp > felix ;
	// error handling omitted for brevity
	felix.CoCreateInstance( L"Felix.App",
		NULL,
		CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER ) ;

	// make it visible
	felix->Visible = VARIANT_TRUE ;

	// put the translation
	// If there is a current query, this will
	// create a new entry, with the query as the
	// source and the trans as the translation.
	CComBSTR bTrans( trans.c_str() ) ;
	felix->Trans = bTrans ;
}

Top | Back (FAQ)