You can use the WriteFileParams constructor that accepts the single collections.
Please consider the below scene with 10 colored meshes:
Random rand = new Random(100);
for (int i = 0; i < 10; i++)
{
var mesh = Mesh.CreateBox(5, 5, 5);
mesh.Translate(10 * i, 10 * 1);
mesh.ColorMethod = colorMethodType.byEntity;
mesh.Color = System.Drawing.Color.FromArgb((int)(0xFF000000 + (rand.Next(0xFFFFFF))));
design1.Entities.Add(mesh);
}
design1.ZoomFit();
design1.Invalidate();
If you need to save, for example, the first entity only, you can use the below code:
string fileName = "SingleMesh.eye";
new WriteFile(new WriteFileParams(new List<Entity>() { design1.Entities[0] })
, fileName).DoWork();
You can check the stored file by reading it back
design1.OpenFile(fileName);
design1.ZoomFit();
design1.Invalidate();
An entity linked to other collections
If the entity, to be correctly rendered, needs some other master collections items, you need to store them as well.
Please consider the below scene with a single LinearPath with a pattern defined by the layer:
string lineTypeDashDot = "DashDot";
design1.LineTypes.Add(lineTypeDashDot, new float[] { 5, -1.5f, 0.25f, -1.5f });
string layerDashDot = "LayerDD";
design1.Layers.Add(new Layer(layerDashDot) { LineTypeName = lineTypeDashDot });
var lp = new LinearPath(Plane.XY, 0, 0, 100, 50)
{
LayerName = layerDashDot,
LineTypeMethod = colorMethodType.byLayer
};
design1.Entities.Add(lp);
In this case, you need to save both Layer and LineType as well:
fileName = "SingleLp.eye";
new WriteFile(new WriteFileParams(new List<Entity>() { lp })
{
Layers = new LayerKeyedCollection() {design1.Layers[layerDashDot]},
LineTypes = new LineTypeKeyedCollection() {design1.LineTypes[lineTypeDashDot]}
}
, fileName).DoWork();
Comments
Please sign in to leave a comment.