Version 1.5, 5 August 2014 Excellon File Handler

COMMENTS

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

...
///
/// This class handles the plugin initialisation.
/// 
public class ExcellonIOPlugin
{
    /// 
    /// This is the plugin entry point and will be called once by CamBam during initialisation.
    /// This method should handle plugin initialisation and registering any menu handlers etc.
    /// 
    /// ui : The current CamBam user interface instace.
    ///
    public static void InitPlugin(CamBamUI ui)
    {
        // Register a new file handler
        // The file handler class defines a property containing the file filter and extension
        CamBamUI.CADFileHandlers.Add(new ExcellonIOHandler());

        // Detect when CamBam is closing
        ThisApplication.TopWindow.FormClosing += new System.Windows.Forms.FormClosingEventHandler(TopWindow_FormClosing);

        // Add a menu to the top Plugins menu to edit this plugins configuration
        ToolStripMenuItem miConfig = new ToolStripMenuItem("ExcellonIO Config");
        miConfig.Click += new EventHandler(ExcellonIOConfig_Click);
        ui.Menus.mnuPlugins.DropDownItems.Add(miConfig);

    }
    ...
}
...

ExcellonIOHandler.cs

...
/// 
/// This is a file handler class for Excellon files
/// 
/// The class should handle the following overrides...
/// 
/// public string FileFilter {get;}
///     A property that returns the file open filter and file extensions that this class handles.
///     
/// public bool ReadFile(string path)
///     Method called by CamBam to read the source file
///     
/// public bool AddToDocument(CADFile doc)
///     If a file is read successfully, CamBam will call this method to add the file contents to a new drawing.
/// 
public class ExcellonIOHandler : CADFileIO
{
    ...

    /// 
    /// A property that returns the file open filter and file extensions that this class handles.
    /// 
    public override string FileFilter
    {
        get
        {
            return "Excellon File (*.drl)|*.drl";
        }
    }

    /// 
    /// Method called by CamBam to read the source file
    /// 
    /// path : The path and filename of the file to read
    /// returns True if the file was read successfully
    ///
    public override bool ReadFile(string path)
    {
        _Initialize();

        using (StreamReader sr = new StreamReader(path))
        {
            long line_num = 0;

            // makes sure there is a current point list...
            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;
                }

                // Find and process the first pattern that matches this string...
                foreach( _ExcellonPattern pattern in _Patterns )
                {
                    if (pattern.Process(this, s)) break;
                }
            }
            ThisApplication.AddLogMessage("{0} lines read from {1}", line_num, path);
        }

        return true;
    }

    /// 
    /// If a file is read successfully, CamBam will call this method to add the file contents to a new drawing.
    /// 
    /// doc : The CADFile to add the source file contents to
    /// Returns True if the document was updated successfully
    ///
    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)

  • Initial Release

Comments

<< 1 >> 
#  Paul 19/12/2013 14:01:20
Can you send me a sample Excellon file that Cambam can import please? I am trying to import a Metric one with 3.2 format (ie DDD.DD) and it is failing...

Thanks

Paul
Reply Quote   8  
#  steve 09/07/2014 19:53:56
nice! -- can you add .drd file extension for import as well?

using eagle --> cambam and eagle (excellon) exports .drd

(yes I can change this in eagle -- but I have several work flows and standard export would be awesome.)

I can change the extension manually to .drl and it works fine -- source suggests it would be simple to add -- but i have no compile tools

s
Reply Quote   9  

name: Rate this article

url:
e-mail:
Name, url and e-mail are optional. E-mail addresses will NOT be displayed, but please provide one if you would like a reply.
If your comment or url is not displayed immediately, it may be awaiting approval.
The following BBCode formatting codes are supported : [b], [i], [u], [code], [quote], [list], [*]
Your comments...


Submit Comment