This article explains the basic concept of assembly navigation. For a better understanding, it is recommended to read the RootBlock article first. For an advanced implementation of this feature, you can see the code of the AssemblyDemo sample.
Take for example a simple scene with two blocks, in addition to the root one.
Block red = new Block("Red"); red.Entities.Add(Brep.CreateBox(20, 20, 20), Color.Red); model1.Blocks.Add(red); BlockReference brRed = new BlockReference(red.Name); model1.Entities.Add(brRed); Block blue = new Block("Blue"); blue.Entities.Add(Brep.CreateBox(20, 20, 20), Color.Blue); model1.Blocks.Add(blue); BlockReference brBlue = new BlockReference(40, 10, 0, blue.Name, 0.5); brBlue.Rotate(0.3, Vector3D.AxisX); model1.Entities.Add(brBlue);
Set a BlockReference as current
The basic method to set a BlockReference as current is Environment.SetCurrent(). The BlockReference must be a first-level child of the current scene. If the parameter is null, the current BlockReference is unset and the scene goes back to the root level of the OpenBlock. Environment.SetParentAsCurrent() can be used to go back to the previous level.
When a BlockReference is set as current, only the referenced block entities are active on the scene, others are still visible but in a "frozen" state. Entities are shown in the OpenBlock reference system, so with the accumulated parents transformation (Environment.CurrentTransformation property). This context allows you to focus and operate on a single part of the model but showing it within the rest of the scene.
Open a Block
Before opening a block you must set one of the BlockRreference that refers to it as current, then you can use Environment.OpenCurrentBlock(). With Environment.CloseOpenBlock() you can close the OpenBlock and go back on the previous level, with Environment.ResetOpenBlocks() you can close all opened blocks up to the RootBlock.
There is always an OpenBlock, which is the RootBlock when the environment is initialized. When a Block is "open" only its entities are shown, the rest of the scene is hidden and not involved in any operation such as bounding box computation, zoom fit, and so on. Entities are shown in the Block reference system, without the parents transformation. It's like having a new window only on the OpenBlock.
The introduction of a root block allows seamless navigation through assemblies, with endless edit/open command combinations, since there is no longer a collection of entities associated with the environment but the entities are always inside a block.
The internal data structures used to store the information on open and current blocks are stacks. So, following the LIFO concept, the navigation can only be done on one branch at a time and basically going down and going up one level at a time.