Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

How to filter points belong a random box

SandmanINV
Advocate

How to filter points belong a random box

SandmanINV
Advocate
Advocate

Hi, 

Hi, I have a point cloud which contains 3D work points (thousand points). And I have a random box. So, if I create a "Foreach(.....)" loop, to check interference between points with box one by one. I will take a huge time to check and collect the points I need. With this situation, what should I do to improve speed?

Thank you very much.

SandmanINV_0-1647114110826.png

 

0 Likes
Reply
Accepted solutions (1)
524 Views
6 Replies
Replies (6)

Ralf_Krieg
Advisor
Advisor

Hello

 

Can you tell us how the "box" is created? Is it an extrusion as solid body, a transient geometry or something else? A box object has a Contains method. A SurfaceBody and a FaceShell has a IsPointInside method. Can you post a sample file? This would make it much easier to understand .


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com

SandmanINV
Advocate
Advocate

Hi Krieg,
"Box" is a solidbody be created by "Extrude".
Point created from excel coordinate table.
Please see the sample I created by inventor 2022.
Thank you very much.

0 Likes

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Thank for the sample. A PointCloud in Inventor means something different, a box also. Anyway, the sample file answers all questions. Can you try how much time this VBA snippet needs to collect the points?

Option Explicit

Private Sub WPInOut()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSB As SurfaceBody
Set oSB = oDoc.ComponentDefinition.SurfaceBodies(1)

Dim oObjColl As ObjectCollection
Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection

Dim oContainmentEnum As ContainmentEnum
Dim oCoords() As Double
Dim oWP As WorkPoint

For Each oWP In oDoc.ComponentDefinition.WorkPoints
    If oWP.IsCoordinateSystemElement = False Then
        Call oWP.Point.GetPointData(oCoords())
        oContainmentEnum = oSB.IsPointInside(oCoords)
        If oContainmentEnum = kInsideContainment Or oContainmentEnum = kOnContainment Then
            Call oObjColl.Add(oWP)
        End If
    End If
Next
End Sub

 


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com

SandmanINV
Advocate
Advocate

Thank you for your advice.

So the flow is : Get point data => result is : [x,y,z] => check it with surfacebody => see result. Did I understand right ?

I convert them to C#.

 oWpoint.Point.GetPointData(oCoords);  // get X,Y,Z as double[]
                    oContainmentEnum = oPartdef.SurfaceBodies[1].IsPointInside[oCoords]; // Check this double[] with body 1
                    if(oContainmentEnum == ContainmentEnum.kInsideContainment || oContainmentEnum == ContainmentEnum.kOnContainment) 
                    {
                        oObj_Collection.Add(oWpoint);
                    }

 

0 Likes

Ralf_Krieg
Advisor
Advisor

Hello

 

Yes, that's right. My test with VBA and around 1200 Workpoints finished within 1 second. Should be fast enough.


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
0 Likes

SandmanINV
Advocate
Advocate

SandmanINV_0-1647255689339.png

Thank you very much

0 Likes