Distances between solid bodies

Distances between solid bodies

orhan.alihanov
Participant Participant
306 Views
2 Replies
Message 1 of 3

Distances between solid bodies

orhan.alihanov
Participant
Participant

I'm trying to find the minimum distance between a solid body and a plane.

I have an idea to select any vertex of the body and find the distance to the plane:

 

For Each solid In partDoc.ComponentDefinition.SurfaceBodies
		g = Measure.MinimumDistance(solid.Vertices(1), "YZ Plane")
Next

 

0 Likes
Accepted solutions (1)
307 Views
2 Replies
Replies (2)
Message 2 of 3

Dev_rim
Advocate
Advocate
Accepted solution

Hi there,

This is the code given distance between "YZ Plane" and '1' indexed vertex of each solid.

 

For Each solid In partDoc.ComponentDefinition.SurfaceBodies
    Dim Distance as Double
    Distance = partDoc.ComponentDefinition.WorkPlanes("YZ Plane").Plane.DistanceTo(solid.Vertices(1).Point)
Next

 

 

If you want to get all vertices on a Solid and find the closest one:

For Each solid In partDoc.ComponentDefinition.SurfaceBodies
    Dim minimumDistance as Double
    Dim vertexCounter as Int
    vertexCounter = 0
    Dim vertex as Vertex
    For Each vertex in solid.Vertices
        Dim distance as Double
        If vertexCounter = 0 Then
            minimumDistance = = partDoc.ComponentDefinition.WorkPlanes("YZ Plane").Plane.DistanceTo(vertex.Point)
        Else
            distance = partDoc.ComponentDefinition.WorkPlanes("YZ Plane").Plane.DistanceTo(vertex.Point)
            If distance < minimumDistance Then
                minimumDistance = distance
            End If   
        End If
    vertexCounter = vertexCounter+1
    Next 
    vertexCounter =0    
Next

 

 

Best Regards

Devrim

 

 

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
Message 3 of 3

orhan.alihanov
Participant
Participant
Thank you very much, helped a lot!