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);
design1.Blocks.Add(red);
BlockReference brRed = new BlockReference(red.Name);
design1.Entities.Add(brRed);
Block blue = new Block("Blue");
blue.Entities.Add(Brep.CreateBox(20, 20, 20), Color.Blue);
design1.Blocks.Add(blue);
BlockReference brBlue = new BlockReference(40, 10, 0, blue.Name, 0.5);
brBlue.Rotate(0.3, Vector3D.AxisX);
design1.Entities.Add(brBlue);
Set a BlockReference as current
The basic method to set a BlockReference as current is Workspace.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. Workspace.SetParentAsCurrent() can be used to go back to the previous level.
design1.SetCurrent(brBlue);
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 (Workspace.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.
The Workspace.CurrentBlockReference property can be used to retrieve the current BlockReference, the property returns null if no BlockReference is set as current.
Open a Block
Before opening a block you must set one of the BlockRreference that refers to it as current, then you can use Workspace.OpenCurrentBlock(). With Workspace.CloseOpenBlock() you can close the OpenBlock and go back on the previous level, with Workspace.ResetOpenBlocks() you can close all opened blocks up to the RootBlock.
design1.OpenCurrentBlock();
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 Workspace.OpenBlock property can be used to retrieve the open Block. The Workspace.IsOpenRootLevel property indicates whether the OpenBlock is the RootBlock.
Seamless navigation
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.
Comments
Please sign in to leave a comment.