You can use the WriteFileParams constructor that accepts the single collections.
Please consider the below scene with 10 colored meshes:
using devDept.Eyeshot.Entities;
using devDept.Eyeshot;
using devDept.Eyeshot.Control;
using devDept.Graphics;
using devDept.Eyeshot.Translators;
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
Could be that to ensure accurate rendering of the entity, it is necessary to store any other required master collection items as well.
Take into account the following scene, which includes a single LinearPath with a pattern defined by its 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);
design1.ActiveViewport.Grid.Visible = false; // hides the grid just to see the pattern.
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.