TextWrangler LDraw Kit
What is this?
The TextWrangler LDraw Kit is a collection of scripts and other bits and pieces that extend TextWrangler with some additional capabilities for working with LDraw files. Specifically, it provides a shortcut for opening part files referenced by the current file.
TextWrangler has an “Open Selection” command typically used to open header files associated with the current source code file. When an LDraw file is open, this kit overloads that command to locate and open the selected part. It can also be invoked directly to open all the parts referenced in a larger selection.
This kit also provides a compatibility script that properly exposes the LSynth Service’s functionality to TextWrangler. The current file or selection can be processed in place with LSynth.
This kit is inspired by LDraw DesignPad, an excellent LDraw text editor for Windows.
With minor modifications, this kit should also be compatible with TextWrangler’s big brother, BBEdit.
Download
The TextWrangler LDraw Kit is currently comprised of four separate files:
- ldraw.plist.zip (1k) Placeholder language module
- ldlocate.tcl.zip (4k) Part finder reports path to named parts
- glue.scpt.zip (6k) AppleScript connects TextWrangler interface to part finder
- LSynth.tcl.zip (1k) Wrapper for LSynth Service Tool
Installation
At present it remains necessary to install the TextWrangler LDraw Kit components manually. Here’s how:
The ldraw.plist
file goes in ~/Library/Application Support/TextWrangler/Language Modules/
. This identifies dat
, ldr
, and mpd
files as LDraw files and lists MPD submodels in the function popup menu (this requires TextWrangler 2.2). You may need to remove a conflicting suffix in order for dat
files to be recognized properly.
Unzip the AppleScript and put it in ~/Library/Application Support/TextWrangler/Menu Scripts/
. Rename it File•Open Selection.scpt
(type the bullet character by pressing Option-8). Notice how the name is used to associate the script with the menu item it may override.
The “Open Selection” menu command is not available when multiple lines are selected, but this kit can open parts referenced within a multiline selection. To use it this way, make an alias (or copy) of the AppleScript in ~/Library/Application Support/TextWrangler/Scripts/
and give it an appropriate name, such as Open Extended Selection.scpt
.
By default the AppleScript assumes ldlocate.tcl
has been installed as /usr/local/bin/ldlocate
; however, you may wish to place it elsewhere. If you do, open the AppleScript and change the ldlocate
path accordingly.
You’ll need to make ldlocate
executable: chmod +x /usr/local/bin/ldlocate
Put LSynth.tcl
in ~/Library/Application Support/TextWrangler/Unix Support/Unix Filters/
. It does not strictly need to be made executable. Apply LSynth to the current file or selection by selecting LSynth.tcl
from the Unix Filters submenu of the #!
menu. The LSynth Service or lsynthst
must also be installed.
ldlocate
Here is the usage message for ldlocate
:
Usage: ldlocate [options] Locate LDraw part files. [-/+grep FILENAME] Search FILENAME and its parent directory. [-/+path DIRECTORY] Search DIRECTORY as a normal directory. [-/+ldraw DIRECTORY] Search DIRECTORY as an LDraw root directory. [-part FILENAME] Search for FILENAME (with or without suffix). [-stdin] Search for parts referenced in standard input. [-noenv] Do not search $LDRAWDIR environment variable. The grep, path, and ldraw arguments specify where to look for parts in addition to the standard $LDRAWDIR location (or instead of $LDRAWDIR if -noenv is given). Files are searched before directories; otherwise, locations are searched in the order they are given. Locations given with a "-" prefix are searched before $LDRAWDIR and those with a "+" prefix are searched after $LDRAWDIR. The path to the first match is printed. Specific parts to search for are given with -part. If -stdin is given, parts references (or a single part) are read from standard input. Input lines that are not part references are ignored.