EAGLE - ULP for Exporting JLC PCB SMT BOM & POS

已注销

EAGLE ULP For JLC PCB SMT BOM & POS

Recently, I was using shenzhen JLC PCB Inc. online PCB manufacturing service. They provides swift and very convenient service. However, they have one little flaw: lack the SMT support for EAGLE which is my favorite PCB designing tool. I tried to import my board in KiCAD and followed their instructions but no luck. Finally, I had to write my own ULP to generate BOM and POS files from boards.

The ULP script is very simple. It does just one thing: iterating all elements -- here means all components -- and generate BOM file file and position file -- both are in CSV format. The CSV files will be located under the schematic/board directory.

NOTE
The position file can not be recognized by JLC SMT online purchase system. You should open it with Excel and save as .xlsx file.

Here goes the ULP code:

// JLCPCB SMT Association Utility
// Generate BOM and Position CSV files.
// Version: 0.1
// Author: igame
// E-mail: igame2000@hotmail.com
// Good luck!

string POS_HEADER = "Designator,Footprint,Mid X,Mid Y,Ref X, Ref Y,Pad X,Pad Y,Layer,Rotation,Comments\n";
string BOM_HEADER = "Comment,Description,Designator,Footprint,Libref,Pins,Quantity,No.\n";

string strrpl(string src, string tag, string dst) {
    string res = "";
    int src_len = strlen(src);
    int tag_len = strlen(tag);
    int idx = 0;

    if (!src_len || !tag_len || !strlen(dst)) return src;

    do {
        int pos = strstr(src, tag, idx);

        if (pos < 0) {
            if (idx == 0) {
                res = src;
            } else {
                res += strsub(src, idx);
            }
            
            break;
        }

        if (pos > idx) {
            res += strsub(src, idx, pos - idx);
        }
            
        res += dst;
        idx = pos + tag_len; 

        if (idx >= src_len) break;
    } while(1);

    return res;
}

string fmt_num(real x) {
    string str = "";

    sprintf(str, "%.3f", x);

    return str;
}

string get_layer(UL_FOOTPRINT fpt) {
    fpt.dimensions(D) {
       return D.layer ? "B" : "T";
    }

    return "T";
}

string format_bom_item(UL_ELEMENT E) {
    string res = 
        (strlen(E.value) > 0 ? E.value : E.name) + "," +   // Comment
        E.name + " " + E.footprint.name + "," +             // Description
        E.name + "," +                                      // Designator
        E.footprint.name + "," +                            // FootPrint
        E.footprint.library + "," +                         // Libref
        "" + "," +                                         // Pins
        "1" + "," +                                        // Quantity
        E.name +                                            // No.
        "\n";

    return strrpl(res, "%", "%%");
}

string format_pos_item(UL_ELEMENT E) {
    string res =
        E.name + "," +                      // Designator
        E.footprint.name + "," +            // Footprint
        fmt_num(u2mm(E.x)) + "," +
        fmt_num(u2mm(E.y)) + "," +          // Mid X, Mid Y
        "," +                               // Ref X 
        "," +                               // Ref Y
        "," +                               // Pad X
        "," +                               // Pad Y
        get_layer(E.footprint) + "," +      // Layer
        fmt_num(E.angle) + ","  +           // angle
        // E.value +                           // Comments
        "\n";

    return strrpl(res, "%", "%%");
}

void gen_CSV(UL_BOARD B) {
    string pos_file = B.name + "_JLC_SMT_Pos.CSV";
    string bom_file = B.name + "_JLC_SMT_Bom.CSV";
    string bom_lines = "";
    string pos_lines = "";

    B.elements(E) {
        bom_lines += format_bom_item(E);
        pos_lines += format_pos_item(E);
    } // foreach elem

    output(bom_file) {
        printf(BOM_HEADER);
        printf(bom_lines);
    } 

    output(pos_file) {
        printf(POS_HEADER);
        printf(pos_lines);
    }

    string msg = 
        "All jobs are done!\n\n" + 
        "BOM:\t" + bom_file + "\n" +
        "POS:\t" + pos_file + "\n";

    dlgMessageBox(msg, "+OK");
}

board(B) {
    gen_CSV(B);
}

If you find any any bugs, please let my know.

Good luck.

阅读 1.8k

A babysitter.

6 声望
2 粉丝
0 条评论

A babysitter.

6 声望
2 粉丝
文章目录
宣传栏