Hide menu
Loading...
Searching...
No Matches
Molding Feature Recognizer Example

Demonstrates how to perform recognition of molding 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 molding features on a 3D model using molding feature recognition tool (Molding_FeatureRecognizer). For this purpose, used a console application that imports a model, traverses through unique ModelData_Part , creates and runs Molding_FeatureRecognizer, groups and prints information about found features and their parameters into console. Molding 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: molding_feature_recognizer <input_file>, where:
<input_file> is a name of the file to be read


For more information about feature recognition visit Injection Molding page.

Implementation

PartProcessor class is inherited from SolidProcessor and overrides ProcessSolid method that are used to run Molding_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 SolidProcessor class implementation.

class PartProcessor(shape_processor.SolidProcessor):
def __init__(self):
super().__init__()
def ProcessSolid(self, theSolid: mtk.Solid):
# Set up recognizer
aRecognizerParameters = mtk.Molding_FeatureRecognizerParameters();
aRecognizerParameters.SetMaxRibThickness (30.0)
aRecognizerParameters.SetMaxRibDraftAngle (0.2)
aRecognizerParameters.SetMaxRibTaperAngle (0.1)
aRecognizer = mtk.Molding_FeatureRecognizer(aRecognizerParameters)
aFeatureList = aRecognizer.Perform (theSolid)
PrintFeatures(aFeatureList)

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

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

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

for aFeature in theFeatureList:
if mtk.Molding_ScrewBoss.CompareType(aFeature):
aScrewBoss = mtk.Molding_ScrewBoss.Cast(aFeature)
aManager.AddFeature ("Screw Boss(es)", "Screw Boss(es)", True, aScrewBoss)
elif mtk.MTKBase_Boss.CompareType(aFeature):
aBoss = mtk.MTKBase_Boss.Cast(aFeature)
aManager.AddFeature ("Boss(es)", "Boss(es)", True, aBoss)
elif mtk.Molding_Rib.CompareType(aFeature):
aRib = mtk.Molding_Rib.Cast(aFeature)
aManager.AddFeature ("Rib(s)", "Rib(s)", True, aRib)

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 feature parameters. It uses as an input parameter of Print method.

def PrintFeatureParameters(theFeature: mtk.MTKBase_Feature):
if mtk.Molding_ScrewBoss.CompareType(theFeature):
aScrewBoss = mtk.Molding_ScrewBoss.Cast(theFeature)
feature_group.FeatureGroupManager.PrintFeatureParameter ("outer radius", aScrewBoss.OuterRadius(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter ("inner radius", aScrewBoss.InnerRadius(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter ("draft angle", ToDegrees (aScrewBoss.DraftAngle()), "deg")
elif mtk.MTKBase_Boss.CompareType(theFeature):
aBoss = mtk.MTKBase_Boss.Cast(theFeature)
feature_group.FeatureGroupManager.PrintFeatureParameter ("length", aBoss.Length(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter ("height", aBoss.Height(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter ("width", aBoss.Width(), "mm")
elif mtk.Molding_Rib.CompareType(theFeature):
aRib = mtk.Molding_Rib.Cast(theFeature)
feature_group.FeatureGroupManager.PrintFeatureParameter ("length", aRib.Length(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter ("height", aRib.Height(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter ("thickness", aRib.Thickness(), "mm")
feature_group.FeatureGroupManager.PrintFeatureParameter ("draft angle", ToDegrees (aRib.DraftAngle()), "deg")

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

Example output

Below is an example output for model from ./examples/models/Part3.stp.

Model Example output
Model: Part3.stp

Part #0 ["Part3"] - solid #0 has:
    Rib(s): 5
        1 Rib(s) with
          length: 33.2764 mm
          height: 15.5984 mm
          thickness: 15 mm
          draft angle: 0 deg
        3 Rib(s) with
          length: 40 mm
          height: 29 mm
          thickness: 3.91237 mm
          draft angle: 0 deg
        1 Rib(s) with
          length: 127.988 mm
          height: 18.7895 mm
          thickness: 15 mm
          draft angle: 0 deg
    Screw Boss(es): 3
        1 Screw Boss(es) with
          outer radius: 18.85 mm
          inner radius: 15 mm
          draft angle: 0 deg
        1 Screw Boss(es) with
          outer radius: 22 mm
          inner radius: 10 mm
          draft angle: 0 deg
        1 Screw Boss(es) with
          outer radius: 22.3392 mm
          inner radius: 20 mm
          draft angle: 11.3099 deg

    Total features: 8

Files