Hello there!
I seem to have a peculiar problem:
I'm trying to compute the intersections of several SurfaceBody instances with a plane and then convert the resulting edges of the intersection bodies to 2D approximations in the plane's local space.
The intersection part works fine. The only "issue" is that the TransientBRep.CreateIntersectionWithPlane(...) method throws an exception if there is no intersection between the body and the plane and those exceptions clutter my debug output, but that's not really a problem.
The problem comes up in the next step: Since I can't find a way to get a 2D projection on the plane of the 3D curves of the intersection's edges directly, I tried to get a linear approximation of each edge and project the points of this approximation onto my plane.
Sadly, getting the linear approximation of these edges seems to be nigh impossible. I tried three approaches:
a) Use the CalculateStrokes method of the edge directly:
foreach (Edge edge in intersectionBody.Edges) { try { int vertexCount, segmentCount; double[] vertexCoords = { }; int[] vertexIndices = { }; edge.CalculateStrokes(tolerance, out vertexCount, out segmentCount, out vertexCoords, out vertexIndices); // immediate crash } catch (System.Exception ex) { ... } }
b) Use the GetStrokes method of the edge's geometry's evaluator:
foreach (Edge edge in intersectionBody.Edges) { try { CurveEvaluator eval = edge.Geometry.Evaluator; double minParam, maxParam, length; eval.GetParamExtents(out minParam, out maxParam); int vertexCount; double[] vertexCoords = { }; eval.GetStrokes(minParam, maxParam, tolerance, out vertexCount, out vertexCoords); // immediate crash } catch (System.Exception ex) { ... } }
c) Use the TransientGeometry.CreatePolyline3dFromCurve method.
foreach (Edge edge in intersectionBody.Edges) { try { Polyline3d pl = tGeo.CreatePolyline3dFromCurve(edge.Geometry, tolerance); // throws an exception } catch (System.Exception ex) { ... } }
Both a) and b) result in an immediate crash of Inventor with no way for me to catch the exception. c) throws an exception, meaning I can actually catch that one and keep Inventor from crashing immediately.
Since a) and b) crash immediately I can't tell if they would work for other edges in the body. c) doesn't work for any of the edges.
My current workaround is to use the CurveEvaluator to get a ridiculous number of points and filter those based on my tolerance. This is pretty inefficient and actually takes a lot longer than the intersection computation does, so it's not a real option in the long run.
Can anybody help me with this issue?
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
So
edge.CalculateStrokes
does not work for any edge? Could you try initializing the arrays like this?
double[] vertexCoords = new double [] { };
int[] vertexIndices = new int[]{ };
How can I use ThisApplication.TransientGeometry.CreatePolyline3dFromCurve from edge object? Is that possible?
I am having hard time to translate from edges for elipticalarc to 3d points... Is there any shorter way to acomplish this?
I also tried with
Call oEdge.CalculateStrokes(oEdge.GetExistingStrokeTolerances(100,), 100, 100, vertexCoordinates, vertexIndices)
Bu this gives me only 2d points - Is it possible to get 3d points with
Call oEdge.CalculateStrokes(oEdge.GetExistingStrokeTolerances(100,), 100, 100, vertexCoordinates, vertexIndices)
regards
On Inventor 2016 SP1, CurveEvaluator.GetStrokes fails on circle. Inventor immediately crash with an access violation in ASMKERN221.dll and the message: "Memory may have been left in an inconsistent state." It works for arc.
Here is a bit of VBA code to reproduce the crash:
Public Sub Crash() Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument ' Set a reference to component definition of the active part. Dim oCompDef As PartComponentDefinition Set oCompDef = oDoc.ComponentDefinition Dim oTransientBRep As TransientBRep Set oTransientBRep = ThisApplication.TransientBRep Dim oTransGeom As TransientGeometry Set oTransGeom = ThisApplication.TransientGeometry Dim p As Point Set p = oTransGeom.CreatePoint(0, 0, 0.035) Dim n As Vector Set n = oTransGeom.CreateVector(0, 0, 1) Dim pl As Plane Set pl = oTransGeom.CreatePlane(p, n) Dim sb As SurfaceBody Set sb = oTransientBRep.CreateIntersectionWithPlane(oCompDef.SurfaceBodies.Item(1), pl) Dim w As Wire Dim e As Edge For Each w In sb.Wires For Each e In w.Edges Dim ce As CurveEvaluator Set ce = e.Geometry.Evaluator Dim min As Double Dim max As Double ce.GetParamExtents min, max Dim vc As Long Dim coords() As Double ce.GetStrokes min, max, 0.01, vc, coords ' <- boom !
' e.Evaluator.GetStrokes min, max, 0.01, vc, coords ' OK Next e Next w End Sub
Use it on a cylinder part.
Hi Maxence,
I installed SP1 which was painful - maybe something is wrong with my VM - and got stuck in the end so I had to restart.
Still, it says that it has SP1 installed and I cannot reproduce the issue. Now I'm not sure if my install is missing something that is needed for the behaviour to appear. :-s
Can you reproduce it with ANY cylindrical part? What happens if you migrate the part to Inventor 2016 SP1 - i.e. save it in that version?
Cheers,
I could reproduce it after all I just had the sketch in another plane, not XY. I thought you meant to say that it was a 2016 SP1 issue, but I found the same in Inventor 2015 as well.
Have logged it in our system: #126239
Any issue with the workaround you found of using "e.Evaluator.GetStrokes min, max, 0.01, vc, coords" instead?
e.Evaluator.GetStrokes works, no problem so far. But for me it crashes also when the sketch is on the XY plane (see IPT attached).
Sorry, I did not put it clearly.
What I mean to say was "I could reproduce it after all I just originally had the sketch in another plane, not XY - and that's why I could not reproduce the issue. Once the sketch was on the XY plane I could reproduce the behaviour." 🙂