Convert IntersectionCurve into a path I can find start / stop points and params

Convert IntersectionCurve into a path I can find start / stop points and params

johnPGNFG
Enthusiast Enthusiast
380 Views
4 Replies
Message 1 of 5

Convert IntersectionCurve into a path I can find start / stop points and params

johnPGNFG
Enthusiast
Enthusiast

Hi all!

 

Is there a way to treat an intersection curve similar to an edge?  For example, an edge you can use edge.Evaluator.GetParamExtents(.....) and edge.StartVertex.  I need to find these values but the only way I have found to do this is by checking the sketchEntity3d.Type in each intersection curve and then casting the sketchEntity3d to that type.  This is a problem because I can have multiple Types and I need to keep all the entities in the same list.  Below I'm only finding sketchSpline3d types.  Is there a generic type that I can make each entity?  Or is there a way to force the entity to be a spline regardless of the type? It seems like there's a way to convert the intersection curve into some kind of path that I can extract the data from.  I tried converting it to a ProfilePath3d and Path but to no prevail.  

 

Sketch3D sketch3d = oCompDef.Sketches3D.Add();
IntersectionCurves iCurves = sketch3d.IntersectionCurves;

List<SketchSpline3D> sketchSplineList = new List<SketchSpline3D>();

SketchSpline3D spline = null;

 

foreach (IntersectionCurve intersectCurve in iCurves)
   {
       foreach (SketchEntity3D sketchInt in intersectCurve.SketchEntities)
       {
           if (sketchInt.Type  == ObjectTypeEnum.kSketchSpline3DObject)
           {      

                spline = (SketchSpline3D)sketchInt;
                sketchSplineList.Add(spline);
           }
       }
  }

0 Likes
Accepted solutions (1)
381 Views
4 Replies
Replies (4)
Message 2 of 5

Michael.Navara
Advisor
Advisor

All relevant geometries (except sketchPoints and maybe something else) has oSketchEntity3D.Geometry.Evaluator property of type CurveEvaluator

From this object you can get param extents, point at param, etc.

0 Likes
Message 3 of 5

johnPGNFG
Enthusiast
Enthusiast
When I use oSketchEntity3D.Geometry.Evaluator, Geometry is not recognized and says "SketchEntity3D does not contain a definition for Geometry...". Am I missing something?
0 Likes
Message 4 of 5

Michael.Navara
Advisor
Advisor
Accepted solution

Yes, I'm sorry. You use C# instead of iLogic.

In this case you need to use "late binding" to obtain Geometry from SketchEntity3D.

Use dynamic type

 

CurveEvaluator GetCurveEvaluator1(SketchEntity3D sketchEntity3D)
{
    dynamic sketchEntityDynamic = sketchEntity3D;
    try
    {
        return sketchEntityDynamic.Geometry.Evaluator;
    }
    catch
    {
        return null;
    }
}

 

 

Use late binding directly using InvokeMember

 

CurveEvaluator GetCurveEvaluator2(SketchEntity3D sketchEntity3D)
{
    try
    {
        var geometry = sketchEntity3D.GetType().InvokeMember("Geometry", BindingFlags.GetProperty, null, sketchEntity3D, null);
        var evaluator = geometry.GetType().InvokeMember("Evaluator", BindingFlags.GetProperty, null, geometry, null);

        return evaluator as CurveEvaluator;
    }
    catch
    {
        return null;
    }

}

 

 

Sample usage

 

public override void Main()
{
    var pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Pick curve");
    var sketchEntity3D = pick as SketchEntity3D;

    CurveEvaluator curveEvaluator1 = GetCurveEvaluator1(sketchEntity3D);
    CurveEvaluator curveEvaluator2 = GetCurveEvaluator2(sketchEntity3D);

    Logger.Debug((curveEvaluator1 != null).ToString());
    Logger.Debug((curveEvaluator2 != null).ToString());
}

 

 

iLogic/VB.NET does it for you automatically.

 

0 Likes
Message 5 of 5

johnPGNFG
Enthusiast
Enthusiast

Thank you! That works perfectly 

0 Likes