Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Interactively selected profiles in .NET API not persistent

gilsdorf_e
Collaborator
Collaborator

Interactively selected profiles in .NET API not persistent

gilsdorf_e
Collaborator
Collaborator

Hi,

I'm struggling with 2D profiles. I want to have the user select a sketched profile interactively of which a BoundaryPatchFeature is created. Everything works well, except that the user selected profile does not seem to be persistent.

When you save, close and re-open the part document, the BoundaryPatch looks ok. But if you edit it, you can see that it lost the profile as boundary loop input. The selection is just empty. Strange enough, the parent planar sketch is still listed as dependency below the BoundaryPatch.

There must be a solution, as the same workflow done manually with native UI command works perfectly fine.

 

0 Likes
Reply
Accepted solutions (1)
324 Views
2 Replies
Replies (2)

Michael.Navara
Advisor
Advisor
Accepted solution

Can you share some code fragment for test? My simple solution with dataset is attached.

gilsdorf_e
Collaborator
Collaborator

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 .

0 Likes