Version 1.5, 5 August 2014
Excellon File Handler
This plugin adds Excellon file support to CamBam's file opening options.
As an Excellon importer, it is relatively simplistic, looking for a handful of regular expressions to determine drill size and hole locations.
The main aim of this plugin is to provide an example of writing a custom file handler using the CamBam API.
See Also
There is also another Excellon plugin available, kindly provided by bigbigblue on the on the CamBam user forum...
Excellon (NC Drill) Import plugin
Excellon programming specification
Download
Plugin
ExcellonIO-1.5.zip (7 KB)
Source
ExcellonIO-1.5-source.zip (8 KB)
Installation
To install the plugin, unzip ExcellonIO.dll into the CamBam plugins folder.
If the installation is successful, you should see a new entry in the File - Open file types 'Excellon File (*.drl)', and new menu item 'ExcellonIO Config' under the plugins menu.
Source
This shows a summary of the relevent code required to impliment a file handler plugin. Please see the full source code for details.
ExcellonIOPlugin.cs
...
public class ExcellonIOPlugin
{
public static void InitPlugin(CamBamUI ui)
{
CamBamUI.CADFileHandlers.Add(new ExcellonIOHandler());
ThisApplication.TopWindow.FormClosing += new System.Windows.Forms.FormClosingEventHandler(TopWindow_FormClosing);
ToolStripMenuItem miConfig = new ToolStripMenuItem("ExcellonIO Config");
miConfig.Click += new EventHandler(ExcellonIOConfig_Click);
ui.Menus.mnuPlugins.DropDownItems.Add(miConfig);
}
...
}
...
ExcellonIOHandler.cs
...
public class ExcellonIOHandler : CADFileIO
{
...
public override string FileFilter
{
get
{
return "Excellon File (*.drl)|*.drl";
}
}
public override bool ReadFile(string path)
{
_Initialize();
using (StreamReader sr = new StreamReader(path))
{
long line_num = 0;
ChangeTool(0);
for (; ; )
{
line_num++;
string s = sr.ReadLine();
if (s == null) break;
s = s.Trim();
if (s.Length == 0) continue;
if (s == "%")
{
InHeader = false;
continue;
}
foreach( _ExcellonPattern pattern in _Patterns )
{
if (pattern.Process(this, s)) break;
}
}
ThisApplication.AddLogMessage("{0} lines read from {1}", line_num, path);
}
return true;
}
public override bool AddToDocument(CADFile doc)
{
doc.DrawingUnits = DrawingInits;
doc.Add(_Points);
if (ExcellonIOConfig.Defaults.CreateMOP)
{
// Make sure there is an active part in the drawing...
doc.EnsureActivePart(false);
for (int i = 0; i < _Points.Count; i++)
{
PointList plist = (PointList)_Points[i];
MOPDrill drill = new MOPDrill();
drill.PrimitiveIds = new int[] { plist.ID };
drill.Name = drill.GetSafeName(doc.ActivePart);
int tool_num = _HoleSizes[i];
double tool_diameter = 0;
if (Tools.ContainsKey(tool_num))
{
tool_diameter = Tools[tool_num];
}
drill.ToolNumber = new CBValue(tool_num);
if (ExcellonIOConfig.Defaults.SetToolDiameter)
drill.ToolDiameter = new CBValue(tool_diameter);
drill.TargetDepth = new CBValue(ExcellonIOConfig.Defaults.TargetDepth);
if (ExcellonIOConfig.Defaults.SetToolProfile)
drill.ToolProfile = new CBValue(ExcellonIOConfig.Defaults.ToolProfile);
if (ExcellonIOConfig.Defaults.SetHoleDiameter)
drill.HoleDiameter = new CBValue(tool_diameter);
doc.ActivePart.MachineOps.Add(drill);
}
}
return true;
}
...
}
...
History
Version 1.5
- Config file now working for Linux / Mono.
- Added support for M71 / M72.
- Fixed coordinates with decimal points bug.
- Fixed trailing zero bug when coordinates more than 6 characters.
Version 1.4
ExcellonIO-1.4.zip (6 KB)
- Fixed leading zero padding bug.
Version 1.3
ExcellonIO-1.3.zip (6 KB)
- Fixed a bug relating to negative (no decimal) coordinates causing errors.
- Handle modal X or Y coordinates.
- Prevent error when undeclared tool selected.
- Added XScaleMetric and YScaleMetric config options to control default metric scaling.
- Added SetToolDiameter, SetHoleDiameter, SetToolProfile and ToolProfile config options.
Version 1.2
ExcellonIO-1.2.zip (6 KB)
- Fixed a bug relating to negative coordinates causing errors.
Version 1.0
ExcellonIO-1.0.zip (6 KB)