2 Replies Latest reply on Apr 26, 2016 10:36 AM by Joe Pickens

    API To find hole locations on imported parts

    Joe Pickens

      In short what I am doing is taking two imported parts and aline the holes and mating them.


      the macro i am trying to wright would locate and make an array of hole locations of both parts so i can use the array to find the set of holes that match up.


      the issue that i am running into is that i can figure out a way to get the hole centers and axis direction and hole diameter from the part


      i am currently using the iface2 with GetFirstFace and GetNextFace to try to pull the info i want but i cant figure out how to get the info i need from that member

        • Re: API To find hole locations on imported parts
          Michael Spens

          Hi Joe,

               I'll make some assumptions from your message.  If you already have interfaces to Face2, use GetEdges.  This also assumes you're getting the faces from an assembly Component2 interface.


          'vb.net, SelFace is a Face2 interface, Comp is a Component2 interface...

          Dim FaceEdges() As Object = SelFace.GetEdges

          For Each MyEdge As Edge In FaceEdges

          If IsFullCircle(MyEdge) Then

          Dim MyCurve as Curve

          MyCurve = MyEdge.GetCurve()

          Dim center() as Double

          center = GetCircleCenter(MyCurve, Comp, swApp)

          'do something with the center


          End For


          'function to check if an edge is a full circle

          Private Function IsFullCircle(ByVal EdgeToCheck As Edge) As Boolean

          Dim MyCurve As Curve = EdgeToCheck.GetCurve

          If MyCurve.IsCircle Then

          'you have a circular edge

          'is it a complete circle?

          If EdgeToCheck.GetStartVertex() Is Nothing Then

          'full circle

          Return True

          Exit Function

          End If

          End If

          Return False

          End Function


          'return an array of doubles for the x, y, z circle center

          'relative to the assembly

          Private Function GetCircleCenter(ByVal MyCurve As Curve, _

          ByVal Comp As Component2, _

          ByVal swApp As SldWorks) As Double()

          Dim MyCenter(2) As Double

          Dim returnValues As Object = MyCurve.CircleParams

          MyCenter(0) = returnValues(0)

          MyCenter(1) = returnValues(1)

          MyCenter(2) = returnValues(2)

          'returnValues(3-5) represent the axis x, y, and z

          'returnValues(6) represents the radius

          Dim Radius As Double = returnValues(6)

          Dim MathUtil As MathUtility = swApp.GetMathUtility

          Dim mPoint As MathPoint = Nothing

          mPoint = MathUtil.CreatePoint(MyCenter)

          Dim CompTransform As MathTransform = Comp.Transform2

          mPoint = mPoint.MultiplyTransform(CompTransform)

          'return the x,y,z location in assembly space

          Return mPoint.ArrayData

          End Function