Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FindUsingVector

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
pveng
838 Views, 7 Replies

FindUsingVector

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

7 REPLIES 7
Message 2 of 8
nagwani
in reply to: pveng

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

Message 3 of 8
pveng
in reply to: nagwani

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?

 

 

 

Message 4 of 8
nagwani
in reply to: pveng

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

Message 5 of 8
nagwani
in reply to: pveng

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

 

 

Message 6 of 8
shirazbj
in reply to: nagwani

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

Message 7 of 8
nagwani
in reply to: pveng

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

Message 8 of 8
pveng
in reply to: nagwani

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.

Post to forums  

Autodesk Design & Make Report