AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

turn ON or OFF fdo layer using AutoCAD .net

10 REPLIES 10
Reply
Message 1 of 11
dr5156
1020 Views, 10 Replies

turn ON or OFF fdo layer using AutoCAD .net

Hi all,

 

How to turn ON or OFF fdo layer using AutoCAD .net

 

Some one please share the information or Sample code.

 

Regards

Dayalan

Regards,
Dayalan
10 REPLIES 10
Message 2 of 11
hence_the_name
in reply to: dr5156

Hi Dayalan,

 

have a look at:

 

http://wikihelp.autodesk.com/AutoCAD_Map_3D/enu/2013/Help/0006-AutoCAD_0/0032-Maps_and32/0034-Basic_...

 

here is what works for me:c

 

AcMapMap currentMap = AcMapMap.GetCurrentMap();
                 MgLayerCollection layers = currentMap.GetLayers();
                 foreach (MgLayerBase layer in layers)
                 {
                             layer.SetVisible(true);
                         }
  

Rob

http://raumpatrouille3d.blogspot.ch/
Message 3 of 11
dr5156
in reply to: hence_the_name

Ho Rob

 

Thank you very much for your reply.

 

I tried this below code. But it is not working for me.

  

  1. Acutely I am using AutoCAD Map3D enterprise 2012(Topobase)
  2.  First I am opening the project.
  3. Generating the graphics, Layers will be added in FDO task pane
  4. And then running my tool, which I created as Plug-in.

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

Regards,
Dayalan
Message 4 of 11
hence_the_name
in reply to: dr5156

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

http://raumpatrouille3d.blogspot.ch/
Message 5 of 11
dr5156
in reply to: hence_the_name

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

 

Regards,
Dayalan
Message 6 of 11
hence_the_name
in reply to: dr5156

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

http://raumpatrouille3d.blogspot.ch/
Message 7 of 11
dr5156
in reply to: hence_the_name

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();

Regards,
Dayalan
Message 8 of 11
hence_the_name
in reply to: dr5156

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

http://raumpatrouille3d.blogspot.ch/
Message 9 of 11
dr5156
in reply to: hence_the_name

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....

Regards,
Dayalan
Message 10 of 11
hence_the_name
in reply to: dr5156

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

http://raumpatrouille3d.blogspot.ch/
Message 11 of 11
dr5156
in reply to: hence_the_name

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

Regards,
Dayalan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost