Hide menu
Loading...
Searching...
No Matches
CNC Machining DFM Analyzer Example

Demonstrates how to perform machining design analysis on a 3D model and print information about found issues and their parameters in a console.

Overview

In this example demonstrates how to perform machining design analysis on a 3D model using machining dfm analyzer tool (DFMMachining_Analyzer). For this purpose, used a console application that imports a STEP model, traverses through unique ModelData_Part , creates and runs DFMMachining_Analyzer, groups and prints information about found issues and their parameters into console. Machining design analysis will be performed for each unique ModelData_Part , but only for the scope of accepted geometries.


Application needs 2 input arguments to run:

Usage: machining_dfm_analyzer <input_file> <operation>, where:
<input_file> is a name of the file to be read
<operation> is a name of desired machining operation
Supported operations:
milling: CNC Machining Milling feature recognition
turning: CNC Machining Lathe+Milling feature recognition


For more information about machining design analysis visit CNC Machining Design for Manufacturing (DFM) page.

Implementation

PartProcessor class is inherited from SolidProcessor and overrides ProcessSolid method that are used to run design analysis on given shape. To reduce computation time, Machining_Data will be used as an input argument to perform design analysis. Machining data contains information about found features, therefore, the first step is to run Machining_FeatureRecognizer. The Machining_FeatureRecognizerParameters.SetOperation() method of the tool parameters is used to set the type of operation (Milling or LatheMilling). The operation type will be taking into account during recognition process and the recognition result will be different depending on it.
Once feature recognition is done, design analysis is run for various sub-processes (drilling / milling / turning). CombineFeatureLists method is used to combine issues from design analysis of different sub-processes.
After design analysis is performed, PrintIssues method is used to print information about found features and their parameters in a console.
Visit Model Explore Helper Implementation page for more information about base SolidProcessor class implementation.

class PartProcessor(shape_processor.SolidProcessor):
def __init__(self, theOperation):
super().__init__()
self.myOperation = theOperation
def CombineFeatureLists(self, theFirst: mtk.MTKBase_FeatureList, theSecond: mtk.MTKBase_FeatureList):
for anElement in theSecond:
if (self.myOperation == mtk.Machining_OT_LatheMilling
and mtk.DFMMachining_MillingIssue.CompareType(anElement)
and not mtk.DFMMachining_DeepPocketIssue.CompareType(anElement)):
continue
theFirst.Append(anElement)
def ProcessSolid(self, theSolid: mtk.Solid):
# Find features
aData = mtk.Machining_Data()
aRecognizer = mtk.Machining_FeatureRecognizer()
aRecognizer.Parameters().SetOperation(self.myOperation)
aRecognizer.Perform (theSolid, aData)
# Run drilling analyzer for found features
aDrillingParameters = mtk.DFMMachining_DrillingAnalyzerParameters()
aDrillingAnalyzer = mtk.DFMMachining_Analyzer(aDrillingParameters)
anIssueList = aDrillingAnalyzer.Perform(theSolid, aData)
# Run milling analyzer for found features
aMillingParameters = mtk.DFMMachining_MillingAnalyzerParameters()
aMillingAnalyzer = mtk.DFMMachining_Analyzer(aMillingParameters)
aMillingIssueList = aMillingAnalyzer.Perform(theSolid, aData)
# Combine issue lists
self.CombineFeatureLists(anIssueList, aMillingIssueList)
aTurningIssueList = mtk.MTKBase_FeatureList()
if self.myOperation == mtk.Machining_OT_LatheMilling:
# Run turning analyzer for found features
aTurninigParameters = mtk.DFMMachining_TurningAnalyzerParameters()
aTurningAnalyzer = mtk.DFMMachining_Analyzer(aTurninigParameters)
aTurningIssueList = aTurningAnalyzer.Perform(theSolid, aData)
# Combine issue lists
self.CombineFeatureLists(anIssueList, aTurningIssueList)
PrintIssues(anIssueList)

To traverse only unique parts of the imported model, the ModelData_ModelElementUniqueVisitor class is used.

aPartProcessor = PartProcessor(anOperation)
aVisitor = mtk.ModelData_ModelElementUniqueVisitor aVisitor (aPartProcessor);
aModel.Accept(aVisitor)

After performing design analysis, the object of FeatureGroupManager class is used to group and sort found issues. For this purpose, there is a traverse through all found issues and add each of them to FeatureGroupManager with a specified name.

for anIssue in theIssueList:
#drilling
if mtk.DFMMachining_SmallDiameterHoleIssue.CompareType(anIssue):
aManager.AddFeature("Small Diameter Hole Issue(s)", "Hole(s)", True, anIssue)
elif mtk.DFMMachining_DeepHoleIssue.CompareType(anIssue):
aManager.AddFeature("Deep Hole Issue(s)", "Hole(s)", True, anIssue)
elif ...
#milling
elif mtk.DFMMachining_NonStandardRadiusMilledPartFloorFilletIssue.CompareType(anIssue):
aManager.AddFeature("Non Standard Radius Milled Part Floor Fillet Issue(s)", "Floor Fillet(s)", True, anIssue)
elif mtk.DFMMachining_DeepPocketIssue.CompareType(anIssue):
aManager.AddFeature("Deep Pocket Issue(s)", "Pocket(s)", True, anIssue)
elif ...
#turning
elif mtk.DFMMachining_IrregularTurnedPartOuterDiameterProfileReliefIssue.CompareType(anIssue):
aManager.AddFeature("Irregular Turned Part Outer Diameter Profile Relief Issue(s)", "Outer Diameter Profile Relief(s)", True, anIssue)
elif mtk.DFMMachining_SmallRadiusTurnedPartInternalCornerIssue.CompareType(anIssue):
aManager.AddFeature("Small Radius Turned Part Internal Corner Issue(s)", "Internal Corner(s)", True, anIssue)
elif ...

After adding all found issues to FeatureGroupManager, a Print method of the manager is used to print information about found issues and their parameters in a console. PrintFeatureParameters is created to explore and print issue parameters. It uses as an input parameter of Print method.

def PrintFeatureParameters(theIssue: mtk.MTKBase_Feature):
if mtk.DFMMachining_SmallDiameterHoleIssue.CompareType(theIssue):
aSDHIssue = mtk.DFMMachining_SmallDiameterHoleIssue.Cast(theIssue)
feature_group.FeatureGroupManager.PrintFeatureParameter("expected min diameter", aSDHIssue.ExpectedMinDiameter(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter("actual diameter", aSDHIssue.ActualDiameter(), "mm")
elif mtk.DFMMachining_DeepHoleIssue.CompareType(theIssue):
aDHIssue = mtk.DFMMachining_DeepHoleIssue.Cast(theIssue)
feature_group.FeatureGroupManager.PrintFeatureParameter("expected max depth", aDHIssue.ExpectedMaxDepth(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter("actual depth", aDHIssue.ActualDepth(), "mm")
elif ...

Visit Feature Group Helper Implementation page for more information about FeatureGroupManager class implementation.

Example output

The first is an example output for model from ./examples/models/Fresamento_CAM1_v3.stp and operation set to Milling. and the second one is an output for model from ./examples/models/senthi.step and operation set to Lathe+Milling.

Model Example output
Model: Fresamento_CAM1_v3.stp

Part #0 ["Fresamento_CAM1"] - solid #0 has:
    Deep Hole Issue(s): 4
        4 Hole(s) with
          expected max depth: 29.841 mm
          actual depth: 31.3245 mm
    Non Standard Diameter Hole Issue(s): 4
        4 Hole(s) with
          nearest standard diameter: 9 mm
          actual diameter: 8.526 mm
    ...

    Total issues: 24
Model: senthi

Part #0 ["drawing no 1"] - solid #0 has:
    Non Standard Radius Milled Part Floor Fillet Issue(s): 2
        1 Floor Fillet(s) with
          nearest standard radius: 4 mm
          actual radius: 5 mm
        1 Floor Fillet(s) with
          nearest standard radius: 4 mm
          actual radius: 50 mm
    Non Perpendicular Milled Part Shape Issue(s): 1
        1 Shape(s) with
          actual angle: 141.936 deg
    Milled Part External Edge Fillet Issue(s): 1
    Inconsistent Radius Milled Part Floor Fillet Issue(s): 1
        1 Floor Fillet(s) with
          expected radius: 5 mm
          actual radius: 50 mm

    Total issues: 5

Files