Inventor Customization

Reply
Active Member
pveng
Posts: 7
Registered: ‎02-07-2013
Message 1 of 8 (332 Views)
Accepted Solution

FindUsingVector

332 Views, 7 Replies
02-07-2013 04:03 AM

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

Employee
nagwani
Posts: 33
Registered: ‎11-17-2011
Message 2 of 8 (313 Views)

Re: FindUsingVector

02-11-2013 12:50 AM 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

Active Member
pveng
Posts: 7
Registered: ‎02-07-2013
Message 3 of 8 (309 Views)

Re: FindUsingVector

02-11-2013 03:19 AM 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?

 

 

 

Employee
nagwani
Posts: 33
Registered: ‎11-17-2011
Message 4 of 8 (297 Views)

Re: FindUsingVector

02-11-2013 09:12 PM 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

Employee
nagwani
Posts: 33
Registered: ‎11-17-2011
Message 5 of 8 (272 Views)

Re: FindUsingVector

02-13-2013 01:28 AM 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

 

 

Active Contributor
shirazbj
Posts: 46
Registered: ‎02-25-2007
Message 6 of 8 (266 Views)

Re: FindUsingVector

02-13-2013 04:04 AM 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

Employee
nagwani
Posts: 33
Registered: ‎11-17-2011
Message 7 of 8 (263 Views)

Re: FindUsingVector

02-13-2013 04:31 AM 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

Active Member
pveng
Posts: 7
Registered: ‎02-07-2013
Message 8 of 8 (239 Views)

Re: FindUsingVector

02-14-2013 05:50 AM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube