3 Replies Latest reply on Aug 11, 2016 4:54 PM by Josh Brady

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

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.Insert3DSketch2(False)

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

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

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

TempSketch = swModel.GetActiveSketch2

swFeat = TempSketch

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?

• ###### Re: Is there a problem in the API concerning the distance between two holes?

Hi Edwin
You are right for assemblies the transformation is required:

Set swCompXform = swComp.Transform2

Set swMathPt = swMathPt.MultiplyTransform(swCompXform)

Method: "swFace2.GetClosestPointOn" Is quite precise and never failed me

• ###### Re: Is there a problem in the API concerning the distance between two holes?

Here is what I have found:

When I selected a vertex using  "vertex = SelObj.GetPoint"  a transform must be used to properly place the point into an assembly, and this works nicely.

However, when I selected a surface using "nDist = swModel.ClosestDistance(swFace1, swFace2, vPoint1, vPoint2)" NO transformation is required and vPoint1 and vPoint2 will correctly place the points into an assembly.

The problem is that if two cylindrical surfaces are parallel with each other, to obtain the closet distance, and not the center to center distance " vClosestPt2 = swFace2.GetClosestPointOn(vPoint1(0), vPoint1(1), vPoint1(2))" must be used. However, the values for the points returned are not correct if transformed or not.

This is just a guess but after working with this a little, it is almost as though the point values from the ClosestDistance needs to be "inverse transformed" and used in the GetClosestPointOn command so the points returned from the GetClosestPointOn can then be transformed to properly place the point into the assembly.

Any ideas?

• ###### Re: Is there a problem in the API concerning the distance between two holes?

Sorry, I haven't dug real deep here, but any particular reason you aren't using the Measure API? I would think that would simplify a lot of your code...