Hide menu
Loading...
Searching...
No Matches
Sheet Metal Feature Recognizer Example

Demonstrates how to perform recognition of sheet metal features on a 3D model and print information about found features and their parameters in a console.

Overview

In this example demonstrates how to perform recognition of sheet metal features on a 3D model using sheet metal feature recognition tool (SheetMetal_FeatureRecognizer). For this purpose, used a console application that imports a model, traverses through unique ModelData_Part , creates and runs SheetMetal_FeatureRecognizer, groups and prints information about found features and their parameters into console. Sheet metal feature recognition will be performed for each unique ModelData_Part , but only for the scope of accepted geometries.


Application needs 1 input argument to run:

Usage: sheet_metal_feature_recognizer <input_file>, where:
<input_file> is a name of the file to be read


For more information about feature recognition visit Sheet Metal page.

Implementation

PartProcessor class is inherited from ShapeProcessor and overrides ProcessSolid and ProcessShell methods that are used to run SheetMetal_FeatureRecognizer on given shapes. Then PrintFeatures 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 ShapeProcessor class implementation.

class PartProcessor(shape_processor.ShapeProcessor):
def __init__(self):
super().__init__()
self.myRecognizer = mtk.SheetMetal_FeatureRecognizer()
def ProcessSolid(self, theSolid: mtk.Solid):
aFeatureList = self.myRecognizer.Perform(theSolid)
PrintFeatures(aFeatureList)
def ProcessShell(self, theShell: mtk.Shell):
aFeatureList = self.myRecognizer.Perform(theShell)
PrintFeatures(aFeatureList)

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

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

After performing feature recognition, the object of FeatureGroupManager class is used to group and sort found sheet metal features. For this purpose, there is a traverse through all found features and add each of them to FeatureGroupManager with a specified name.

def GroupByParameters(theFeatureList: mtk.MTKBase_FeatureList, theManager: feature_group.FeatureGroupManager):
for aFeature in theFeatureList:
if mtk.SheetMetal_Bead.CompareType(aFeature):
theManager.AddFeature("Bead(s)", "Bead(s)", True, aFeature)
elif mtk.SheetMetal_Cutout.CompareType(aFeature):
theManager.AddFeature("Cutout(s)", "Cutout(s)", True, aFeature)
elif ...

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

def PrintFeatureParameters(theFeature: mtk.MTKBase_Feature):
if mtk.SheetMetal_Bead.CompareType(theFeature):
aBead = mtk.SheetMetal_Bead.Cast(theFeature)
feature_group.FeatureGroupManager.PrintFeatureParameter("depth", aBead.Depth(), "mm")
elif mtk.SheetMetal_Cutout.CompareType(theFeature):
aCutout = mtk.SheetMetal_Cutout.Cast(theFeature)
feature_group.FeatureGroupManager.PrintFeatureParameter("perimeter", aCutout.Perimeter(), "mm")
elif ...

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

Example output

Below is the example output for model from ./examples/models/Power_box_Chasis.stp.

Model Example output
Model: Power_box_Chasis

Part #0 ["power box sheetmetal"] - solid #0 has:
    Bend(s): 8
        2 Bend(s) with
          radius: 0.7366 mm
          angle: 90 deg
          length: 1.15705 mm
          width: 60 mm
        2 Bend(s) with
          radius: 0.7366 mm
          angle: 90 deg
          length: 1.15705 mm
          width: 137.327 mm
        4 Bend(s) with
          radius: 0.7366 mm
          angle: 90 deg
          length: 1.15705 mm
          width: 148 mm
    ...

    Total features: 76

Files