Message 1 of 4
Context with .GetMinimumDistance throws error in VB.NET , not in VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
With the code below i do the following:
Loop in part 1 which is in a subassembly through all circular holes
Measure the shortest distance to...
Loop in part 2 which is in a subassembly through all faces of a specific body
Then i check if the holes are not to close with GetMinimumDistance
All works fine, but oContext throws an error in VB.NET although the same code works in VBA
In need the oContext to calculate the Shortest distance in the XY-Plane, because shortest distance gives the shortest distance in 3 directions.
Other solutions are welcome!
Sub CheckHolesAgainstGlass()
Try
Dim oOccurenceGlas As ComponentOccurrence = Nothing
Dim oOccurenceBuitenvel As ComponentOccurrence = Nothing
Dim oPartCompDefGlas As PartComponentDefinition
Dim oPartCompDefBuitenvel As PartComponentDefinition
Dim oBodyGlas As SurfaceBody = Nothing
Dim oBodyBuitenvel As SurfaceBody = Nothing
For Each oRefAssemblyDoc As Document In oAsmdoc.ReferencedDocuments
Try
If oRefAssemblyDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oRefAsmDoc As AssemblyDocument = oRefAssemblyDoc
Dim oRefAsmDocDef As AssemblyComponentDefinition = oRefAsmDoc.ComponentDefinition
Select Case IO.Path.GetFileName(oRefAsmDoc.FullFileName)
Case "Assembly Buitenvel Magnetude.iam"
oOccurenceBuitenvel = oRefAsmDocDef.Occurrences(1)
oPartCompDefBuitenvel = oOccurenceBuitenvel.Definition
oBodyBuitenvel = oPartCompDefBuitenvel.SurfaceBodies(1)
Case "Assembly Trekkers.iam"
oOccurenceGlas = oRefAsmDocDef.Occurrences(1)
oPartCompDefGlas = oOccurenceGlas.Definition
oBodyGlas = oPartCompDefGlas.SurfaceBodies(2)
End Select
End If
Catch
End Try
Next oRefAssemblyDoc
For Each oFaceBuitenvel As Face In oBodyBuitenvel.Faces
If oFaceBuitenvel.SurfaceType = SurfaceTypeEnum.kCylinderSurface And oFaceBuitenvel.Edges.Count = 2 Then
Dim FaceProxyBuitenvel As FaceProxy = Nothing
oOccurenceBuitenvel.CreateGeometryProxy(oFaceBuitenvel, FaceProxyBuitenvel)
Dim FaceProxyGlas As FaceProxy = Nothing
For Each oFaceGlas As Face In oBodyGlas.Faces
Call oOccurenceGlas.CreateGeometryProxy(oFaceGlas, FaceProxyGlas)
Dim oContext As NameValueMap '= InvApp.TransientObjects.CreateNameValueMap()
InvApp.MeasureTools.GetMinimumDistance(FaceProxyGlas, FaceProxyBuitenvel, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference, oContext)
Dim dblDistance As Double = Math.Sqrt((oContext.Item(2).X - oContext.Item(3).X) ^ 2 + (oContext.Item(2).Y - oContext.Item(3).Y) ^ 2) * 10
If dblDistance < 50 Then
SendMail("Distance to small :" & Round(dblDistance, 1).ToString)
Exit Sub
End If
Next oFaceGlas
End If
Next
Catch ex As Exception
End Try
End Sub
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
please feel free to "kudos"