By Naveen Kumar
In Navisworks, grids and levels are valuable tools for exploring a scene, providing spatial context for your location and the placement of objects within the environment.
You can access grids and levels through the "Grids & Levels" panel in the View tab. Now, let’s utilize the Navisworks API to work with grids and levels.
In this blog post, we will explore the following topics:
- Turns grids on or off
- Customizing grid line colors based on the camera’s position
- Configuring the grid mode
- Setting a specific display level when "Fixed" grid mode is selected
Turns grids on or off
// Access the active document in Navisworks Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument; // Retrieve grid options from the Navisworks application GridsOptions gridOptions = Autodesk.Navisworks.Api.Application.Options.Grids; // Enable grid visibility (set to 'false' to hide the grid) gridOptions.Enabled = true; // If X-ray mode is switched off, transparent gridlines hidden by objects will not be displayed. gridOptions.XRayMode = true;
Customizing grid line colors based on the camera’s position
// Customize grid line colors based on the camera's position gridOptions.AboveColor = new Color(1, 0, 0); gridOptions.BelowColor = new Color(0, 1, 0); gridOptions.OtherColor = new Color(1, 1, 1);
Configuring the grid mode
// Access the Grids object from the active document DocumentGrids docGrids = doc.Grids; // Set the grid render mode to show both above and below grid lines docGrids.RenderMode = GridsRenderMode.AboveAndBelow;
Setting a specific display level when "Fixed" grid mode is selected
GridSystem gridSystem = docGrids.ActiveSystem; // Set the grid render mode to "Fixed" and restrict grid visibility to a specific level // e.g., Level 3 // ensuring the grid remains fixed at that level during navigation. GridLevelCollection gridLevelCollection = gridSystem.Levels; GridLevel requiredGridLevel = gridLevelCollection.Where(level => level.DisplayName=="Level 3").First(); // Set grid render mode to "Fixed" if Level 3 is found if (requiredGridLevel != null) { docGrids.RenderMode = GridsRenderMode.Locked; docGrids.SetSystemLockedLevel(gridSystem, requiredGridLevel); }