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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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