Issues with Add-ins using ControlDefinitions in C#

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've run into an issue trying to get my add-in to execute inventor commands via ControlDefinitions and was wandering if anyone else has run into this and figure out how to make this work (in C#). I'm using user interactions to have the user select a face then export the selected face to a .DWG file via the GeomToDXFCommand (all I need are plines describing the edge of the selected face).
Here's the OnExecute portion of the StandardAddInServer.cs file:
void CreateDwgButtonDef_OnExecute(NameValueMap Context)
{
Die DieCreation = new Die(m_inventorApplication);
}
Here's the basic area of the class in question
public class Die
{
#region Class Variable Declaration
private bool bStillSelecting;
private Inventor.Application inventorApp;
private Edge xAxis;
private Face dieProfile;
private PartDocument partDoc;
private SelectEvents selectEvents;
private InteractionEvents interaction;
#endregion
public Die(Inventor.Application app)
{
#region Variable Declarations
inventorApp = app;
partDoc = (PartDocument)inventorApp.ActiveDocument;
ControlDefinition controlDef;
CommandManager commandManager = inventorApp.CommandManager;
#endregion
#region Setup event handlers for user interaction
interaction = commandManager.CreateInteractionEvents();
interaction.SelectEvents.OnSelect += new SelectEventsSink_OnSelectEventHandler(SelectEvents_OnSelect);
selectEvents = interaction.SelectEvents;
#endregion
#region Select Extrusion Face and X-Axis
// Note, that the event handler takes care of assigning the selected entities to the
// correct object (dieProfile or xAxis).
UserSelect("Select surface describing the extrusion", SelectionFilterEnum.kPartFacePlanarFilter);
UserSelect("Select X-Axis for Die Properties", SelectionFilterEnum.kPartEdgeLinearFilter);
#endregion
#region Die Export
// Export the Die Profile to a user specified file
partDoc.SelectSet.Clear();
partDoc.SelectSet.Select(dieProfile);
controlDef = commandManager.ControlDefinitions["GeomToDXFCommand"];
controlDef.Execute();
#endregion
}
void SelectEvents_OnSelect(ObjectsEnumerator JustSelectedEntities, SelectionDeviceEnum SelectionDevice, Point ModelPosition, Point2d ViewPosition, Inventor.View View)
{
// check to see if the entity select is a face or an edge
if ((JustSelectedEntities[1] as Face) != null)
dieProfile = (Face)JustSelectedEntities[1];
else
xAxis = (Edge)JustSelectedEntities[1];
bStillSelecting = false;
}
void UserSelect(string statusBar, SelectionFilterEnum filter)
{
// setup Inventors status bar
interaction.StatusBarText = statusBar;
// Setup the selection filter based on the passed filter
selectEvents.ClearSelectionFilter();
selectEvents.ResetSelections();
selectEvents.AddSelectionFilter(filter);
selectEvents.SingleSelectEnabled = true;
bStillSelecting = true;
interaction.Start();
//loop until the user selects an entity
while (bStillSelecting)
System.Windows.Forms.Application.DoEvents();
interaction.Stop();
}
}
The problem occurs within the Die Export Region of the code. I've set the Control Definition to the GeomToDXFCommand but nothing happens (no export occurs). If I run the above code as part of a stand alone application (not as an add-in) that hooks into an existing instance of inventor using the below code I don't have any issues (everything works perfect).
Inventor.Application inventorApp = null;
try
{
// Attempt to get a reference to a running instance of Inventor.
inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
}
catch
{
return;
}
Die dieData = new Die(inventorApp);
The REALLY weird part is I was worried that maybe the entity being pre-selected was an incorrect entitiy type (saw something similar to this on another post). So, I did something to confirm I was having problems with the ControlDefinition and not the entity selected. I inserted the following piece of code into my app and still absolutely nothing.
controlDef = commandManager.ControlDefinitions[""PartNew3DSketchCmd""];
controlDef.Execute();
Since the PartNew3DSketchCmd doesn't take any preselected entities or have any user interaction to create the sketch it should have created a new 3D Sketch in the active part file. Since nothing happened I'm pretty sure I was able to isolate my problem to how I'm using ControlDefinitions (or at least I hope it's how I'm setting them up and that they aren't bugged for Add-ins when using C#).
Any Ideas?
Alan