Reply
Solved! Go to solution

How to get the active profile?

Hey guys,

I started with the Solid Edge API 2 weeks ago and there are still some difficulties to achieve my first successes. My programming skills are based on native C and a little bit C++.

My main problem is to get the active profile.

All the examples I found show how to create a new profile, but I need the active and I was not able to get it by myself.

I searched the help, but I found nothing that really helped. I already found the examples by Jason Newell and his "Solid Edge Spy". That helped me a lot but not in this special case.

 

The situation:

I have an open part document with an already opened sketch that shows 5 lines (somewhere and not connected).

What i want to achieve is to produce a duplicate of the clicked line.

 

Can anybody please help me with this?

I attached a started project if that makes things easier.

 

Greetings,

starger.

3 REPLIES

Re: How to get the active profile?

Hi starger,
use the ActiveSketch of the ActiveDocument.
regards

JB
VS2015, SE ST10
Solution
Solution
Accepted by topic author starger
‎03-26-2017 06:18 PM

Re: How to get the active profile?

Hello Starger,

 

I'll show you an example in C # to show you the step-by-step.

 

I've highlighted the field of code you need to get the active sketch.

 

 

 class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Declare your main variables
            SolidEdgeFramework.Application seApplication = null;
            SolidEdgeFramework.Documents seDocuments = null;

            // Declare your document variables
            SolidEdgePart.PartDocument sePartDoc = null;

            // Variables and Objets for Sketchs
            SolidEdgePart.RefPlanes planesCollection = null;
            SolidEdgePart.RefPlane workPlane = null;
            SolidEdgePart.Sketchs sketchsCollection = null;
            SolidEdgePart.Sketch sketch = null;
            SolidEdgePart.Profiles profiles = null;
            SolidEdgePart.Profile workProfile = null;

            // Variable of Lines and Relationships
            SolidEdgeFrameworkSupport.Lines2d linesCollection = null;
            SolidEdgeFrameworkSupport.Relations2d relationsCollection = null;

            try
            {
                // Register
                OleMessageFilter.Register();

                // Connect your Solid Edge
                seApplication = SolidEdgeUtils.Connect(true);

                // Get your Document Collection
                seDocuments = seApplication.Documents;
                // Check for any active part document
                if (seApplication.ActiveDocumentType != DocumentTypeConstants.igPartDocument)
                {
                    // If don't have a part document active, break this code
                    return;
                }

                // Get Active Document
                sePartDoc = (PartDocument)seApplication.ActiveDocument;

                // Get time for the program
                seApplication.DoIdle();

                // Get the reference plane
                planesCollection = sePartDoc.RefPlanes;

                // Get the top plane
                workPlane = planesCollection.Item(1);

                // ---> Get the Active Sketch <---
                sketch = sePartDoc.ActiveSketch;

                // Get the profile collection
                profiles = sketch.Profiles;

                // ---> Get active profile <---
                workProfile = profiles.Item(1);

                // Get the reference of lines 2d collection
                linesCollection = workProfile.Lines2d;

                // Create three lines
                linesCollection.AddBy2Points(0, 0, 0.1, 0.1);           // Your first line, Item(1)
                linesCollection.AddBy2Points(0.1, 0.1, 0.1, 0);         // Second line, Item(2)
                linesCollection.AddBy2Points(0.1, 0, 0, 0);             // Third line, Item(3)

                // Get the reference of relationships
                relationsCollection = (Relations2d)workProfile.Relations2d;

                // Create three new connection relationships
                relationsCollection.AddKeypoint(
                    linesCollection.Item(1), 
                    (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    linesCollection.Item(2), 
                    (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                relationsCollection.AddKeypoint(
                    linesCollection.Item(2),
                    (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    linesCollection.Item(3),
                    (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                relationsCollection.AddKeypoint(
                    linesCollection.Item(3),
                    (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    linesCollection.Item(1),
                    (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                // Create two new alignment relationship, Horizontal and Vertical
                relationsCollection.AddVertical(linesCollection.Item(2));
                relationsCollection.AddHorizontal(linesCollection.Item(3));

                // End Sketch/Profile
                workProfile.End(ProfileValidationType.igProfileClosed);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                // Ungister
                OleMessageFilter.Unregister();
            }
        }
    }

 

To copy a line, you can get points X1, Y1 and X2, Y2 and create a new one based on these positions.

 

To get these points by click, use the SelectSet class.

 

If you are interested in learning more about Solid Edge API in C #, link below:

 

https://www.youtube.com/playlist?list=PLZyAyG4_KmYk8nYLT9k9M2ttKL7JQ0nTF

 

Have a nice day.



==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com

Re: How to get the active profile?

Thank you guys. That really helped me.