Hi, here is a very stripped down code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Inventor;
using System.Reflection;
namespace SampleSelection
{
class Action
{
private InteractionEvents m_interactionEvents;
private SelectEvents m_selectEvents;
private SelectEventsSink_OnSelectEventHandler m_Select_OnSelect_Delegate;
private InteractionEventsSink_OnTerminateEventHandler m_interaction_OnTerminate_Delegate;
private MouseEvents m_mouseEvents;
Inventor.Application m_application;
bool finished;
public Action(Inventor.Application _invApp)
{
try
{
finished = false;
m_application = _invApp;
m_application.Documents.Open(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)+"\\20220622-02.ipt", true);
m_interactionEvents = m_application.CommandManager.CreateInteractionEvents();
m_interactionEvents.SelectionActive = true;
m_interactionEvents.StatusBarText = "Select a sketch profile";
m_interactionEvents.SetCursor(CursorTypeEnum.kCursorBuiltInCrosshair, null, null);
m_selectEvents = m_interactionEvents.SelectEvents;
m_selectEvents.ClearSelectionFilter();
m_selectEvents.ResetSelections();
m_selectEvents.AddSelectionFilter(SelectionFilterEnum.kSketchProfileFilter);
m_selectEvents.SingleSelectEnabled = true;
m_Select_OnSelect_Delegate = new SelectEventsSink_OnSelectEventHandler(SelectEvents_OnSelect);
m_selectEvents.OnSelect += m_Select_OnSelect_Delegate;
m_interaction_OnTerminate_Delegate = new InteractionEventsSink_OnTerminateEventHandler(InteractionEvents_OnTerminate);
m_interactionEvents.OnTerminate += m_interaction_OnTerminate_Delegate;
m_interactionEvents.Start();
while(finished == false)
{
}
}
catch(Exception ex)
{
String innerMessage = ex.Message;
}
}
private void MouseEvents_OnMouseClick(MouseButtonEnum Button, ShiftStateEnum ShiftKeys, Point ModelPosition, Point2d ViewPosition, View View)
{
return;
}
private void SelectEvents_OnSelect(ObjectsEnumerator JustSelectedEntities, SelectionDeviceEnum SelectionDevice, Point ModelPosition, Point2d ViewPosition, View View)
{
if(JustSelectedEntities.Count>0)
{
PartDocument pDoc = (PartDocument)m_application.ActiveDocument;
BoundaryPatchDefinition bPatchDef = pDoc.ComponentDefinition.Features.BoundaryPatchFeatures.CreateBoundaryPatchDefinition();
bPatchDef.BoundaryPatchLoops.Add(JustSelectedEntities[1]);
pDoc.ComponentDefinition.Features.BoundaryPatchFeatures.Add(bPatchDef);
//m_interactionEvents.OnTerminate -= m_interaction_OnTerminate_Delegate;
finished = true;
// m_interactionEvents.Stop();
// m_interactionEvents = null;
}
}
private void InteractionEvents_OnTerminate()
{
throw new NotImplementedException();
}
}
}
If you execute this, it will create a boundary patch based on the input profile. You can also double click the boundary patch and see the referred profile. Once you close and reopen the ipt, the reference to the profile is gone .