OpenRoads Designer CONNECT Edition SDK Help

Connect to other DGN file

In a current dgn, if user wants to read/write data to/from other file, user must explicitly make a Connection to that DGN file. The below code snippet shows how to connect to other dgn file from current dgn.

Example

           
 //save the current dgn changes 
newDGNFile.ProcessChanges(DgnSaveReason.FileClose);
//close instance of active dgn
owner.Dispose();

//create DgnDocument from other file path 
Bentley.DgnPlatformNET.DgnFile OtherDGNFile;
String OtherDGNPath = "D:\\Dgn\\OtherDgn.dgn";
Bentley.DgnPlatformNET.DgnDocument dgnDocumentObj = DgnDocument.CreateForLocalFile(OtherDGNPath);

//create file owner  
Bentley.DgnPlatformNET.DgnFileOwner DgnFileOwnerObj = DgnFile.Create(dgnDocumentObj, DgnFileOpenMode.ReadOnly);
OtherDGNFile = DgnFileOwnerObj.DgnFile;

StatusInt openForReadStatus;
Bentley.DgnPlatformNET.DgnFileStatus FileStatus;

//Load the dgn file into current session
if (DgnFileStatus.Success != (FileStatus = OtherDGNFile.LoadDgnFile(out openForReadStatus)))
    return false;

return true;

Continuing in the above code of creating new dgn, to connect to any other DGN file which exists on disk, first save the current file changes (if any) using ProcessChanges(), and Dispose() to close the instance of active dgn file.

Create a DgnDocument for the other file, create owner and load the other dgn. The file "OtherDgn.dgn" in code is accessed in Read only mode. To open it in Read and Write mode change the argument DgnFileOpenMode.ReadOnly of Create() to DgnFileOpenMode.ReadWrite