Inventor 2025 API - How to use AddBySilhouette() to add a Face to a Planar Sketch if they are not on the same plane

Inventor 2025 API - How to use AddBySilhouette() to add a Face to a Planar Sketch if they are not on the same plane

rwemmerLHAEW
Participant Participant
163 Views
1 Reply
Message 1 of 2

Inventor 2025 API - How to use AddBySilhouette() to add a Face to a Planar Sketch if they are not on the same plane

rwemmerLHAEW
Participant
Participant

I have some code where I am trying to add a Face (or Edge) to a Sketch. I keep getting errors and I believe the issue is that they are not on the same plane and I think I need to do some sort of projection to make this occur. 

 

Also, I hope you will forgive me because my code is in C#

 

public void ProjectHoleFaceToSketch(PlanarSketch sketch, Face face)
        {
            if (sketch == null || face == null)
                throw new ArgumentNullException("Sketch or face is null.");

            try
            {
                var failed = false;
                try
                {
                    // this does not work.
                    var faceVertices = face.Vertices;
                    var proximityPoint = faceVertices[1].Point; // Use any vertex as a starting point
                    sketch.AddBySilhouette(face, proximityPoint);

                }
                catch (Exception ex)
                {
                    failed = true;
                    _logger.LogError(ex, "Failed to project face onto sketch.");
                }

                if (failed == true)
                {
                    try
                    {
                        //this also does not work
                        var plane = sketch.PlanarEntity as Plane;
                        double[] rootPoint = new double[3];
                        double[] normal = new double[3];
                        plane.GetPlaneData(ref rootPoint, ref normal);

                        var proximityPoint = _application.TransientGeometry.CreatePoint(rootPoint[0], rootPoint[1], rootPoint[2]);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, "Failed to project face onto sketch.");
                    }
                }
                
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "[SketchService][ProjectHoleFaceToSketch] Failed to project edges onto sketch.");
            }

        }

This results in the following error:

 

The parameter is incorrect. (0x80070057 (E_INVALIDARG))
System.ArgumentException: The parameter is incorrect. (0x80070057 (E_INVALIDARG))
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Object[] aArgs, Boolean[] aArgsIsByRef, Int32[] aArgsWrapperTypes, Type[] aArgsTypes, Type retType)
   at Inventor.PlanarSketch.AddBySilhouette(Face Face, Point ProximityPoint)
   at TeakIsleInventor.AddIn.Services.Inventor.SketchService.ProjectHoleFaceToSketch(PlanarSketch sketch, Face face) in c:\...\\Inventor\SketchService.cs:line 692

 

0 Likes
164 Views
1 Reply
Reply (1)
Message 2 of 2

C_Haines_ENG
Collaborator
Collaborator

I believe you can't directly project a face, and you must cycle through each edge of that face and project them separately. I don't code in C# but maybe you can get the idea from this iLogic code:

Dim oDoc As PartDocument = ThisDoc.Document

Dim oSketch As Sketch = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchObjectFilter, "Select Sketch")
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Face")

For Each oEdge As Edge In oFace.Edges
	
	oSketch.AddByProjectingEntity(oEdge)
	
Next
0 Likes