Hello,
I want to find the intersection point between a cylindrical curve and faces in a body. I have the start point an start vector and a rotational velocity. With this values it should be possible to create this cylindrical curve.
Is there a function in inventor which I can use?
Currently I am using the function "FindUsingRay". But I thing that there is only the possibility to fire a linear function through the body.
Today I found the command "FindUsingVector":
Sub FindUsingVector(OriginPoint As Point, Direction As UnitVector, ObjectTypes As SelectionFilterEnum(), ByRef UseCylinder As [defaultvalue(-1)] Boolean, ByRef ProximityTolerance As [optional] VARIANT, ByRef VisibleObjectsOnly As [defaultvalue(-1)] Boolean, ByRef LocationPoints As [optional] VARIANT,
I did not find any information in the "Autodesk Programming help".
Does anybody know what is the difference between this both functions?
Is the argument "UseCylinder" for a switch into cylindrical coordinate system?
Thanks for reply
Solved! Go to Solution.
Solved by nagwani. Go to Solution.
Hi There,
The FindUsingVector() method also allows you to find items in linear direction. But the advantage is tha you can specify the object of your interest to be returned, i.e if you want to return Assembly occurrence intersected by vector, you can use following sample code. I found that it only returns the first occurrence intersected and the objects on opposite of vector are not considered. Similarly if you want to find intersection with any kind of entity then the ProximityTolerance acts as radius of cylinder. When UseCylinder is false , the ProximityTolerance is considered as angle of Cone in radians at startpoint.
Hope this helps
-Ishwar N
Sub testVec()
Dim doc As AssemblyDocument
Set doc = ThisApplication.ActiveDocument
Dim tr As TransientGeometry
Set tr = ThisApplication.TransientGeometry
Dim def As AssemblyComponentDefinition
Set def = doc.ComponentDefinition
Dim objtypes(1 To 1) As SelectionFilterEnum
objtypes(1) = SelectionFilterEnum.kAssemblyOccurrenceFilter
Dim objsFound As ObjectsEnumerator
Dim vec As Vector
vec = tr.CreateUnitVector(0, 0, 1)
Dim stpt As Point
Set setpt = def.WorkPoints.Item("Work Point1").Point
Set objsFound = def.FindUsingVector(setpt, vec, objtypes, True, 0.01)
Dim objsFoundRay As ObjectsEnumerator
' Create Highlightset object
Set hset = doc.CreateHighlightSet
hset.Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
Dim obj As Object
For Each obj In objsFound
hset.AddItem obj
Next
End Sub
Hy, thank's for your quick answer.
Now I know that the function "FindUsingVector" is not suitable for my problem of intersection a non linear curve and a non planar face.
Maybe you have an idea for another command. I read that inventor 12 has new functions:
- TransientGeometry.CurveSurfaceIntersection
I tried to use it but it doesn't work. I used a cubic part geometry. Here is my code:
Sub intersection()
Dim dt As Single, i As Integer
Dim oPoints(1 To 10) As Point
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim oPartDef As PartComponentDefinition
Set oPartDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oSurfBody As SurfaceBody
Set oSurfBody = ThisApplication.ActiveDocument.ComponentDefinition.SurfaceBodies.Item(1)
Dim otg As TransientGeometry
Set otg = ThisApplication.TransientGeometry
Dim oto As TransientObjects
Set oto = ThisApplication.TransientObjects
Dim pPoint As Point
Set pPoint = otg.CreatePoint(10, 0, 0)
Dim vecPoint As Vector
Set vecPoint = otg.CreateVector(0, 0, 0)
Dim vecRay As Vector
Set vecRay = otg.CreateVector(0, 100, 0)
Dim oFitPoints As ObjectCollection
Set oFitPoints = oto.CreateObjectCollection
'creation of points for polyline
For i = 1 To 10
With vecPoint
.X = pPoint.X + vecRay.X * dt
.Y = pPoint.Y + vecRay.Y * dt
.Z = pPoint.Z + vecRay.Z * dt
Set oPoints(i) = otg.CreatePoint( _
.X * Cos(20 * dt) + .Z * Sin(20 * dt), _
.Y, _
-1 * .X * Sin(20 * dt) + .Z * Cos(20 * dt))
End With
dt = 0.1 * i
oFitPoints.Add oPoints(i)
Next i
Dim oPolyLine As Polyline3d
Set oPolyLine = otg.CreatePolyline3d(oFitPoints)
Dim objEnumIntersection As ObjectsEnumerator
Dim oFace As Face
For Each oFace In oSurfBody.Faces
On Error Resume Next
Set objEnumIntersection = otg.CurveSurfaceIntersection(oPolyLine, oFace.Geometry)
Next oFace
End Sub
The last for each loop only produce "Nothing" for objEnumIntersection. Can anybody help me to solve this problem?
Hi,
I tried your sample and found that all intersection points were coming, infact you may get additional intersection points as the intersection is done with unbounded surfaces. I also tried intersection between a line segment curve and bsplinesurface , see the attached JPEG file. If you feel that you are not getting the intersection points, then please attach the sample part file to reproduce the issue at my end.
Regards,
-Ishwar N
Hi There,
I have modified your sample code to use FindUsingVector and it is much more efficient now and give the minimum required intersection points. See the modified sample code below.
Hope this helps!
Regards
-Ishwar N
Sub intersection()
Dim dt As Single, i As Integer
Dim oPoints(1 To 10) As Point
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim oPartDef As PartComponentDefinition
Set oPartDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oSurfBody As SurfaceBody
Set oSurfBody = oPartDef.SurfaceBodies.Item(1)
Dim otg As TransientGeometry
Set otg = ThisApplication.TransientGeometry
Dim oto As TransientObjects
Set oto = ThisApplication.TransientObjects
Dim pPoint As Point
Set pPoint = otg.CreatePoint(10, 0, 0)
Dim vecPoint As Vector
Set vecPoint = otg.CreateVector(0, 0, 0)
Dim vecRay As Vector
Set vecRay = otg.CreateVector(0, 100, 0)
Dim oFitPoints As ObjectCollection
Set oFitPoints = oto.CreateObjectCollection
'creation of points for polyline
For i = 1 To 10
With vecPoint
.X = pPoint.X + vecRay.X * dt
.Y = pPoint.Y + vecRay.Y * dt
.z = pPoint.z + vecRay.z * dt
Set oPoints(i) = otg.CreatePoint( _
.X * Cos(20 * dt) + .z * Sin(20 * dt), _
.Y, _
-1 * .X * Sin(20 * dt) + .z * Cos(20 * dt))
End With
dt = 0.1 * i
oFitPoints.Add oPoints(i)
'Added by Ishwar
Dim objTypes(1 To 1) As SelectionFilterEnum
objTypes(1) = kPartFaceFilter
Dim oFaces As ObjectsEnumerator
Dim pts As ObjectsEnumerator
Dim v As UnitVector
If (i > 1) Then
' setup vector
Set v = oPoints(i - 1).VectorTo(oPoints(i)).AsUnitVector
Set oFaces = oPartDef.FindUsingVector(oPoints(i - 1), v, objTypes, True, 0.01)
' Create the line segment between previous point and current point
Dim olSeg As LineSegment
Set olSeg = ThisApplication.TransientGeometry.CreateLineSegment(oPoints(i - 1), oPoints(i))
' Get the intersection between line segment and the faces found by FindUsingVector
If (oFaces.Count > 0) Then
Dim oFace As face
For Each oFace In oFaces
Set pts = otg.CurveSurfaceIntersection(olSeg, oFace.Geometry)
Dim pt As Point
If Not pts Is Nothing Then
For Each pt In pts
Call oPartDef.WorkPoints.AddFixed(pt)
Next
End If
Next
End If
End If
Next i
End Sub
Hi Ishwar,
Could you kindly provide your test part file? I am trying to understand this.
I want to project a profile onto a cylinder and get the intersect cuvre. I want to try out if this work for me.
Thank you very much.
Regards,
Peter
Hi,
I have attached the part which contains a cylinderical extrusion, I have placed the cylinder in such a way that it intersects with polyline curve. Open the attached part and execute the macro I sent in previous reply.
-Ishwar N
Hy Ishwar,
thanks for your help and the fruitfully discussion. I learned a lot and think the discretization of the curve with the query of every line segment with "FindUsingVector" will solve my problem.
Kind regards
pveng
Can't find what you're looking for? Ask the community or share your knowledge.