- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Nowadays I'm working on a project where apart from the rest tasks I need to find both points where the given axis intersects the given surface body (solid).
As a most close guide to follow I've found this article - projecting-points-onto-a-solid
With some modification I managed to get a bit closer code. Here it is:
Dim oIPT = ThisDoc.Document
Dim oPCD = oIPT.ComponentDefinition
' Dim sk As PlanarSketch = oPCD.Sketches("The_Sketch")
' The body to project onto
Dim body As SurfaceBody = ThisApplication.CommandManager.Pick(kPartBodyFilter, "Select the body")
Dim oIL = oPCD.WorkAxes("oIL")
Dim skNormal As UnitVector = oIL.Line.Direction
' skNormal = sk.PlanarEntityGeometry.Normal
Dim skRootPoint As Point=oIL.Line.RootPoint ' ~ about Origin (wrong side to project with given Vector??)
' skRootPoint = sk.PlanarEntityGeometry.RootPoint
' oWWW=oPCD.Workpoints.AddFixed(skRootPoint) : oWWW.Name="skRootPoint"
Dim tg As TransientGeometry
tg = ThisApplication.TransientGeometry
' Construct a matrix where the X axis is along the sketch plane normal.
Dim xAxis As Vector
xAxis = skNormal.AsVector
Dim yAxis As Vector
yAxis = tg.CreateVector(xAxis.x + 1, xAxis.y + 1, xAxis.Z + 1)
Dim zAxis As Vector
zAxis = xAxis.CrossProduct(yAxis)
yAxis = zAxis.CrossProduct(xAxis)
xAxis.Normalize
yAxis.Normalize
zAxis.Normalize
Dim transform As Matrix
transform = tg.CreateMatrix
Call transform.SetCoordinateSystem(skRootPoint, xAxis, yAxis, zAxis)
transform.Invert
' offset = 0
Dim offsetVector As Vector
offsetVector = skNormal.AsVector
' Call offsetVector.ScaleBy(offset) ' ??
' *** Perform the intersection calculation of every center point in the sketch.
Dim resultPoints As ObjectCollection
resultPoints = ThisApplication.TransientObjects.CreateObjectCollection
Dim skPoint As SketchPoint
Dim pnt As Point = skRootPoint
' Move the point outside the solid.
Call pnt.TranslateBy(offsetVector)
' Intersect the point with the solid.
Dim foundEnts As ObjectsEnumerator
Dim locPoints As ObjectsEnumerator
Call body.FindUsingRay(pnt, skNormal, 0.00001, foundEnts, locPoints, True)
' If an intersection was found, add it to the list.
If locPoints.count > 0 Then
Call resultPoints.Add(locPoints(1))
End If
For i = 1 To resultPoints.count
Call oPCD.WorkPoints.AddFixed(resultPoints(i))
Next
For some bodies (I believe it depends on body location related to the model origin) it does build one of the required points (try choose "Solid 1" in the sample IPT attached, 2021.3.1).
Unfortunately I stuck a bit and currently don't understand how to modify it further to get what I need thus ask for some help from community, please.
Please vote for Inventor-Idea Text Search within Option Names
Solved! Go to Solution.