[C# Connect U4 DgnPlatformNet] Setting Per-View Level Display

I see the ViewInformation class contains a GetLevelDisplay method, but there is no way for me to set the level display for that view..

I have one level that I need to make sure is always displayed and cannot figure out how to do that. :)

Any help would be great!

Parents
  • Hello Maury,

    did you find a solution for this problem?

    Regards Martin

  • Hi Martin,

    It has been a while, but what I ended up doing was checking if the level was displayed in all views using

    ViewInformation.GetEffectiveLevelDisplay

    If it returned false, I reset the level mask using

    ViewGroupCollection viewGroupCollection = Ms.GetActiveDgnFile().GetViewGroups();
    ViewGroup viewGroup = viewGroupCollection.GetActive();

    viewGroup.ResetEffectiveLevelMasks();

  • Hi Maury,

    I'm trying to achieve something like what you were trying to do - ensure in certain operations a certain set of levels in a particular dgnfile are displayed.

    I looked at the ResetEffectiveLevelMasks() and when I ran this method it always turned the level display off all the levels that had element usage plus a couple of other levels consistently each time I ran it.

    I figure I've missed something somewhere.  Do you have any further suggestions about how to do it?

    It would be much appreciated.

    Perhaps the disappearing mdlLevel_SetDisplay from mdl days may have resurfaced somewhere.

    Thanks for your previous suggestion. I'm still trying to work something out.

    David

  • Perhaps the disappearing mdlLevel_SetDisplay from mdl days

    MDL functions, including mdlLevel_xxx, mostly moved to the C++ MicroStationAPI.  There may be additional C++ classes that make the programmer's work easier.

    The .NET APIs often wrap the MicroStationAPI.  Sometimes, it's the other way around.  In your case, it looks like the level functionality from MDL failed to evolve a .NET wrapper.  File a Service Request with Bentley Systems.

     
    Regards, Jon Summers
    LA Solutions

  • Thanks Jon,

    I've been able to develop everything in c# so far and have been trying to avoid - a) developing using the Microstation API's either in totality or b) using a CLR wrapper (I have very little experience in this).  I guess for the moment I'll try the .NET wrapper.

    Yes I noticed the mdlLevel_SetDisplay in the APIs - slightly different but it does what I want.

    Thanks for your help and suggestion.

    David

  • Hi David,

    Unfortunately, I don't think I ever got this working properly using just the C# API.

  • Hi Jon and Maury,

    Thanks for your help. 

    I have the get level display working for both Root and  Attachment  models.  However in trying to check the set state of view levels I have a problem with the c# ViewInformation.GetLevelDisplay for DgnAttachments - it works fine for the Root model.  The problem occurs when trying to get ViewGroup from the ViewGroupCollection or in the case below the ViewInformation directly - it returns a null.  I'm wondering if there is another way to access the ViewInformation of a DgnAttachment or am I doing something wrong in passing the parameters I've used in the code below - see the GetLevels method below.

    Any help would be appreciated.

    David

    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using Bentley.DgnPlatformNET;
    using Bentley.MstnPlatformNET;
    
    namespace CodeTest
    	{
    	public static class LevelOps
    		{
    // imports
    		[DllImport("stdmdlbltin.dll")] static extern int mdlView_setLevelDisplay(IntPtr  ipDMR , int iViewNumber, int uiLevelID, bool bSet);
    // static methods
    		public static int SetLevelDisplay(DgnModel dmModOrAtt, int iViewNumber, int uiLevelID, bool bSet) 
    			{
    			return mdlView_setLevelDisplay(dmModOrAtt.GetNative() , iViewNumber, uiLevelID, bSet);
    			}
    // set levels
    		public static void SetLevels(DgnModel dmModOrAtt, int iViewNumber, bool bDisplayOnOff)
    			{
    			int			iRet;
    			LevelCache lcLevel = dmModOrAtt.GetDgnFile().GetLevelCache();
    			foreach(LevelHandle lh in lcLevel.GetHandles())
    				{
    				int iLevelID = lh.LevelId;
    				iRet = SetLevelDisplay(dmModOrAtt, iViewNumber, iLevelID, bDisplayOnOff);
    				}
    			}
    // get levels
    		public static void GetLevels(DgnModel dmModOrAtt, int iViewNumber)
    			{
    			bool bOnOff=false;
    			ViewInfoStatus visRet;
    
    			ViewInformation viViewInfo = dmModOrAtt.GetDgnFile().GetViewGroups().GetActiveViewInformation(0);
    			LevelCache lcLevel = dmModOrAtt.GetDgnFile().GetLevelCache();
    
    			foreach(LevelHandle lh in lcLevel.GetHandles())
    				{
    				int iLevelID = lh.LevelId;
    				visRet = viViewInfo.GetLevelDisplay(out bOnOff, dmModOrAtt, iLevelID);
    				}
    			}
    
    		}
    	}
    

  • The problem occurs when trying to get ViewGroup from the ViewGroupCollection ...
    ViewInformation viViewInfo = dmModOrAtt.GetDgnFile().GetViewGroups().GetActiveViewInformation(0);

    That doesn't look right.  An attachment doesn't have an active view — it's the active DGN file that has active views.

    Try enumerating the view groups, and get ViewInformation not ActiveViewInformation.

     
    Regards, Jon Summers
    LA Solutions

  • Thanks Jon,

    That really helped. You alerted me to the mistake of passing and using DgnAttachment.GetDgnModel() rather than DgnAttachment.  Once I created separated calls for these two then fixed the problem using  ViewGroups  ViewInformation for the DgnAttachment.  It also fixed other problems too!

    Thanks again,

    David.

    Corrected code below

    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using Bentley.DgnPlatformNET;
    using Bentley.MstnPlatformNET;
    
    namespace CodeTest
    	{
    	public static class LevelOps
    		{
    // imports
    		[DllImport("stdmdlbltin.dll")] static extern int mdlView_setLevelDisplay(IntPtr  ipDMR , int iViewNumber, int uiLevelID, bool bSet);
    // static methods
    		public static int SetLevelDisplay(DgnModel dmModel, int iViewNumber, int uiLevelID, bool bSet) 
    			{
    			return mdlView_setLevelDisplay(dmModel.GetNative() , iViewNumber, uiLevelID, bSet);
    			}
    		public static int SetLevelDisplay(DgnAttachment daAttach, int iViewNumber, int uiLevelID, bool bSet) 
    			{
    			return mdlView_setLevelDisplay(daAttach.GetNative() , iViewNumber, uiLevelID, bSet);
    			}
    // set levels
    		public static void SetLevels(DgnModel dmModel, int iViewNumber, bool bDisplayOnOff)
    			{
    			int			iRet;
    			LevelCache lcLevel = dmModel.GetDgnFile().GetLevelCache();
    			foreach(LevelHandle lh in lcLevel.GetHandles())
    				{
    				int iLevelID = lh.LevelId;
    				iRet = SetLevelDisplay(dmModel, iViewNumber, iLevelID, bDisplayOnOff);
    				}
    			}
    
    		public static void SetLevels(DgnAttachment daAttach, int iViewNumber, bool bDisplayOnOff)
    			{
    			int			iRet;
    			LevelCache lcLevel = daAttach.GetDgnFile().GetLevelCache();
    			foreach(LevelHandle lh in lcLevel.GetHandles())
    				{
    				int iLevelID = lh.LevelId;
    				iRet = SetLevelDisplay(daAttach, iViewNumber, iLevelID, bDisplayOnOff);
    				}
    			}
    
    // get levels
    		public static void GetLevels(DgnModel dmModel, int iViewNumber)
    			{
    			bool bOnOff=false;
    			ViewInfoStatus visRet;
    
    			ViewInformation viViewInfo = dmModel.GetDgnFile().GetViewGroups().GetActiveViewInformation(iViewNumber);
    			LevelCache lcLevel = dmModel.GetDgnFile().GetLevelCache();
    
    			foreach(LevelHandle lh in lcLevel.GetHandles())
    				{
    				int iLevelID = lh.LevelId;
    				visRet = viViewInfo.GetLevelDisplay(out bOnOff, dmModel, iLevelID);
    				}
    			}
    
    		public static void GetLevels(DgnAttachment daAttach, int iViewNumber)
    			{
    			bool bOnOff=false;
    			ViewInfoStatus visRet;
    
    			ViewGroupCollection vgr = daAttach.GetDgnFile().GetViewGroups();
    			foreach(ViewGroup vg in vgr) 
    				{
    				ViewInformation viViewInfo = vg.GetViewInformation(iViewNumber);
    				LevelCache lcLevel = daAttach.GetDgnFile().GetLevelCache();
    
    				foreach(LevelHandle lh in lcLevel.GetHandles())
    					{
    					int iLevelID = lh.LevelId;
    					visRet = viViewInfo.GetLevelDisplay(out bOnOff, daAttach, iLevelID);
    					}
    				}
    			}
    		}
    	}

Reply
  • Thanks Jon,

    That really helped. You alerted me to the mistake of passing and using DgnAttachment.GetDgnModel() rather than DgnAttachment.  Once I created separated calls for these two then fixed the problem using  ViewGroups  ViewInformation for the DgnAttachment.  It also fixed other problems too!

    Thanks again,

    David.

    Corrected code below

    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using Bentley.DgnPlatformNET;
    using Bentley.MstnPlatformNET;
    
    namespace CodeTest
    	{
    	public static class LevelOps
    		{
    // imports
    		[DllImport("stdmdlbltin.dll")] static extern int mdlView_setLevelDisplay(IntPtr  ipDMR , int iViewNumber, int uiLevelID, bool bSet);
    // static methods
    		public static int SetLevelDisplay(DgnModel dmModel, int iViewNumber, int uiLevelID, bool bSet) 
    			{
    			return mdlView_setLevelDisplay(dmModel.GetNative() , iViewNumber, uiLevelID, bSet);
    			}
    		public static int SetLevelDisplay(DgnAttachment daAttach, int iViewNumber, int uiLevelID, bool bSet) 
    			{
    			return mdlView_setLevelDisplay(daAttach.GetNative() , iViewNumber, uiLevelID, bSet);
    			}
    // set levels
    		public static void SetLevels(DgnModel dmModel, int iViewNumber, bool bDisplayOnOff)
    			{
    			int			iRet;
    			LevelCache lcLevel = dmModel.GetDgnFile().GetLevelCache();
    			foreach(LevelHandle lh in lcLevel.GetHandles())
    				{
    				int iLevelID = lh.LevelId;
    				iRet = SetLevelDisplay(dmModel, iViewNumber, iLevelID, bDisplayOnOff);
    				}
    			}
    
    		public static void SetLevels(DgnAttachment daAttach, int iViewNumber, bool bDisplayOnOff)
    			{
    			int			iRet;
    			LevelCache lcLevel = daAttach.GetDgnFile().GetLevelCache();
    			foreach(LevelHandle lh in lcLevel.GetHandles())
    				{
    				int iLevelID = lh.LevelId;
    				iRet = SetLevelDisplay(daAttach, iViewNumber, iLevelID, bDisplayOnOff);
    				}
    			}
    
    // get levels
    		public static void GetLevels(DgnModel dmModel, int iViewNumber)
    			{
    			bool bOnOff=false;
    			ViewInfoStatus visRet;
    
    			ViewInformation viViewInfo = dmModel.GetDgnFile().GetViewGroups().GetActiveViewInformation(iViewNumber);
    			LevelCache lcLevel = dmModel.GetDgnFile().GetLevelCache();
    
    			foreach(LevelHandle lh in lcLevel.GetHandles())
    				{
    				int iLevelID = lh.LevelId;
    				visRet = viViewInfo.GetLevelDisplay(out bOnOff, dmModel, iLevelID);
    				}
    			}
    
    		public static void GetLevels(DgnAttachment daAttach, int iViewNumber)
    			{
    			bool bOnOff=false;
    			ViewInfoStatus visRet;
    
    			ViewGroupCollection vgr = daAttach.GetDgnFile().GetViewGroups();
    			foreach(ViewGroup vg in vgr) 
    				{
    				ViewInformation viViewInfo = vg.GetViewInformation(iViewNumber);
    				LevelCache lcLevel = daAttach.GetDgnFile().GetLevelCache();
    
    				foreach(LevelHandle lh in lcLevel.GetHandles())
    					{
    					int iLevelID = lh.LevelId;
    					visRet = viViewInfo.GetLevelDisplay(out bOnOff, daAttach, iLevelID);
    					}
    				}
    			}
    		}
    	}

Children