Demonstrates how to perform unfolding of 3D model.
Overview
In this example demonstrates how to perform unfolding of 3D model using sheet metal unfolder tool (SheetMetal_Unfolder). For this purpose, used a console application that imports a model, collects unique ModelData_Part s, traverses through unique ModelData_Part s, creates and runs SheetMetal_Unfolder, prints information about flat pattern parameters into console.
Unfolding will be performed for each unique ModelData_Part , but only for the scope of accepted geometries.
Application needs one input arguments to run:
Usage: sheet_metal_unfolder <input_file>, where:
<input_file> is a name of the file to be read
For more information about unfolding visit Sheet Metal Unfolding page.
Implementation
To explore the model and process ModelData_Part you need to derive a class from the ModelData_ModelElementVoidVisitor and override the part processing method void operator() (const ModelData::Part& thePart)
. In this example we use the PartProcessor
class for this purpose. The operator()
method is implemented to check each ModelData_Part for the presence of B-Rep Geometry and ModelData_Solid or ModelData_Shell shapes in it.
def __call__(self, thePart: mtk.Part):
aPartName = "noname" if thePart.Name().IsEmpty() else str(thePart.Name())
aBodyList = thePart.Bodies()
i = 0
for aBody in aBodyList:
aShapeIt = mtk.ShapeIterator(aBody)
for aShape in aShapeIt:
if aShape.Type() == mtk.ShapeType_Solid:
print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - solid #", i, " has:", sep="")
self.ProcessSolid(mtk.Solid.Cast(aShape), aPartName, i)
i += 1
elif aShape.Type() == mtk.ShapeType_Shell:
print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - shell #", i, " has:", sep="")
self.ProcessShell(mtk.Shell.Cast (aShape), aPartName, i)
i += 1
self.myPartIndex += 1
ProcessSolid
and ProcessShell
methods are used to run sheet metal unfolder for given entities.
def ProcessSolid(self, theSolid: mtk.Solid, thePartName: str, theShapeIndex: int):
aFlatPattern = self.myUnfolder.Perform(theSolid)
PrintFlatPatternInfo(aFlatPattern)
def ProcessShell(self, theShell: mtk.Shell, thePartName: str, theShapeIndex: int):
aFlatPattern = self.myUnfolder.Perform(theShell)
PrintFlatPatternInfo(aFlatPattern)
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)
Method PrintFlatPattern
is used to explore and print flat pattern parameters.
def PrintFlatPattern(theFlatPattern: mtk.SheetMetal_FlatPattern):
if theFlatPattern.IsNull():
print(" Failed to create flat pattern.")
return
print(" Flat Pattern with:")
print(" length: ", theFlatPattern.Length(), " mm", sep="")
print(" width: ", theFlatPattern.Width(), " mm", sep="")
print(" thickness: ", theFlatPattern.Thickness(), " mm", sep="")
print(" perimeter: ", theFlatPattern.Perimeter(), " mm", sep="")
Example output
Below is the example output for model from ./examples/models/Part2.stp
.
Model: Part2
Part #0 ["Part2"] - solid #0 has:
Flat Pattern with:
length: 220.712 mm
width: 167.838 mm
thickness: 1 mm
perimeter: 1121.37 mm
|
Original model
|
Unfolded view
|
Files