Skip to main content

Split and merge project files

To split or merge a project file, use the methods of the IProjectUnitManager object. The IProjectUnitManager object can be obtained using the UnitManager property of the IProject object.

Caution

When you perform split and merge, the changes are saved. Be sure to check the changes before splitting and merging.

Split project files

To split model units from a project file, use the SplitModelUnits method of the IProjectUnitManager object.

public void SplitModelUnits(ICommandContext c, ICommandParams p) 
{
//Get the model selected in the current navigator
var currentNavigator = c.App.Window.EditorPage.CurrentNavigator;
var targetModels = currentNavigator.SelectedItems.OfType<IModel>();

//Split the retrieved model into model units
IProjectUnitManager unitManager = c.App.Workspace.CurrentProject.UnitManager;
unitManager.SplitModelUnits(targetModels);<br/>
}

To specify the file name of the model unit when splitting, use the SplitModelUnit method of the IProjectUnitManager object.

public void SplitModelUnit(ICommandContext c, ICommandParams p) 
{
//Get the current model selected in the model navigator
var targetModel = c.App.Workspace.CurrentModel;

//Split the retrieved model into model units
IProjectUnitManager unitManager = c.App.Workspace.CurrentProject.UnitManager;

//Determine the unit file name
//Here, as an example, we will create an abbreviated file name if the file name is longer than 8 characters
//You can also specify any file name, such as including the owning model name in the file name
var unitName = targetModel.Name;
if (unitName.Length > 8)
{
unitName = $"{unitName.Substring(0, 7)}_";
}

//Specify the unit file name and split it
unitManager.SplitModelUnit(targetModel, unitName);<br/>
}
Note

When specifying a unit file name, make sure it is unique within the project.

Integrating project files

To integrate model units into a project file, use the UnifyModelUnits method of the IProjectUnitManager object.

public void UnifyModelUnits(ICommandContext c, ICommandParams p) 
{
//Get the models selected in the current navigator
var currentNavigator = c.App.Window.EditorPage.CurrentNavigator;
var targetModels = currentNavigator.SelectedItems.OfType<IModel>();

//Get the model units to which the retrieved models belong
IEnumerable<IModelUnit> modelUnits = targetModels.Select(model => model.ModelUnit).Distinct();

//Integrate the retrieved model units into the project file
IProjectUnitManager unitManager = c.App.Workspace.CurrentProject.UnitManager;
unitManager.UnifyModelUnits(modelUnits);<br/>
}