private void OnEnableCommand(ExportCommands_e cmd, ref CommandItemEnableState_e state) { //state is already calculated based on swWorkspaceTypes_e value specified for the //command (i.e. in this case if the active model is no an assembly the state of the button will be //DeselectDisable. So we only need to verify if the state is DeselectEnable if (state == CommandItemEnableState_e.DeselectEnable) { if (App.IActiveDoc2.ISelectionManager.GetSelectedObjectsComponent4(1, -1) == null) { //if no components selected deselect and disable the command state = CommandItemEnableState_e.DeselectDisable; } } }
private void OnCommand(ExportCommands_e cmd) { var ext = ""; switch (cmd) { case ExportCommands_e.Parasolid: ext = ".x_t"; break; case ExportCommands_e.Iges: ext = ".igs"; break; case ExportCommands_e.Step: ext = ".step"; break; default: throw new NotSupportedException(); } var comp = App.IActiveDoc2.ISelectionManager.GetSelectedObjectsComponent4(1, -1) as IComponent2; if (comp != null) { var filePath = Path.Combine( Path.GetDirectoryName(App.IActiveDoc2.GetPathName()), "Export", Path.GetFileNameWithoutExtension(comp.GetPathName()) + ext); comp.Export(filePath); } else { Debug.Assert(false, "Command should be disabled"); throw new NullReferenceException("Component"); } }