Script Editing - Tutorial 5 - Hole Recognition

This tutorial is an example on how you can speed up the program creation from existing 2D geometry with different machined holes.

Sample part :

In this sample part you can see different taped holes, counterbore and simple hole. We can recognize and classificate some of these diameter and associate related machining strategies.

For example , a inner circle of diameter 5mm , with an concentric arc of diameter 6mm, it represents a M6x1 tapped hole.

Or a 6.5mm inner diameter with a 10.5 outer circle, most probably it's a counterbore hole.

This time the script is composed by several functions , the necessary step are :

• Recognize a certain feature ( tapped hole, counterbore , etc )
• Associate a machining strategy to extracted recognized geometry
• Process the machining strategy.

Holes Recognition script file

Now we create a new script file and call it "HolesRecognition".

/// <summary>
/// This is the function you need to call from command line.
/// All the necessary sub-step are called here
/// </summary>
public void HoleRecognitionMain()
{
//Recognize and associate strategies to geometries holes
DefineHolesStrategies();

//It run all the created strategy with method above
RunStrategies();
}

/// <summary>
/// With this function, we recognize geometries as tapped holes
/// or counterbored holes or just a simple drilled holes,
/// and we associate extracted geometries to a machining strategy
/// </summary>
public void DefineHolesStrategies()
{
//
// METRIC -
if (Unit == MeasureUnit.Metric)
{
//TAPPED HOLES - (mm)

//COUNTERBORED HOLES - (mm)

//SIMPLE HOLE - (mm)

}

//
// IMPERIAL
else if (Unit == MeasureUnit.Imperial)
{

// Add data in similar way as above but the dimension expressed in inch

}
}

/// <summary>
/// This strategy is called to create a TAPPED holes
/// machining from recognized geometries
/// </summary>
public void TapStrategy()
{
// These is extracted geometry or selected geometries in viewport
var geometries = GetSelectedGeometries();

// I get thread data compatible with current geometry selection

if (threadData == null) return;// No compatible thread data is found, exit from function.

//Initialize machining work parameters
work = InitWithCustomParameters(work);

//Define parameters
work.MillingParams.DrillHoleDiameter = predrillDia;
work.MillingParams.DepthDrill = tapDia * 3.5;

//Create sub operation
}

/// <summary>
/// This strategy is called to create a COUNTERBORED holes
/// machining from recognized geometries.
/// </summary>
public void CounterboreStrategy()
{
// These is extracted geometry or selected geometries in viewport
var geometries = GetSelectedGeometries();

// The geometries should be list of a couples of circles, rappresenting
// the outer and the inner diameter of the counterbore machining.

var firstCoupleOfDiameter = geometries.FirstOrDefault();

if (firstCoupleOfDiameter.Count() != 2)
return;

//By convention the first circle is the bigger.
var circleMax = firstCoupleOfDiameter.OfType<Circle>().OrderBy(c => c.Radius).First();
var circleMin = firstCoupleOfDiameter.OfType<Circle>().OrderByDescending(c => c.Radius).First();

//Initialize machining work parameters
work = InitWithCustomParameters(work);

var innerDia = circleMin.Radius * 2;
var outerDia = circleMax.Radius * 2;

//Define parameters
work.MillingParams.DrillHoleDiameter = innerDia;
work.MillingParams.DepthDrill = innerDia * 5;
work.MillingParams.DepthCounterbore = outerDia;

//Create sub operation

//
// If the counterbore diameter is big, i use a roughing cycle with endmill
if (Unit == MeasureUnit.Metric && outerDia > 16)
{
endMillCounterboreOp.Tool = FindRotaryTool(ToolType.MillType_EndMill, 10);

}
else if (Unit == MeasureUnit.Imperial && outerDia > 0.6)
{
endMillCounterboreOp.Tool = FindRotaryTool(ToolType.MillType_EndMill, 0.4);

}
else
{
//If the counterbore outerdia is less than 16mm or 0.6inch , i use a counterbore tool
}

}

/// <summary>
/// This strategy is called to create a SIMPLE DRILLED holes
/// machining from recognized geometries.
/// </summary>
public void SimpleDrillStrategy()
{
var geometries = GetSelectedGeometries();

//From geometry recognizer function, i get all circles grouped by diameter.
//For every different diameter i create a different machining work

foreach (var groupedByDiameter in geometries)
{
// I get the first circle of the group to obtain the diameter value.
var firstCircle = groupedByDiameter.FirstOrDefault() as Circle;

if (firstCircle == null) continue;

var diameterValue = firstCircle.Radius * 2;

work.MillingParams.DrillHoleDiameter = diameterValue;
work.MillingParams.DepthDrill = diameterValue * 5;

drillOp.Tool = FindRotaryTool(ToolType.DrillType_Drill, diameterValue);
}
}

Once the script is launched , this will be the project status, 15 operations are created automatically.

Note :

The effective holes depths must be adjusted manually , since there is no way to extract this information from a 2D drawing.