Hi all,
How to turn ON or OFF fdo layer using AutoCAD .net
Some one please share the information or Sample code.
Regards
Dayalan
Hi Dayalan,
have a look at:
here is what works for me:c
AcMapMap currentMap = AcMapMap.GetCurrentMap();
MgLayerCollection layers = currentMap.GetLayers();
foreach (MgLayerBase layer in layers)
{
layer.SetVisible(true);
}
Rob
Ho Rob
Thank you very much for your reply.
I tried this below code. But it is not working for me.
But it is not working. Any suggestions?
AcMapMap acMap = AcMapMap.GetCurrentMap();
MgLayerCollection layers = acMap.GetLayers();
if (layers != null && layers.Count > 0)
{
foreach (MgLayerBase layer in layers)
{
layer.SetVisible(false);
}
}
Regards
Dayalan
Hi Dayalan,
there are many potential reasons why the plugin might fail. The code snippet does its job in my little plugin for Map 2012 Enterprise.
I'm not an experienced programmer - I only know that it took some time to get my stuff running and I relied heavily on "trial and error" approach. Can you provide a bit more information and / or your code / code example?
Rob
Please find the attached Source Code.
1. By using code, i have created the dll and tbp file.
2. then copied into AutoCAD bin folder.
3. Open the AutoCAD
4. Open the Project
5. Generate the graphics
6. Created plug-in button will apear.
6. Click on the button, The fdo layer should be in Turn off status. I
Regards
Dayalan
Hi Dayalan,
your plugin does what you want - when I click the button the layers are no longer visible in the drawing anymore.
I do no understand why you have a Forcerefresh in your plugin. As far as I understand that reloads the layer data. Why would you do that if you just have turned off the layer?
Have you just tried:
foreach (MgLayerBase layer in layers) { layer.SetVisible(false); }
Then go from there and add further code.
Rob
Hi Rob
Thanks for the reply.
i have have commented all the statements except layer.SetVisible(false);
But still my layer not getting turned off.
if i do Forece refresh, then my data will be in invisble state. but Layer still in turned ON state.
My original requirement is, Turn OFF some set of layers and turn ON some set of layers. I am strugling to turn off/On
i tried in different ways, but i am not getting result.
Note: I am using Enterprise(Topobase) data in Map3d. Not adding oracle spatial data directly. using Topobase functionality generating the data in Map3d.
Why the Discussion Groups not giving solutions for these kind off issue.
AcMapMap acMap = AcMapMap.GetCurrentMap();
MgLayerCollectionlayers = acMap.GetLayers();
if (layers != null&& layers.Count > 0)
{
foreach (MgLayerBase layer inlayers)
{
if(layer.GetVisible())
{
layer.SetVisible(
false);
//layer.Visible = false;//layer.ForceRefresh();
}
//if (layer.GetDisplayInLegend())//{// layer.DisplayInLegend = false;// layer.SetDisplayInLegend(false);// layer.ForceRefresh();//}
}
}
//AcMapMap.ForceScreenRefresh();
Hi,
I tried your original plugin with three Map Enterprise (Topobase) datasets and the result is always bit different.
In all cases the layers are no displayed anymore in the drawing.
Exception one:
- with one dataset one of the layers is still visible
But in DisplayManager all layer still appear "turned on". This happened with my data sets when:
- there were no groups
- there where groups but I had expanded them before running the plugin.
Only when the datasets has groups and I didn't expand them then the result was as you want: layers not displayed anymore and layers appear "turned off" in Display Manager.
See screenhot (after running the plugin I expanded the groups and layers appear "turned off" as well)
Don't know why that is - I'm using this function without any problems. Will have another look later on,
Rob
Please check, I am still having issue.
One more information.
The Plug-in will work only the first time after genrating the graphics.
After that turn on some layers manully and run the tool without generating the graphics. it will not work.
Please check and help me....
Hi,
so, I think the issue here is that your class is of type "DocumentPlugin". You are starting off with the "Topobase API" but you really are using Map API functionality (display management). And somehow it seems that there is something missing to make them work together.
When you create a simple AC Map class then the following code will do what you want. If you use the same code from within your DocumentPlugin class it will not work as expected. That is where I think you need to do further research.
Here is the code - snippet for an ordinary AC class. You need to reference acdbmgd and acmgd dlls from AutoCAD additionally.
... using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; namespace ClassLibrary1 { public static class Class1 { [CommandMethod("test101", CommandFlags.UsePickSet | CommandFlags.Modal | CommandFlags.Redraw)] public static void test1() { try { AcMapMap acMap = AcMapMap.GetCurrentMap(); MgLayerCollection layers = acMap.GetLayers(); if (layers != null && layers.Count > 0) { foreach (MgLayerBase layer in layers) { if (layer.IsVisible() == true || layer.GetVisible() == true) { layer.SetVisible(false); } else { layer.SetVisible(true); } } } }
Load dll with netload and type "test101". It will work with all kind of FDO layers.
Hope it helps you,
Rob
Hi Rob,
Great. I appreciate your support.
Yes. It is working for me now. I will take care from now to incorpearte with topobase plug-in.
Once again thank you.
Reagrds
Dayalan