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: 

Get and Set AcMapLayer order using Map 3D Platform API

13 REPLIES 13
Reply
Message 1 of 14
Anonymous
1150 Views, 13 Replies

Get and Set AcMapLayer order using Map 3D Platform API

Anonymous
Not applicable

Hi all,

I am new to this Auto CAD Map 3D Can anyone help me in the below issue.


Issue: I have 50 layers in my Draw order section and the changed the prioiry of the layers which should appear at the top in the map and lower in the map.

I was unable to write a code in c# to SAVE this changed priority in the draw order panel. Can anyone help me in this.

Thanks a lot.. In Advance. This would help me a lot.

0 Likes

Get and Set AcMapLayer order using Map 3D Platform API

Hi all,

I am new to this Auto CAD Map 3D Can anyone help me in the below issue.


Issue: I have 50 layers in my Draw order section and the changed the prioiry of the layers which should appear at the top in the map and lower in the map.

I was unable to write a code in c# to SAVE this changed priority in the draw order panel. Can anyone help me in this.

Thanks a lot.. In Advance. This would help me a lot.

13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi,

 

isn't the draw order "saved" when then drawing is saved?

Or do you mean something else?

 

Rob

 

 

0 Likes

Hi,

 

isn't the draw order "saved" when then drawing is saved?

Or do you mean something else?

 

Rob

 

 

Message 3 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi Robert,

 

In the attched pic, The Draw order panel consists of some layers After Loading the displaying model. Now I made change in the prioity of the Layers in Draw order section.

 

 

This change in the order for the layers, in the Draw order section is to be saved from my c# code.Which I failed to do that?

 

Please let me know if i can provide more info.

0 Likes

Hi Robert,

 

In the attched pic, The Draw order panel consists of some layers After Loading the displaying model. Now I made change in the prioity of the Layers in Draw order section.

 

 

This change in the order for the layers, in the Draw order section is to be saved from my c# code.Which I failed to do that?

 

Please let me know if i can provide more info.

Message 4 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi,

 

do you use GenerateGraphics / IndustryModel or what do you mean by "After Loading the displaying model"?

If so - then the display model needs to be saved back to disk. But I'm not sure whether you use plain Map or an IndustryModel. Let me know,

 

Rob

0 Likes

Hi,

 

do you use GenerateGraphics / IndustryModel or what do you mean by "After Loading the displaying model"?

If so - then the display model needs to be saved back to disk. But I'm not sure whether you use plain Map or an IndustryModel. Let me know,

 

Rob

Message 5 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Yes Robert. We use GenerateGraphics for loading Display Model.

 

I am saving the Display model too.. but in the saved display Model , in TBDMMAP file the DisplayModelMapLayer order which i changed(in Draw Order) is not geeting reflected and all other changes like layer symbol change and layer visibility are getting saved with my code.

 

 

But when i test this without my project .Then everything is working fine

0 Likes

Yes Robert. We use GenerateGraphics for loading Display Model.

 

I am saving the Display model too.. but in the saved display Model , in TBDMMAP file the DisplayModelMapLayer order which i changed(in Draw Order) is not geeting reflected and all other changes like layer symbol change and layer visibility are getting saved with my code.

 

 

But when i test this without my project .Then everything is working fine

Message 6 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi,

 

I had a quick look at the API docs and it seems that IM API has additional functionailty for changing layer draw order. Not sure if this is an optional or required addition:

 

IDisplayModelMap..::..MoveLayer Method - Moves a layer within the draw order to the specified index. 

 

There is also an event :

 

IGraphicsGenerator..::..DisplayModelModified Event The Display Model was modified in the Display Manager. Possible sources: - Layer stylization modified - Layer added via "Data Connect" - Layer added via "Load Layer" - Layer added via "Drag and Drop" - Layer copy and pasted - Layer removed - Draw order of layers changed* - Grouping of layers changed* * Not available through GWS events.

 

Maybe the change in Map's DisplayManager has no direct impact on IM display model (tbdmmap) and therefore IM display model needs to be modified as well before saving it back?

Just guessing, sorry, didn't find any code sample...

 

Good luck, Rob

 

0 Likes

Hi,

 

I had a quick look at the API docs and it seems that IM API has additional functionailty for changing layer draw order. Not sure if this is an optional or required addition:

 

IDisplayModelMap..::..MoveLayer Method - Moves a layer within the draw order to the specified index. 

 

There is also an event :

 

IGraphicsGenerator..::..DisplayModelModified Event The Display Model was modified in the Display Manager. Possible sources: - Layer stylization modified - Layer added via "Data Connect" - Layer added via "Load Layer" - Layer added via "Drag and Drop" - Layer copy and pasted - Layer removed - Draw order of layers changed* - Grouping of layers changed* * Not available through GWS events.

 

Maybe the change in Map's DisplayManager has no direct impact on IM display model (tbdmmap) and therefore IM display model needs to be modified as well before saving it back?

Just guessing, sorry, didn't find any code sample...

 

Good luck, Rob

 

Message 7 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

not related to my previous posting - but you could also try to use SaveAs instead of Save - for testing purpose, any difference?

0 Likes

not related to my previous posting - but you could also try to use SaveAs instead of Save - for testing purpose, any difference?

Message 8 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

No Difference as per my understanding..

 

 

Thanks a lot for your valuable responses.

 

here the issue is Autodesk Map3d Save as or save DisplayModel layer as functionalities Are worrking fine...

 

 

I need to implement the same functionality in my code as per my req. Everything is working except this draw order issue. So i am looking to handle this.

 

which I was failing..

 

So Still trying to get the sample code..

0 Likes

No Difference as per my understanding..

 

 

Thanks a lot for your valuable responses.

 

here the issue is Autodesk Map3d Save as or save DisplayModel layer as functionalities Are worrking fine...

 

 

I need to implement the same functionality in my code as per my req. Everything is working except this draw order issue. So i am looking to handle this.

 

which I was failing..

 

So Still trying to get the sample code..

Message 9 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi,

 

so I did a quick test and it seems to be as I thought. Changing draw order in Map Display Manager does not automatically reflects in IM DisplayModel layer draw order. See sampel code below - if you change draw order in DisplayManager the draw order <index> value for display model as shown in MessageBox has not changed. But you can move layer accordingly in IM DisplayMap.

 

Autodesk.Map.IM.Display.GraphicsGeneration.IGraphicsGenerator gg = Autodesk.Map.IM.Display.GraphicsGeneration.GraphicsGeneratorFactory.Instance;

Autodesk.Map.IM.Display.DisplayModelManagement.IDisplayModel dm = gg.DisplayModel;

this.Application.MessageBox(dm.FileName);

 

//if you have more than one map in your DisplayModel....

Autodesk.Map.IM.Display.DisplayModelManagement.IDisplayModelMap dmMap = dm.Maps[0];

 

 

foreach (IDisplayModelMapLayer dmMapLayer in dmMap.Layers)

{

this.Application.MessageBox(dmMapLayer.NodeName+ " "+ dmMap.Layers.IndexOf(dmMapLayer).ToString());

 

}

 

 

 

Good luck, Rob

 

 

0 Likes

Hi,

 

so I did a quick test and it seems to be as I thought. Changing draw order in Map Display Manager does not automatically reflects in IM DisplayModel layer draw order. See sampel code below - if you change draw order in DisplayManager the draw order <index> value for display model as shown in MessageBox has not changed. But you can move layer accordingly in IM DisplayMap.

 

Autodesk.Map.IM.Display.GraphicsGeneration.IGraphicsGenerator gg = Autodesk.Map.IM.Display.GraphicsGeneration.GraphicsGeneratorFactory.Instance;

Autodesk.Map.IM.Display.DisplayModelManagement.IDisplayModel dm = gg.DisplayModel;

this.Application.MessageBox(dm.FileName);

 

//if you have more than one map in your DisplayModel....

Autodesk.Map.IM.Display.DisplayModelManagement.IDisplayModelMap dmMap = dm.Maps[0];

 

 

foreach (IDisplayModelMapLayer dmMapLayer in dmMap.Layers)

{

this.Application.MessageBox(dmMapLayer.NodeName+ " "+ dmMap.Layers.IndexOf(dmMapLayer).ToString());

 

}

 

 

 

Good luck, Rob

 

 

Message 10 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Thanks a lot for the work.

 

 

As per the above sample code, My understading is that, new index for the moved layer in the draw order section is not getting reflected throuh IM DisplayModel MapLayer.

 

 

So if we opt for  IDisplayModelMap.Movelayer(layer,newIndex of  this layer ).

 

Here how could i get newIndex by the code. if I get this index i think then the problem will be solved completely.

 

 Please correct me if my understaing is wrong. Thanks in Advance.

0 Likes

Thanks a lot for the work.

 

 

As per the above sample code, My understading is that, new index for the moved layer in the draw order section is not getting reflected throuh IM DisplayModel MapLayer.

 

 

So if we opt for  IDisplayModelMap.Movelayer(layer,newIndex of  this layer ).

 

Here how could i get newIndex by the code. if I get this index i think then the problem will be solved completely.

 

 Please correct me if my understaing is wrong. Thanks in Advance.

Message 11 of 14
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi Robert,

 

Thanks a lot for your suggestions on this isuue. I have worked on this to some extent as per your suggestions and finally issue got resolved. 

Here is the sample code I used.

 

private Dictionary<string,IDisplayModelMapLayer> GetLayerFccolection(IDisplayModelMap pMap)
{
Dictionary<string,IDisplayModelMapLayer> dicCollection = new Dictionary<string,IDisplayModelMapLayer>();

IList<IDisplayModelMapLayer> layerCo = pMap.Layers;
IList<string> duplist = new List<string>();

foreach (IDisplayModelMapLayer layer in layerCo)
{
if (!dicCollection.ContainsKey(layer.FeatureClassName))
{
dicCollection.Add(layer.FeatureClassName, layer);
}
else
{
duplist.Add(layer.FeatureClassName);
}
}
return dicCollection;
}
/// <summary>
/// Function to get the layers from Map3D task pane and move them based on draw order
/// </summary>
/// <returns>layer Name and layer in Dictionary</returns>
private Dictionary<string, MgLayerBase> GetMapLayers()
{
Dictionary<string, MgLayerBase> dictionaryLayers = new Dictionary<string, MgLayerBase>();
try
{
AcMapMap acMapMapCurrent = AcMapMap.GetCurrentMap();
IDisplayModelMap pMap = loadedDisplayModel.Maps[0];
Dictionary<string, IDisplayModelMapLayer> layerCo = GetLayerFccolection(pMap);

MgLayerCollection mgLayerCollection = acMapMapCurrent.GetLayers();
for (int k = 0; k < mgLayerCollection.Count; k++)
{

MgLayerBase mgLayerBase = mgLayerCollection.GetItem(k);

string[] layerArray = mgLayerBase.FeatureClassName.Split(':');
if (layerArray.Length > 1)
{
string layer = layerArray[1];
if (layerCo.ContainsKey(layer))
{
IDisplayModelMapLayer mapLayer = layerCo[layer];
pMap.MoveLayer(mapLayer, k);
}

if (!dictionaryLayers.ContainsKey(mgLayerBase.LayerDefinition.Name))
{
dictionaryLayers.Add(mgLayerBase.LayerDefinition.Name, mgLayerBase);
}
}
}
}
catch (Exception)
{
throw;
}
return dictionaryLayers;
}

 

 

 

Once Again Thanks a lot..  

 

 

 

 

 

 

 

 

 

 

0 Likes

Hi Robert,

 

Thanks a lot for your suggestions on this isuue. I have worked on this to some extent as per your suggestions and finally issue got resolved. 

Here is the sample code I used.

 

private Dictionary<string,IDisplayModelMapLayer> GetLayerFccolection(IDisplayModelMap pMap)
{
Dictionary<string,IDisplayModelMapLayer> dicCollection = new Dictionary<string,IDisplayModelMapLayer>();

IList<IDisplayModelMapLayer> layerCo = pMap.Layers;
IList<string> duplist = new List<string>();

foreach (IDisplayModelMapLayer layer in layerCo)
{
if (!dicCollection.ContainsKey(layer.FeatureClassName))
{
dicCollection.Add(layer.FeatureClassName, layer);
}
else
{
duplist.Add(layer.FeatureClassName);
}
}
return dicCollection;
}
/// <summary>
/// Function to get the layers from Map3D task pane and move them based on draw order
/// </summary>
/// <returns>layer Name and layer in Dictionary</returns>
private Dictionary<string, MgLayerBase> GetMapLayers()
{
Dictionary<string, MgLayerBase> dictionaryLayers = new Dictionary<string, MgLayerBase>();
try
{
AcMapMap acMapMapCurrent = AcMapMap.GetCurrentMap();
IDisplayModelMap pMap = loadedDisplayModel.Maps[0];
Dictionary<string, IDisplayModelMapLayer> layerCo = GetLayerFccolection(pMap);

MgLayerCollection mgLayerCollection = acMapMapCurrent.GetLayers();
for (int k = 0; k < mgLayerCollection.Count; k++)
{

MgLayerBase mgLayerBase = mgLayerCollection.GetItem(k);

string[] layerArray = mgLayerBase.FeatureClassName.Split(':');
if (layerArray.Length > 1)
{
string layer = layerArray[1];
if (layerCo.ContainsKey(layer))
{
IDisplayModelMapLayer mapLayer = layerCo[layer];
pMap.MoveLayer(mapLayer, k);
}

if (!dictionaryLayers.ContainsKey(mgLayerBase.LayerDefinition.Name))
{
dictionaryLayers.Add(mgLayerBase.LayerDefinition.Name, mgLayerBase);
}
}
}
}
catch (Exception)
{
throw;
}
return dictionaryLayers;
}

 

 

 

Once Again Thanks a lot..  

 

 

 

 

 

 

 

 

 

 

Message 12 of 14
jan_tappenbeck
in reply to: Anonymous

jan_tappenbeck
Collaborator
Collaborator

hi !

 

i want to use the code of the posting before.

 

by the call of loadedDisplayModel.Maps(0) i get a message that loadedDisplayModel is not declare!

 

could someone help me?

 

regards Jan

 

0 Likes

hi !

 

i want to use the code of the posting before.

 

by the call of loadedDisplayModel.Maps(0) i get a message that loadedDisplayModel is not declare!

 

could someone help me?

 

regards Jan

 

Message 13 of 14
Anonymous
in reply to: jan_tappenbeck

Anonymous
Not applicable

Hi Jan,

 

look at my code snippet above. You need to get the IDisplayModel first and from that you will be able to get the map.

 

By the way - it would be better to open a new discussion and not to extend a old discussion with a new question,

 

Rob

 

0 Likes

Hi Jan,

 

look at my code snippet above. You need to get the IDisplayModel first and from that you will be able to get the map.

 

By the way - it would be better to open a new discussion and not to extend a old discussion with a new question,

 

Rob

 

Message 14 of 14
jan_tappenbeck
in reply to: Anonymous

jan_tappenbeck
Collaborator
Collaborator

new posting for my question look at: https://forums.autodesk.com/t5/forums/postpage/board-id/84

 

Jan

0 Likes

new posting for my question look at: https://forums.autodesk.com/t5/forums/postpage/board-id/84

 

Jan

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

Post to forums  

Autodesk Design & Make Report