CADability
CADability copied to clipboard
Exporting and importing step files loses data
The following piece of code generate a solid and exports it to a step file, then imports it and re-exports it to step file again. The first export is succefull, but when the step file is imported the model is corrupted as can be seen from the attachments.
static void Main(string[] args)
{
var project1 = Project.CreateSimpleProject();
//Create a shape with two nested squares
SimpleShape profile = buildProfile();
var start = new GeoPoint(0, 0, 0);
var surface = new PlaneSurface(start, GeoVector.YAxis, GeoVector.XAxis);
var face = Face.MakeFace(surface, profile);
var path = CADability.GeoObject.Path.Construct();
path.Add(Line.MakeLine(start, start + 2000 * GeoVector.ZAxis));
//Create a pipe and substract part of it.
Solid result = Solid.Construct();
result.SetShell((Shell)Make3D.MakePipe(face, path, project1));
result = Solid.Subtract(result, Make3D.MakeCylinder(new GeoPoint(0, 50, 1000), 20 * GeoVector.XAxis, 30 * GeoVector.YAxis)).Single();
project1.GetModel(0).Add(result);
//The file is correctly exported.
new ExportStep().WriteToFile("step1.stp", project1);
//Read the exported step file and export it again
var project2 = Project.CreateSimpleProject();
project2.GetModel(0).Add (new ImportStep().Read("step1.stp"));
//The exported model is corrupted.
new ExportStep().WriteToFile("step2.stp", project2);
}
private static SimpleShape buildProfile()
{
var outerborder = new BorderBuilder();
outerborder.AddSegment(new Line2D(new GeoPoint2D(0, 0), new GeoPoint2D(100, 0)));
outerborder.AddSegment(new Line2D(new GeoPoint2D(100, 0), new GeoPoint2D(100, 100)));
outerborder.AddSegment(new Line2D(new GeoPoint2D(100, 100), new GeoPoint2D(0, 100)));
outerborder.AddSegment(new Line2D(new GeoPoint2D(0, 100), new GeoPoint2D(0, 0)));
var innerBorder = new BorderBuilder();
innerBorder.AddSegment(new Line2D(new GeoPoint2D(10, 10), new GeoPoint2D(90, 10)));
innerBorder.AddSegment(new Line2D(new GeoPoint2D(90, 10), new GeoPoint2D(90, 90)));
innerBorder.AddSegment(new Line2D(new GeoPoint2D(90, 90), new GeoPoint2D(10, 90)));
innerBorder.AddSegment(new Line2D(new GeoPoint2D(10, 90), new GeoPoint2D(10, 10)));
return new SimpleShape(outerborder.BuildBorder(), innerBorder.BuildBorder());
}