📄 mill-outlines.ulp
字号:
#usage "<b>Export milling data for a board layout</b>\n"
"<br>"
"<author>Author: support@cadsoft.de</author>"
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
// 08.05.2002 alf@cadsoft.de - reverse milling
// 23.06.2002 alf@cadsoft.de - Polygon:CHANGE THERMAL OFF
// 14.05.2003 alf@cadsoft.de - With REFERENCE-Drill to mirror for drilling machine
// - Switch On/Off 2. isolate/cupper pouring
// 02.09.2003 - Switch On/Off drills
// 24.04.2004 alf@cadsoft.de - String ulp_path no longer necessary
string Version = "Outlines generator for PCB milling. ULP-Version 4.1.03";
/*
Complete the following steps to add a new output device definition:
1. Add a new member to the 'enum { devScript = 1, ...'
2. Add the new (unique!) device name to 'DeviceNames[]'
3. Add the necessary 'case dev...' branches to
'DeviceInit()',
'DeviceReInit()',
'DeviceDraw()',
'CircleDraw()',
'ArcDraw()'
and 'DeviceEnd()'
4. Add also new Tool values to
'toolFiles()'
and 'ValueInit()'
*/
string DRCinfo = "<qt><b>Distance info:</b><br>Distance Copper/Dimension (see <b>DRC</b>) this is the distance between <br>"
"the polygon and outline of the board. If the value for 'Copper/Dimension' <br>"
"in the DRC settings is set higher than the radius of the mill tool#2, the <br>"
"board dimensions will be milled larger by the difference of these two <br>"
"respective values. For the best result, make sure the value for <br>"
"<b>Copper/Dimension</b> in <b>DRC Distance</b> is set on <b>0.01 mm</b>, or use the <br>"
"same value in the Design Rule's settings as the radius of the milling tool#2 <br>"
"is, before running this ULP!<p>"
"Press button <b>Reference</b> to generate a reference Package to place<br>"
"refernece holes on PCB for exact mirroring the bottom side of PCB on milling machine.<br>"
"</qt>";
string infoREFERENCE = "<nobr>Generate a special package with<br>" +
"REFERENCE circles in Layer Holes.<br>" +
"Place it in the layout for milling and <br>" +
"mirroring (bottom side) with offset and <br>" +
"start this ULP again.<br>";
"The position of the circles are defined<br>" +
"in the NC drill data file which comes<br>" +
"from the NC machine (eg. Excellon).</nobr><p>";
//
// The various output devices
//
int defaultdevice = 2; // set default device
int SelectedDevice = 0;
string Device;
enum { devScript = 1, devHPGL };
string DeviceNames[] = { "Select a device", "SCRIPT", "HPGL" };
string DeviceExt[] = { ".$$$" , ".scr", ".plt" };
string DrillExt[] = { ".$$$" , "_drl.scr" , "" };
string DefaultSuffix = DeviceExt[0];
string DrlDefaultSuffix = DrillExt[0];
string DrillLabel = "D&rill file";
string DrBrowse = "Bro&wse";
//
// Parmameters
//
// *** The milling tool diameter ***
real MillToolOutl = 0.2;
real MillToolIsolate = 0.0; //
int OverlapOutlPercent = 20; // percent, to avoid fine copper lines while milling out the area
real MillToolFree = 0.8; // Blow up & free pouring
int millfreeyes = 1; // free pouring on/off
int OverlapRubOut = 20; // percent, to avoid fine copper lines while milling out the area
real DrillPad = 0.8;
real DrillVia = 0.8;
real DrillHole = 0.8;
int onlydrill = 0; // output only drill on HPGL
int generatedrills = 1; // aktivate drills only in one export file
// while drills crashed in 2. run.
real DimensionMillTool = 2.0; // milling board outline from holder
real Distance_Copper_Dimension = 1.016; // default value
real Holder_Spacing = 10.0; // in mm, the distance to make a holder spacing for outline miling.
// The HPGL PEN list
enum { PadDrill = 1, ViaDrill, Contour, BlowUp_RubOut, HoleDrill, DimensionLine } // HPGL Pen select "SP.."
string PenList[];
PenList[PadDrill] = "PadDrill";
PenList[ViaDrill] = "ViaDrill";
PenList[Contour] = "Contour";
PenList[BlowUp_RubOut] = "Blow-Up/Rub-Out";
//PenList[RubOut] = "Rub-Out";
PenList[HoleDrill] = "HoleDrill";
PenList[DimensionLine] = "DimensionLine";
string sToolValue[]; // Tool diameter as String
enum { HPGLsolution = 1016 } // Inch/1016 = 0.025 mm
real Mirror = 1.0;
string ref_pac = "_REFERENCE_HOLE_"; // special package for mirror milling data
int mirr_offsetx = 0;
int ref_null_offsetX = 0;
int ref_null_offsetY = 0;
int ref_offsetX[];
int ref_offsetY[];
int ref_cnto = 0;
int Layer = 0;
string fillstyle = "Interleave"; // 9 Interleave
string lOutl;
string trueOutline_coordinate; // the generatet polygon outlines for the milling polygon
string OutlinesSignalName = "_OUTLINES_"; // reserved Signal name for special polygon
string OutlineMillSignal = "$_OUTLINEMILL_$";
string PassDimensionPoly = "PASSDIMESION"; // the true output line defined by Layer 20 Dimension
string Pass2 = "PASS_2";
string PassPour = "PASS_POUR";
string PassOutmill = "PASS_OUTLINE";
string InPassDimensionPoly;
string InPass2;
string InPassPour;
string InPassOutmill;
int menu = 0;
string showpic[];
string info;
string infotext;
string path;
string File, FileName;
string DrFile, DrillFile;
int test = 0;
// *** Functions ***
void viewtest(string txt) {
dlgDialog("test") {
dlgHBoxLayout {
dlgTextEdit(txt);
dlgVBoxLayout dlgSpacing(150);
}
dlgHBoxLayout {
dlgPushButton("OK") dlgAccept();
dlgPushButton("Cancel") { dlgReject(); exit(0); }
dlgSpacing(400);
}
};
return;
}
void Warning(string Message, string Details) {
dlgMessageBox("<b>Warning: " + Message + "</b> " + Details, "OK");
return;
}
void Fatal(string Message, string Details) {
dlgMessageBox("<b>ERROR: " + Message + "</b><hr><p>\n" + Details);
exit(1);
}
void Error(string Message, string Details) {
dlgMessageBox("<b>ERROR: " + Message + "</b><p>\n" + Details);
}
if (!board) Fatal("No board!", "This program can only work in the board editor.");
void dirtest(void) {
string a[];
int n = fileglob(a, "*.*");
if (n) {
dlgMessageBox("Working directory:\n" + filedir(a[0]), "OK");
}
return;
}
string vunit(int val, int unit) {
string s;
if (unit) sprintf(s, "%.4f", u2mm(val));
else sprintf(s, "%.6f",u2inch(val));
return s;
}
string getval(string line, real exf, real refholediameter) {
int Y = strchr(line, 'Y');
string s;
sprintf(s, "(%.4f %.4f) (%.4f %.4f);\n",
strtol(strsub(line, 1)) * exf,
strtol(strsub(line, Y+1)) * exf,
strtol(strsub(line, 1)) * exf + refholediameter/2 * exf,
strtol(strsub(line,Y+1)) * exf );
return s;
}
void setZerroReference(void) {
int refunit = 0;
int format = 0;
string ReferenceUnit[] = { "INCH", "MM", "INCH", "MM" };
real exf[] = { 0.001, 0.0001, 0.001, 0.0001 };
// Drillformat 2.3 2.4 2.3 2.4
// Unit Inch Inch MM MM
real refhdiameter[] = { 118, 1180, 3000, 30000 };
int Result = dlgDialog(filename(argv[0]) + " - generate refernece and place on Board") {
dlgLabel(showpic[17]);
dlgLabel(infoREFERENCE);
dlgHBoxLayout {
dlgGroup("Unit") {
dlgHBoxLayout {
dlgRadioButton("INCH", refunit);
dlgRadioButton("MM", refunit);
dlgStretch(1);
}
}
dlgStretch(1);
}
dlgGroup("Format") {
dlgHBoxLayout {
dlgRadioButton("2.3", format);
dlgRadioButton("2.4", format);
dlgStretch(1);
}
}
dlgHBoxLayout {
dlgPushButton("+OK") dlgAccept();
dlgStretch(1);
dlgPushButton("-Cancel") dlgReject();
}
};
if (Result) {
board(B) {
string usedlibraries = "USE -*;\n";
int u = 0;
do {
if (used_libraries[u]) {
usedlibraries += "USE '" + used_libraries[u] + "';\n";
u++;
}
} while(used_libraries[u]);
string used_scr = filedir(B.name) + "used-lbrs-" + filesetext(filename(B.name), ".scr");
output(used_scr, "wt") {
printf("%s", usedlibraries);
}
dlgMessageBox("<nobr>After reference package placing start the<br>" +
used_scr +
"<br>to set the used libraries back.", "OK");
string cmd;
string ref[];
string reference_file = dlgFileOpen("Select drill reference file (Holes)", "", "*.ncd\n*.*");
if (!reference_file) return;
int unit_format = refunit * 2 + format;
int l;
l = fileread(ref, reference_file);
string lbrname;
lbrname = filesetext(B.name, "$$$ref_tmp.lbr");
sprintf( cmd, "OPEN '%s';\n", lbrname );
cmd += "Edit '" + ref_pac + ".PAC';\nCHANGE LAYER 45;\nGRID " + ReferenceUnit[refunit] + ";\n";
for (int n = 0; n <= l; n++) {
string s = ref[n];
if(s[0] == 'X') cmd += "CIRCLE 0 " + getval(ref[n], exf[unit_format], refhdiameter[unit_format]);
}
cmd += "WRITE;\n";
cmd += "EDIT '" + B.name + "';\n";
cmd += "DISPLAY 45;\n";
cmd += "GRID " + ReferenceUnit[refunit] + ";\n";
cmd += "WIN FIT; WIN (" +
vunit((B.area.x1 + B.area.x2 )/2, refunit) + " " +
vunit((B.area.y1 + B.area.y2 )/2, refunit) + ") (" +
vunit((B.area.x1 + B.area.x2 )/2 + 1000, refunit) + " " +
vunit((B.area.y1 + B.area.y2 )/2 + 1000, refunit) + ") (" +
vunit((B.area.x1 + B.area.x2 )/2 + 150 , refunit) + " " +
vunit((B.area.y1 + B.area.y2 )/2 + 150 , refunit) + ");\n",
cmd += "USE -*; USE '" + lbrname + "';\n";
cmd += "ADD " + ref_pac + "\n";
if (test) viewtest(cmd);
exit(cmd);
}
}
return;
}
// *** Tools in EXCELLON and GERBER (mm)
void toolFiles(void) {
board(B) {
output(filesetext(B.name, ".rac")) {
printf("T01 %.1f mm\n", DrillPad);
printf("T02 %.1f mm\n", DrillVia);
printf("T03 %.1f mm\n", MillToolOutl);
printf("T04 %.1f mm\n", MillToolFree);
printf("T05 %.1f mm\n", DrillHole);
printf("T06 %.1f mm\n", DimensionMillTool);
}
output(filesetext(B.name, ".whl")) {
printf(";aperture wheel file generated by %s %s\n", EAGLE_SIGNATURE, filename(argv[0]) );
printf(";remove the above line to prevent this file from being overwritten!\n");
printf("D11 round %6.4fmm\n", DrillPad);
printf("D12 round %6.4fmm\n", DrillVia);
printf("D13 round %6.4fmm\n", MillToolOutl);
printf("D14 round %6.4fmm\n", MillToolFree);
printf("D15 round %6.4fmm\n", DrillHole);
printf("D16 round %6.4fmm\n", DimensionMillTool);
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -