///////////////////////////////////////////////////////////// // Use: Ok Button clicked Handler // ///////////////////////////////////////////////////////////// private void bOk_Click(object sender, EventArgs e) { bool silentOp = _Application.SilentOperation; _Application.SilentOperation = true; PartDocument template = _Application.Documents.Open( _ThreadTemplatePath, false) as PartDocument; _Application.SilentOperation = silentOp; if (!ValidateTemplateParameters(template)) { DialogResult res = MessageBox.Show( "Missing sketch parameter in template file!", "Invalid Template", MessageBoxButtons.OK, MessageBoxIcon.Error); bOk.Enabled = false; _ThreadTemplatePath = string.Empty; tbTemplate.Text = string.Empty; if (template != _Application.ActiveDocument) { template.Close(true); } return; } List <ThreadFeature> threads = new List <ThreadFeature>(); foreach (System.Object selectedObj in _InteractionManager.SelectedEntities) { ThreadFeature thread = selectedObj as ThreadFeature; if (thread.Suppressed) { continue; } threads.Add(thread); } PlanarSketch templateSketch = template.ComponentDefinition.Sketches[1]; if (!ThreadWorker.ModelizeThreads( _Document, templateSketch, threads, _extraPitch)) { DialogResult res = MessageBox.Show( "Failed to create CoilFeature... " + "Try with a bigger Pitch Offset value", "Modelization Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); switch (res) { case DialogResult.OK: //template.Close(true); return; default: break; } } // Problem: closing the template doc here // will empty the undo stack (as designed)... //template.Close(true); if (!_cleaned) { CleanUp(); } _InteractionManager.Terminate(); }