#usage "Extracts the placement from parts to a script
\n"
"
\nThis program can only work in the board editor."); exit(1); } /////////////////////////////////////////// // Create layer list /////////////////////////////////////////// board(B) { B.layers(L) { if (L.used || L.number == iLayerRef) { if (L.number == iLayerRef) iLayerRefSel = iLayerCount; layer_number[iLayerCount] = L.number; sprintf (layer_name[iLayerCount++], "%d - %s", L.number, L.name); } } } /////////////////////////////////////////// // First Dialog /////////////////////////////////////////// iResult = dlgDialog("Extract placement (Step 1 of 2)") { dlgGroup("Elements to extract") { dlgLabel("Rectangles which contains the elements to extract are on Layer:"); dlgComboBox (layer_name, iLayerRefSel); } dlgHBoxLayout { dlgStretch(1); dlgPushButton("+Next >>") dlgAccept(); dlgPushButton("-Cancel") dlgReject(); } }; if (iResult == 0) exit(0); iLayerRef = layer_number[iLayerRefSel]; /////////////////////////////////////////// // Find reference Elements // (inside rectangles on layer 49) /////////////////////////////////////////// board(B) { B.rectangles(R) { if (R.layer == iLayerRef) { B.elements(E) { if (isElementInRectangle(E, R)) { extract[iCount] = 1; ref_x[iCount] = E.x; ref_y[iCount] = E.y; ref_angle[iCount] = E.angle; ref_mirror[iCount] = E.mirror; element[iCount] = E.name; RebuildListLine(iCount); iCount++; if (iCount == 1 || E.x < iMinX) iMinX = E.x; if (iCount == 1 || E.y < iMinY) iMinY = E.x; } } iRectCount++; } } strRefElements = " " + strjoin (element, ' ') + " "; } if (iRectCount == 0) { dlgMessageBox ("Error! No reference rectangle found!
You should draw a rectangle (RECT) on layer '" + layer_name[iLayerRefSel] + "' around the elements whitch are the placement reference."); exit(1); } if (iCount == 0) { dlgMessageBox ("Error! No elements found!
There are no reference elements inside the rectangle(s) on layer '" + layer_name[iLayerRefSel] + "'.");
exit(2);
}
///////////////////////////////////////////
// Second Dialog
///////////////////////////////////////////
real rOffsetX=u2mil(iMinX), rOffsetY=u2mil(iMinY);
iResult = dlgDialog ("Extract placement (Step 2 of 2)")
{
dlgGroup("Offset")
{
dlgGridLayout
{
/* dlgCell(0, 0) dlgHBoxLayout { dlgLabel("Unit:"); dlgSpacing(10); }
dlgCell(0, 1) dlgHBoxLayout
{
dlgRadioButton("&inch", iUnit);
dlgRadioButton("&mil", iUnit);
dlgRadioButton("&mm", iUnit);
dlgRadioButton("&mic", iUnit);
dlgStretch(1);
}
*/
dlgCell(1, 0) dlgLabel("X: ");
dlgCell(1, 1) dlgHBoxLayout { dlgRealEdit(rOffsetX); dlgLabel(" mil"); dlgStretch(1); }
dlgCell(2, 0) dlgLabel("Y: ");
dlgCell(2, 1) dlgHBoxLayout { dlgRealEdit(rOffsetY); dlgLabel(" mil"); dlgStretch(1); }
}
}
dlgGroup("Elements")
{
dlgLabel ("Double click on an item to select/unselect the element.");
dlgListView("Element\tExtract Placement", lines, iListSel) SwitchExtract();
}
dlgSpacing(10);
dlgHBoxLayout
{
dlgStretch(1);
dlgPushButton("Start") dlgAccept();
dlgPushButton("Cancel") dlgReject();
dlgStretch(1);
}
};
if (iResult == 0) exit(0);
////////////////////////////////////////////////////////////////////////////////////////////////////
/// GENERATE SCRIPT
////////////////////////////////////////////////////////////////////////////////////////////////////
string strMirror;
cmd = "GRID MIL 100 OFF;\n";
for (i=0; i