Tuesday, February 3, 2009

Replacing a string in vim to fix an dxf file

I have an DXF file that has entries that look like this:

LCD.1
70
64
62
150
6
CONTINUOUS
0
LAYER
2
LCDMOUNT.1
70
64
62
252
6


Autocad doesn't like this file... I have no idea what created it. After much screwing around I've discovered that it doesn't like the "."s in the entity (or whatever they're called) names. Load the file in vim and use the following regexp to get rid of the dots.

%s/\([A-Z]\)\.\([0-9]\+\)/\1\2/g


Fixed file looks like this:

LCD1
70
64
62
150
6
CONTINUOUS
0
LAYER
2
LCDMOUNT1
70
64
62
252
6


FYI, the \( \) are delimiters in the search sequence. \1 and \2 reference back to these.

Addition: The file in question was produced by a program called "Camera 3D" or "3D Camera" or something... Just in case anyone else has the same problem with this code.

No comments: