AnsweredAssumed Answered

Is there a problem in the API concerning the distance between two holes?

Question asked by Edwin Thompson on Aug 8, 2016
Latest reply on Aug 11, 2016 by Josh Brady

My program needs the capability to measure the shortest distance between the surface of two holes.  Below are a number of cases that all work but there is one left:

For the cases of measuring the distance between two vertices the results are good (shown below).  

 

(code to get first vertex)

   vertex = SelObj.GetPoint

   bRet = TransPoint(vertex(0), vertex(1), vertex(2))

   P1x = T1x

   P1y = T1y

   P1z = T1z

(code to get second vertex)

   vertex = SelObj.GetPoint  

   bRet = TransPoint(vertex(0), vertex(1), vertex(2))

   P2x = T1x

   P2y = T1y

   P2z = T1z

  

Calls Calcdist which translates the coordinates (only in the case of an assembly) and displays the values.

calls tmpline.

 

(tmpline Sub):

    swModel.SetAddToDB(True)

   swModel.Insert3DSketch2(False)

   swSkPoint1 = swModel.CreatePoint2(P1x, P1y, P1z)

   swSkPoint2 = swModel.CreatePoint2(P2x, P2y, P2z)

   swSkLine = swModel.CreateLine2(P1x, P1y, P1z, P2x, P2y, P2z)

 

swModel.SetAddToDB(False)

  TempSketch = swModel.GetActiveSketch2

  swFeat = TempSketch

  swFeat.Name = "DispMeaSketch"

swModel.Insert3DSketch2(True)

   bRet = swModel.EditRebuild3

(End Sub)

 

The results worked very nicely for "parts" but for "assemblies" the points needed to be translated between the part and the assembly coordinate systems:

The next case is to calculate the distance between two surface within an assembly.  The following code was used:

(code to get first and second surfaces)

   nDist = swModel.ClosestDistance(swFace1, swFace2, vPoint1, vPoint2) 

   P1x = vPoint1(0)

   P1y = vPoint1(1)

   P1z = vPoint1(2)

   P2x = vPoint2(0)

   P2y = vPoint2(1)

   P2z = vPoint2(2)

 

(Call Calcdist which automatically "translates" the points to the assembly Coordinate system and displays the values as shown below)

The same results work for both "parts" and for "assemblies".  The only difference is that the points need to be translated for assemblies.

 

The problem is that when the two cylindrical surfaces are parallel the result is not the shortest distance but rather between the two center lines:

According to the literature, to resolve this issue with two parallel cylinders the following code was added:

 

nDist = swModel.ClosestDistance(swFace1, swFace2, vPoint1, vPoint2)  'Gets Center Point

If swSurf1.IsCylinder Then    'Measure has returned the center point, so use the point on the other surface

   vClosestPt1 = swFace1.GetClosestPointOn(vPoint2(0), vPoint2(1), vPoint2(2)) 'Fails here in assembly

Else  'Probably on the surface, but just to be sure...

   vClosestPt1 = swFace1.GetClosestPointOn(vPoint1(0), vPoint1(1), vPoint1(2))

End If

If swSurf2.IsCylinder Then  'Measure has returned the center point, so use the point on the other surface

   vClosestPt2 = swFace2.GetClosestPointOn(vPoint1(0), vPoint1(1), vPoint1(2))

Else  'Probably on the surface, but just to be sure...

   vClosestPt2 = swFace2.GetClosestPointOn(vPoint2(0), vPoint2(1), vPoint2(2))

End If

P1x = vClosestPt1(0)

P1y = vClosestPt1(1)

P1z = vClosestPt1(2)

P2x = vClosestPt2(0)

P2y = vClosestPt2(1)

P2z = vClosestPt2(2)

(Calls Calcdist and displays the values)

(calls tmpline which also translates the the points for the Assembly coordinate system):

 

Within a "part" file the results are good:

However within an "assembly" the results are wrong (shown below).  All of the code that is working in the previous examples is the same.  Below is the result when the points are translated.  Sadly, the results are not much better if the end points of the temporary line are translated or not.

 

It is expected that for a part, the result should be good without translation and for an assembly the result should be good with translation.  However, in this one case, neither result is good.

 

Any idea what the problem is?  One possibility is that perhaps the GetClosestPointOn returns the point values that are already in the Assembly Coordinate system?

Has anyone else ran into this?  Is this a problem within the API?  Any ideas about how to correct this last case?

Outcomes