Import filter for Treepad light 3.0 files into OOo Writer

Creating Extension - Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This forum is not for asking questions about writing your own macros.

Import filter for Treepad light 3.0 files into OOo Writer

Postby pk72 » Sun Sep 13, 2009 12:16 pm

Hi, I changed from Treepad light 3.0 to OO writer as my outliner application. I had to write a document template and an import filter for the treepad files.
You can find the code for the BASIC-Filter below and the document template with the macro attached.

Converts Treepag Light 3.0 (.hjt) Files into OpenOffice Writer Files.
Preserves the tree structure by formatting the node headings with paragraph format "Heading 1".."Heading 9".
The document has Liberation Sans 12pt as default formatting and heading sizes ranging from 12pt-26pt.
This was written with OpenOffice 3.0. I do not know if it works with other OpenOffice versions.
Instruction for using the Document-Template and the script:
Open the "ConvertTreepad2Writer" document template.
Open Treepad .hjt-File in Writer with Insert/File. My Treepad file was created under Windows, so the import parameters were:
Character Encoding: Western Europe (Windows 1252)
Paragraph Break: CR & LF
The first node in the file with tree-level 0 must be removed manually before running the script.
Run the script with the “ConvertTreepad2Writer” Button in the “Macro” Toolbar. This will format Node headings according to the hierarchy in the Treepad tree. The Treepad database structure will be removed from the text.

This is the code for the filter:

Code: Select all   Expand viewCollapse view
Sub ConvertTreepad2Writer()
Dim Doc As Object
Dim Enum As Object
Dim ParagraphObject As Object
Dim ParagraphString As String
Dim HeadingObject As Object
Dim LevelObject As Object
Dim ParagraphTemplate As String

Doc = StarDesktop.CurrentComponent
Enum = Doc.Text.createEnumeration

' loop over all paragraphs
While Enum.hasMoreElements
   'Assign next paragraph to object variable
   ParagraphObject = Enum.nextElement
   ParagraphString = ParagraphObject.String
   'Remove Treepad structure
   If InStr(ParagraphString,"dT=Text") Then Doc.Text.removeTextContent(ParagraphObject)
   If InStr(ParagraphString,"<end node>") Then Doc.Text.removeTextContent(ParagraphObject)
   'If the current paragraph contains the string "<node>" then the following paragraph will be the node heading,
   'followed by level of tree-depth
   If InStr(ParagraphString,"<node>") Then
      'Assign Heading and tree-level to object variables
      HeadingObject = Enum.nextElement
      LevelObject = Enum.nextElement
      'Construct the paragraph template name. This will work only for tree-depths from 1..9
      ParagraphTemplate = "Heading " & Left(LevelObject.String,1)
      'Assign the paragraph template to the heading according to the tree-depth level
      HeadingObject.ParaStyleName = ParagraphTemplate
      'Remove <node> paragraph
      'Remove Paragraph with nodelevel
   End If
End Sub
Outliner document template with Treepad import filter
(9.85 KiB) Downloaded 317 times
OpenOffice 3.0.1
Ubuntu 9.04
Posts: 12
Joined: Sat Sep 12, 2009 1:01 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest