Drawing layer visiblity

Hi,

I need help in creating journal to fix layer visibility in all drawing sheets and in all views in Drawing files.

Journal requirement:

In Sheets : all layers(1-256) should be Visible

In Views : By default (Layer 1) should be Visible and some additional layer also, the layer numbers may vary.

Provide user interface for specifying the additional layers to be made visible in the views.

Finally I need a information window on "Layers", List of layer used in drawings i.e. "layers with objects" information and which layer is WORK layer.

What code do you have so far and where are you stuck?

this is the code I am using to fix layers visible in views, this makes only layer 1 visible.
I am in need of some extra layers also visible (for Example layer no. 10, 11).
these layer numbers may vary from drawing to drawing.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using NXOpen;
using NXOpen.Drawings;
using NXOpen.Layer;

namespace DrawingLayerSettings
{
public class NXfunction
{
// class members
private static Session _theSession;
public static NXfunction TheNXfunction;
public static bool IsDisposeCalled;

//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
public NXfunction()
{
try
{
_theSession = Session.GetSession();

IsDisposeCalled = false;
}
catch (NXException)
{
// ---- Enter your exception handling code here -----
// UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
}
}

//------------------------------------------------------------------------------
// Explicit Activation
// This entry point is used to activate the application explicitly
//------------------------------------------------------------------------------
public static int Main(string[] args)
{
const int retValue = 0;
try
{
TheNXfunction = new NXfunction();
_theSession = Session.GetSession();
LogFile logFile = _theSession.LogFile;
Part workPart = _theSession.Parts.Work;
CategoryCollection categoryCollection = workPart.LayerCategories;
ListingWindow lW = _theSession.ListingWindow;
var layerCategoryAndName = new Dictionary();
lW.Open();
foreach (Category category in categoryCollection)
{
string categoryName = category.Name;
if (categoryName != "ALL")
{
int[] memberLayers = category.GetMemberLayers();
foreach (int layer in memberLayers)
{
if (!layerCategoryAndName.ContainsKey(layer))
{
layerCategoryAndName.Add(layer, categoryName);
}
}
}
}

if (workPart != null)
{
DraftingManager draftingManager = workPart.Drafting;

if (draftingManager != null)
{
DrawingSheetCollection drawingSheetCollection = _theSession.Parts.Work.DrawingSheets;
var stateArray = new StateInfo[256];
for (int i = 0; i < 256; i++)
{
stateArray[i] = new StateInfo(i + 1, State.Hidden);
}
foreach (DrawingSheet drawingSheet in drawingSheetCollection)
{
SheetDraftingViewCollection sheetDraftingViewCollection = drawingSheet.SheetDraftingViews;
foreach (View view in sheetDraftingViewCollection)
{
stateArray[0] = new StateInfo(1, State.Visible);
workPart.Layers.SetObjectsVisibilityOnLayer(view, stateArray, true);
}
}
//lW.Open();
for (int j = 0; j < 256; j++)
{
NXObject[] allObjectsOnLayer = workPart.Layers.GetAllObjectsOnLayer(j+1);
int objectCount = allObjectsOnLayer.Count();
if (objectCount > 0)
{
int layerNumber = j + 1;
string getLayerCategoryName = layerCategoryAndName[layerNumber];
string layerNumberAndObjects = "Layer No: " + layerNumber.ToString(CultureInfo.InvariantCulture) + "-------" + "Number Of Objects: " + objectCount + " Category Name: " + getLayerCategoryName;
logFile.WriteLine(layerNumberAndObjects);
lW.WriteLine(layerNumberAndObjects);
lW.WriteLine("\n");
}
}
lW.Close();
UI.GetUI()
.NXMessageBox.Show("INFO", NXMessageBox.DialogType.Information,
"All Views Layer settings are applied succesfully");
TheNXfunction.Dispose();
}
else
{
UI.GetUI()
.NXMessageBox.Show("INFO", NXMessageBox.DialogType.Information,
"Open drawing To start the application");
}
}
else
{
UI.GetUI()
.NXMessageBox.Show("INFO", NXMessageBox.DialogType.Information,
"KIndly Open Drawing File starting the App");
}
}
catch (NXException)
{
// ---- Enter your exception handling code here -----
UI.GetUI()
.NXMessageBox.Show("INFO", NXMessageBox.DialogType.Information, "Cannot apply Layer Settings");

}
return retValue;
}

//------------------------------------------------------------------------------
// Following method disposes all the class members
//------------------------------------------------------------------------------
public void Dispose()
{
try
{
if (IsDisposeCalled == false)
{
//Add your application code here
}
IsDisposeCalled = true;
}
catch (NXException)
{
// ---- Enter your exception handling code here -----

}
}

public static int GetUnloadOption(string arg)
{
//Unloads the image explicitly, via an unload dialog
//return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);

//Unloads the image immediately after execution within NX
return Convert.ToInt32(Session.LibraryUnloadOption.Immediately);

//Unloads the image when the NX session terminates
//return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
}
}
}

"In Views : By default (Layer 1) should be Visible and some additional layer also, the layer numbers may vary."

I'd suggest by starting with creating a function that would accept a view and the layers that you want visible as arguments; then call the function for each view on the drawing.

I'm not sure why you need to add a GUI to your code. If you add a GUI, how is it different from using the NX interface?