private static void AddCoincidentMate(ModelDoc2 model, IBody2 body, IEntity mateEnt, IEntity mateEntOnBody) { var selData = model.ISelectionManager.CreateSelectData(); selData.Mark = 1; if (!body.Select2(false, selData)) { throw new InvalidOperationException("Failed to select body"); } var moveCopyBodyFeat = model.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 1); var featData = moveCopyBodyFeat.GetDefinition() as IMoveCopyBodyFeatureData; if (featData.AccessSelections(model, null)) { int err; var mate = featData.AddMate(new DispatchWrapper[] { new DispatchWrapper(mateEnt), new DispatchWrapper(mateEntOnBody) }, (int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignCLOSEST, 0, 0, out err); if (mate == null) { throw new NullReferenceException(string.Format("Failed to add mate: {0}", (swAddMateError_e)err)); } if (!moveCopyBodyFeat.ModifyDefinition(featData, model, null)) { throw new InvalidOperationException("Failed to apply feature changes"); } } else { throw new InvalidOperationException("Failed to access the definition"); } }