Demonstrates how to perform unfolding of 3D model.
Overview
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.
public override void Apply(Part thePart)
{
string aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name().ToString();
var aBodyVec = thePart.Bodies();
if (aBodyVec.Count != 0)
{
for (int i = 0; i < aBodyVec.Count; ++i)
{
Body aBody = aBodyVec[i];
var aShapeIt = new ShapeIterator(aBody);
while (aShapeIt.HasNext())
{
var aShape = aShapeIt.Next();
if (aShape.Type() == ShapeType.Solid)
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - solid #{i} has:\n");
ProcessSolid(Solid.Cast(aShape), aPartName, i);
}
else if (aShape.Type() == ShapeType.Shell)
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - shell #{i} has:\n");
ProcessShell(Shell.Cast(aShape), aPartName, i);
}
}
}
}
++myPartIndex;
}
ProcessSolid and ProcessShell methods are used to run sheet metal unfolder for given entities.
public void ProcessSolid(Solid theSolid, string thePartName, int theShapeIndex)
{
SheetMetal_FlatPattern aFlatPattern = myUnfolder.Perform(theSolid);
PrintFlatPatternInfo(aFlatPattern);
}
public void ProcessShell(Shell theShell, string thePartName, int theShapeIndex)
{
SheetMetal_FlatPattern aFlatPattern = myUnfolder.Perform(theShell);
PrintFlatPatternInfo(aFlatPattern);
}
To traverse only unique parts of the imported model, the ModelData.ModelElementUniqueVisitor class is used.
var aPartProcessor = new PartProcessor();
var aVisitor = new ModelData.ModelElementUniqueVisitor(aPartProcessor);
aModel.Accept(aVisitor);
Method PrintFlatPattern is used to explore and print flat pattern parameters.
static void PrintFlatPattern(SheetMetal_FlatPattern theFlatPattern)
{
if (theFlatPattern.IsNull())
{
Console.WriteLine($" Failed to create flat pattern.");
return;
}
Console.WriteLine($" Flat Pattern with:");
Console.WriteLine($" length: {theFlatPattern.Length()} mm");
Console.WriteLine($" width: {theFlatPattern.Width()} mm");
Console.WriteLine($" thickness: {theFlatPattern.Thickness()} mm");
Console.WriteLine($" perimeter: {theFlatPattern.Perimeter()} mm");
}
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