AutoCAD Map 3D Developer

AutoCAD Map 3D Developer

Reply
Active Contributor
dr5156
Posts: 32
Registered: ‎12-08-2010
Message 1 of 11 (418 Views)

turn ON or OFF fdo layer using AutoCAD .net

418 Views, 10 Replies
11-06-2012 05:18 AM

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
Mentor
Robert_Fritz
Posts: 165
Registered: ‎12-08-2011
Message 2 of 11 (412 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-06-2012 07:12 AM 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/
Active Contributor
dr5156
Posts: 32
Registered: ‎12-08-2010
Message 3 of 11 (401 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-06-2012 08:41 PM in reply to: Robert_Fritz

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
Mentor
Robert_Fritz
Posts: 165
Registered: ‎12-08-2011
Message 4 of 11 (396 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-06-2012 11:08 PM 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/
Active Contributor
dr5156
Posts: 32
Registered: ‎12-08-2010
Message 5 of 11 (393 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-06-2012 11:25 PM in reply to: Robert_Fritz

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
Mentor
Robert_Fritz
Posts: 165
Registered: ‎12-08-2011
Message 6 of 11 (388 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-07-2012 12:01 AM 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/
Active Contributor
dr5156
Posts: 32
Registered: ‎12-08-2010
Message 7 of 11 (384 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-07-2012 12:33 AM in reply to: Robert_Fritz

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
Mentor
Robert_Fritz
Posts: 165
Registered: ‎12-08-2011
Message 8 of 11 (381 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-07-2012 01:01 AM 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/
Active Contributor
dr5156
Posts: 32
Registered: ‎12-08-2010
Message 9 of 11 (376 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-07-2012 01:26 AM in reply to: Robert_Fritz

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
Mentor
Robert_Fritz
Posts: 165
Registered: ‎12-08-2011
Message 10 of 11 (371 Views)

Re: turn ON or OFF fdo layer using AutoCAD .net

11-07-2012 03:59 AM 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/
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.