Eyeshot includes a Block, called RootBlock, that represents the scene root. This means that every single piece of geometry is always inside a Block definition. The Workspace.Entities collection is a shortcut that refers always to a Block.Entities collection, normally of the RootBlock if you don't work with the assembly navigation feature.
BlockKeyedCollection
The BlockKeyedCollection, if and only if assigned to a Workspace, always has a root block defined. The root block is not typed, has no properties different than other blocks, it simply must be identified to initialize the scene when a new BlockKeyedCollection is assigned to a workspace. For it, you have to use the BlockKeyedCollection.SetRootBlock(string key) method:
BlockKeyedCollection blocks = new BlockKeyedCollection();
string name = "MyRootBlock";
blocks.Add(new Block(name));
blocks.SetRootBlock(name);
design1.Blocks = blocks;
Once the BlockKeyedCollection is assigned to a workspace, the root block can't be removed, but you can rename it simply by changing its name property or replace it:
design1.RootBlock.Name = "newName";
design1.Blocks.ReplaceItem(newRoot);
The name of the RootBlock is stored in the BlockKeyedCollection.RootBlockName. If this string is null or empty, the collection doesn't have a root block specified. To get an instance, there is the Workspace.RootBlock shortcut.
Block with EntityList
The Block.Entities collection is an EntityList. Properties and methods of the EntityList work at block level so it's possible to operate only in a specified context and not on the whole scene. To work on the whole scene you should always refer to the RootBlock.
For example:
block.Entities.Regen(); //regenerates only the entities of the block
design1.RootBlock.Entities.Regen(); //regenerates all the entities of the root block that are also all the entities of the design.
When an entity is added to a Block already assigned to a Workspace, it's automatically regenerated. It's highly recommended to fill the block entities before adding it to the Workspace.Blocks collection to prevent performance slow down during the geometry loading. For editing/reorganization of already loaded geometry, it's possible to temporarily suspend the automatic regeneration with BlockKeyedCollection.TakeOffLine(), to resume it call BlockKeyedCollection.BringOnline().
Import/Export
Depending on the import method used, the root block may be replaced by the the one loaded from the imported file.
Generally, in writer classes, we use the root block entities as main entities to be exported, but it's still possible to specify the desired list of entities by using the constructor with the collections:
Brep box = Brep.CreateBox(10, 10, 10);
WriteFileParams writeFileParams = new WriteFileParams(new Entity[]{box});
WriteFile writeFile = new WriteFile(writeFileParams, "box.eye");
writeFile.DoWork();
Adding the file contents to an existing 3D scene
A small example of how to insert the content of a file (*.eye or *.igs, *.stp, *.stl, etc.) to the existing 3D scene follows. In the case that the file contains a root block, its name may collide with the current one, so we need to change it.
ReadFileAsyncWithBlocks rfawb = rfa as ReadFileAsyncWithBlocks;
if (rfawb == null || rfawb.Blocks.RootBlockName == null)
{
rfa.FillAllCollectionsData(model1);
design1.Entities.AddRange(rfa.Entities);
}
else // the file contains a root block with a name that may collide with current one
{
const string newName = "dummy";
rfawb.Blocks["RootBlock"].Name = newName;
rfawb.FillAllCollectionsData(model1);
Entity ent = new BlockReference(newName);
design1.Entities.Add(ent);
}
You can read more on this topic here.
Comments
Please sign in to leave a comment.