MicroStation V8 DGN files contain one or more models. When you open a DGN file, the default model is also opened. You may want to open a DGN file as read-only, or perhaps open a specific model rather than the default model.

Open DGN File Read-Only

Q

A The MDL function to open a DGN file is mdlSystem_newDesignFile (char const* fileName). There is no parameter that lets you specify read-only open.

The absence of a read-only option is puzzling, particular since VBA does provide that option with the OpenDesignFile method.

The solution, for versions of MicroStation to V8i, is the global mgds_modes struct. One member of that struct is always_read_only. If you set that flag prior to using mdlSystem_newDesignFile, then your DGN file will open read-only and your user will not see the annoying modal dialog.

I suspect that the MicroStationAPI may provide a better solution for C++ (see the ISessionMgr interface), but for now, here's a C++ class that helps set that global variable automatically …

//////////////////////////////////////////////////////////////////////
//	Class restores state of mgds_modes.always_read_only flag if
//	our code has changed it
class CMgdsMode
{
	const int		always_read_only_;
public:
	//	Constructor saves the state of always_read_only flag
	CMgdsMode	(bool	readOnly	= false) : always_read_only_ (mgds_modes.always_read_only)
	{
		//	Set the state of always_read_only as we want
		mgds_modes.always_read_only	= readOnly? 1: 0;
	}
	//	Destructor restores the state of always_read_only flag
	~CMgdsMode	()
	{
		mgds_modes.always_read_only	= always_read_only_;
	}

	bool		ReadOnly	()	const	{ return 0 != always_read_only_;	}
};

Here's an example usage, where you want to iterate a number of files and avoid the modal prompt dialog if any of them is read-only …

// Usage: set read-only flag before iterating a number of files
{
	CMgdsMode mgds (true);
	for (i = 0; i < nFiles; ++i)
	{
		mdlSystem_newDesignFile (files [i]);
	}
   //	CMgdsMode destructor restores state as the variable goes out-of-scope
}

Return to MDL articles index.


Open DGN File and a Specific Model

Q

A The MDL function to open a DGN file is mdlSystem_newDesignFile (char const* fileName). There is no parameter that lets you specify a model name. It opens the DGN file and actives the default model, whatever that may be.

To open a DGN file and specify a model, use mdlSystem_newDesignFileAndModel (char const* fileName, MSWChar const* modelName). Note that the file path is a char* and the model name is a MSWChar* – they are different types.

Return to MDL articles index.